#include <OptionsLoader.h>

Definition at line 60 of file OptionsLoader.h.
Public Member Functions | |
| bool | errorOccured () const throw () |
| Returns the information whether an error occured. | |
| OptionsLoader () throw () | |
| Constructor. | |
| ~OptionsLoader () throw () | |
Handlers for the SAX DocumentHandler interface | |
| void | characters (const XMLCh *const chars, const XERCES3_SIZE_t length) |
| Called on the occurence of character data. | |
| void | endElement (const XMLCh *const name) |
| Called on the end of an element. | |
| virtual void | startElement (const XMLCh *const name, AttributeList &attributes) |
| Called on the occurence of the beginning of a tag. | |
Handlers for the SAX ErrorHandler interface | |
| void | error (const SAXParseException &exception) |
| Called on an XML-error. | |
| void | fatalError (const SAXParseException &exception) |
| Called on an XML-fatal error. | |
| void | warning (const SAXParseException &exception) |
| Called on an XML-warning. | |
Private Member Functions | |
| OptionsLoader & | operator= (const OptionsLoader &s) |
| OptionsLoader (const OptionsLoader &s) | |
| bool | setSecure (const std::string &name, const std::string &value) const throw () |
| Tries to set the named option to the given value. | |
| bool | setSecure (const std::string &name, bool value) const throw () |
| Tries to set the named option to the given value (for bool-Options). | |
| void | setValue (const std::string &key, std::string &value) |
| Tries to set the named option to the given value. | |
Private Attributes | |
| bool | myError |
| The information whether an error occured. | |
| std::string | myItem |
| The name of the currently parsed option. | |
| OptionsCont & | myOptions |
| The options to fill. | |
| std::string | myValue |
| The currently read characters string. | |
| OptionsLoader::OptionsLoader | ( | ) | throw () |
Constructor.
Definition at line 50 of file OptionsLoader.cpp.
00051 : myError(false), myOptions(OptionsCont::getOptions()), myItem() {}
| OptionsLoader::~OptionsLoader | ( | ) | throw () |
| OptionsLoader::OptionsLoader | ( | const OptionsLoader & | s | ) | [private] |
invalid copy constructor
| void OptionsLoader::characters | ( | const XMLCh *const | chars, | |
| const XERCES3_SIZE_t | length | |||
| ) |
Called on the occurence of character data.
If this occurs inside a single tag it sets the option named by the tag to the value given by the character data. This is considered deprecated in favor of attributes.
Definition at line 102 of file OptionsLoader.cpp.
References TplConvert< E >::_2str(), and myValue.
00103 { 00104 myValue = myValue + TplConvert<XMLCh>::_2str(chars, (unsigned int) length); 00105 }
| void OptionsLoader::endElement | ( | const XMLCh *const | name | ) |
Called on the end of an element.
Resets the element name
Definition at line 131 of file OptionsLoader.cpp.
References myItem, myValue, and setValue().
00131 { 00132 if (myItem.length()==0 || myValue.length()==0) { 00133 return; 00134 } 00135 if (myValue.find_first_not_of("\n\t \a")==std::string::npos) { 00136 return; 00137 } 00138 setValue(myItem, myValue); 00139 myItem = ""; 00140 myValue = ""; 00141 }
| void OptionsLoader::error | ( | const SAXParseException & | exception | ) |
Called on an XML-error.
The warning is reported to the the error-instance of MsgHandler
Definition at line 155 of file OptionsLoader.cpp.
References MsgHandler::getErrorInstance(), MsgHandler::inform(), myError, and toString().
00155 { 00156 MsgHandler::getErrorInstance()->inform( 00157 TplConvert<XMLCh>::_2str(exception.getMessage())); 00158 MsgHandler::getErrorInstance()->inform( 00159 " (At line/column " 00160 + toString(exception.getLineNumber()+1) + '/' 00161 + toString(exception.getColumnNumber()) + ")."); 00162 myError = true; 00163 }
| bool OptionsLoader::errorOccured | ( | ) | const throw () |
Returns the information whether an error occured.
Definition at line 179 of file OptionsLoader.cpp.
References myError.
Referenced by OptionsIO::loadConfiguration().
00179 { 00180 return myError; 00181 }
| void OptionsLoader::fatalError | ( | const SAXParseException & | exception | ) |
Called on an XML-fatal error.
The warning is reported to the the error-instance of MsgHandler
Definition at line 167 of file OptionsLoader.cpp.
References MsgHandler::getErrorInstance(), MsgHandler::inform(), myError, and toString().
00167 { 00168 MsgHandler::getErrorInstance()->inform( 00169 TplConvert<XMLCh>::_2str(exception.getMessage())); 00170 MsgHandler::getErrorInstance()->inform( 00171 " (At line/column " 00172 + toString(exception.getLineNumber()+1) + '/' 00173 + toString(exception.getColumnNumber()) + ")."); 00174 myError = true; 00175 }
| OptionsLoader& OptionsLoader::operator= | ( | const OptionsLoader & | s | ) | [private] |
invalid assignment operator
| bool OptionsLoader::setSecure | ( | const std::string & | name, | |
| const std::string & | value | |||
| ) | const throw () [private] |
Tries to set the named option to the given value.
Checks the item whether it was default before setting it. Returns the information whether the item was set before (was not a default value)
| [in] | name | The name of the option to set |
| [in] | value | The new value for the option |
Definition at line 120 of file OptionsLoader.cpp.
References OptionsCont::isWriteable(), myOptions, and OptionsCont::set().
00121 { 00122 if (myOptions.isWriteable(name)) { 00123 myOptions.set(name, value); 00124 return true; 00125 } 00126 return false; 00127 }
Tries to set the named option to the given value (for bool-Options).
Checks the item whether it was default before setting it. Returns the information whether the item was set before (was not a default value)
| [in] | name | The name of the option to set |
| [in] | value | The new value for the option |
Definition at line 109 of file OptionsLoader.cpp.
References OptionsCont::isWriteable(), myOptions, and OptionsCont::set().
Referenced by setValue().
00110 { 00111 if (myOptions.isWriteable(name)) { 00112 myOptions.set(name, value); 00113 return true; 00114 } 00115 return false; 00116 }
| void OptionsLoader::setValue | ( | const std::string & | key, | |
| std::string & | value | |||
| ) | [private] |
Tries to set the named option to the given value.
Also evaluates whether it is a boolean or a filename option and does the relevant checks / modifications.
| [in] | key | The name of the option to set |
| [in] | value | The new value for the option |
Definition at line 73 of file OptionsLoader.cpp.
References MsgHandler::getErrorInstance(), MsgHandler::inform(), OptionsCont::isBool(), myError, myOptions, and setSecure().
Referenced by endElement(), and startElement().
00074 { 00075 if (value.length()>0) { 00076 try { 00077 bool isWriteable; 00078 if (myOptions.isBool(key)) { 00079 std::transform(value.begin(), value.end(), value.begin(), tolower); 00080 if (value=="1"||value=="yes"||value=="true"||value=="on"||value=="x") { 00081 isWriteable = setSecure(key, true); 00082 } else if (value=="0"||value=="no"||value=="false"||value=="off") { 00083 isWriteable = setSecure(key, false); 00084 } else { 00085 throw InvalidArgument("Invalid boolean value for option '" + key + "'."); 00086 } 00087 } else { 00088 isWriteable = setSecure(key, value); 00089 } 00090 if (!isWriteable) { 00091 MsgHandler::getErrorInstance()->inform("Could not set option '" + key + "' (probably defined twice)."); 00092 myError = true; 00093 } 00094 } catch (InvalidArgument e) { 00095 MsgHandler::getErrorInstance()->inform(e.what()); 00096 myError = true; 00097 } 00098 } 00099 }
| void OptionsLoader::startElement | ( | const XMLCh *const | name, | |
| AttributeList & | attributes | |||
| ) | [virtual] |
Called on the occurence of the beginning of a tag.
Sets the name of the last item
Definition at line 57 of file OptionsLoader.cpp.
References TplConvert< E >::_2str(), OptionsCont::exists(), myItem, myOptions, myValue, and setValue().
00058 { 00059 myItem = TplConvert<XMLCh>::_2str(name); 00060 for (int i = 0; i < (int) attributes.getLength(); i++) { 00061 std::string name = TplConvert<XMLCh>::_2str(attributes.getName(i)); 00062 std::string value = TplConvert<XMLCh>::_2str(attributes.getValue(i)); 00063 if (myOptions.exists(myItem) && (name == "value" || name == "v")) { 00064 setValue(myItem, value); 00065 } else { 00066 setValue(name, value); 00067 } 00068 } 00069 myValue = ""; 00070 }
| void OptionsLoader::warning | ( | const SAXParseException & | exception | ) |
Called on an XML-warning.
The warning is reported to the the warning-instance of MsgHandler
Definition at line 145 of file OptionsLoader.cpp.
References myError, toString(), and WRITE_WARNING.
00145 { 00146 WRITE_WARNING(TplConvert<XMLCh>::_2str(exception.getMessage())); 00147 WRITE_WARNING(" (At line/column " \ 00148 + toString(exception.getLineNumber()+1) + '/' \ 00149 + toString(exception.getColumnNumber()) + ")."); 00150 myError = true; 00151 }
bool OptionsLoader::myError [private] |
The information whether an error occured.
Definition at line 181 of file OptionsLoader.h.
Referenced by error(), errorOccured(), fatalError(), setValue(), and warning().
std::string OptionsLoader::myItem [private] |
The name of the currently parsed option.
Definition at line 187 of file OptionsLoader.h.
Referenced by endElement(), and startElement().
OptionsCont& OptionsLoader::myOptions [private] |
The options to fill.
Definition at line 184 of file OptionsLoader.h.
Referenced by setSecure(), setValue(), and startElement().
std::string OptionsLoader::myValue [private] |
The currently read characters string.
Definition at line 190 of file OptionsLoader.h.
Referenced by characters(), endElement(), and startElement().
1.5.6