XmlSerializerBase Class Reference
The XmlSerializerBase class encapsulates functions that are common to XmlSerializer and XmlDeserializer.
More...
#include <xmlserializerbase.h>
Classes | |
| class | TemporaryNodeChanger |
| This is a helper class to ensure correct state of the XML node for inserting or reading data. More... | |
| class | TemporaryUsePointerContentSerializationChanger |
| This is a helper class to ensure correct use pointer content serialization state. More... | |
Public Member Functions | |
| XmlSerializerBase () | |
| Default constructor. | |
| void | addError (const std::string &message) |
Adds the given error message to the error list. | |
| void | addError (const std::exception &exception) |
Adds the error message of the given exception to the error list. | |
| template<class T > | |
| void | raise (const T &exception) throw (SerializationException) |
Adds the error message from the given exception to the error list and raise the exception afterwards. | |
| void | removeLastError () |
| Removes the last error message from the error list. | |
| std::vector< std::string > | getErrors () const |
| Returns the error list. | |
| bool | getUseAttributes () const |
| Returns whether primitive data is serialized as XML attributes or XML nodes. | |
| void | setUseAttributes (const bool &useAttributes) |
| Sets whether to serialize primitive data as XML attributes or XML nodes. | |
| bool | getUsePointerContentSerialization () const |
| Returns whether pointers are always serialized as content instead of references. | |
| void | setUsePointerContentSerialization (const bool &usePointerContentSerialization) |
| Sets whether to serialize pointer always as content instead of references. | |
| void | registerFactory (SerializableFactory *factory) |
Registers an SerializableFactory to support serialization of polymorphic classes. | |
Protected Types | |
| typedef std::vector < SerializableFactory * > | FactoryListType |
Type definition for an SerializableFactory list. | |
Protected Member Functions | |
| template<class T > | |
| std::string | convertDataToString (const T &data) |
Converts the given data to std::string. | |
| std::string | convertDataToString (const float &data) |
Converts the given data to std::string. | |
| std::string | convertDataToString (const double &data) |
Converts the given data to std::string. | |
| template<class T > | |
| void | convertStringToData (const std::string &str, T &data) |
Converts the given std::string to data. | |
| std::string | getTypeString (const std::type_info &type) |
Returns type string corresponding with given type, when it is supported by a registered factory. | |
| bool | isPrimitiveType (const std::type_info &type) const |
| Returns if given type is a primitive data type. | |
| bool | isPrimitivePointerType (const std::type_info &type) const |
| Returns if given type is a primitive data pointer type. | |
Protected Attributes | |
| TiXmlDocument | document_ |
| XML document that contains the already serialized or deserialized data. | |
| TiXmlNode * | node_ |
| bool | useAttributes_ |
If true all primitive data is serialized as XML attributes, otherwise as XML nodes. | |
| bool | usePointerContentSerialization_ |
| FactoryListType | factories_ |
List of registered SerializableFactory objects. | |
| std::vector< std::string > | errors_ |
| A list containing all error messages that were raised during serialization process. | |
Static Protected Attributes | |
| static const std::string | loggerCat_ = "voreen.XmlSerializerBase" |
| Category for logging. | |
Friends | |
| class | TemporaryNodeChanger |
| XML node for inserting or reading data. | |
| class | TemporaryUsePointerContentSerializationChanger |
If true all pointers are serialized as content instead of references. | |
Detailed Description
The XmlSerializerBase class encapsulates functions that are common to XmlSerializer and XmlDeserializer.
- See also:
- XmlSerializer
- XmlDeserializer
Definition at line 50 of file xmlserializerbase.h.
Member Typedef Documentation
typedef std::vector<SerializableFactory*> FactoryListType [protected] |
Type definition for an SerializableFactory list.
- Note:
- The
XmlSerializerBasedoes not own theSerializableFactoryobjects, so remember to delete theSerializableFactoryobjects where you have created them.
Definition at line 329 of file xmlserializerbase.h.
Member Function Documentation
| void addError | ( | const std::exception & | exception | ) |
Adds the error message of the given exception to the error list.
- Parameters:
-
exception the exception
Definition at line 68 of file xmlserializerbase.cpp.
| void addError | ( | const std::string & | message | ) |
Adds the given error message to the error list.
- Parameters:
-
message the error message
Definition at line 64 of file xmlserializerbase.cpp.
| std::string convertDataToString | ( | const double & | data | ) | [protected] |
Converts the given data to std::string.
- Template Parameters:
-
T type of data to convert
- Parameters:
-
data data to convert
- Returns:
- the string
Definition at line 180 of file xmlserializerbase.cpp.
| std::string convertDataToString | ( | const float & | data | ) | [protected] |
Converts the given data to std::string.
- Template Parameters:
-
T type of data to convert
- Parameters:
-
data data to convert
- Returns:
- the string
Definition at line 156 of file xmlserializerbase.cpp.
| std::string convertDataToString | ( | const T & | data | ) | [inline, protected] |
Converts the given data to std::string.
- Template Parameters:
-
T type of data to convert
- Parameters:
-
data data to convert
- Returns:
- the string
Definition at line 354 of file xmlserializerbase.h.
| void convertStringToData | ( | const std::string & | str, | |
| T & | data | |||
| ) | [inline, protected] |
Converts the given std::string to data.
- Template Parameters:
-
T type of data to convert
- Parameters:
-
str the string data variable to store converted data
Definition at line 361 of file xmlserializerbase.h.
| std::vector< std::string > getErrors | ( | ) | const |
| std::string getTypeString | ( | const std::type_info & | type | ) | [protected] |
Returns type string corresponding with given type, when it is supported by a registered factory.
- Parameters:
-
type the type
- Returns:
- either the type string or an empty string when the type is not supported by any registered factory.
Definition at line 81 of file xmlserializerbase.cpp.
| bool getUseAttributes | ( | ) | const |
Returns whether primitive data is serialized as XML attributes or XML nodes.
- Returns:
trueif primitive data is serialized as XML attributes andfalseotherwise
Definition at line 147 of file xmlserializerbase.cpp.
| bool getUsePointerContentSerialization | ( | ) | const |
Returns whether pointers are always serialized as content instead of references.
- Returns:
trueif pointers are always serialized as content andfalseotherwise
Definition at line 151 of file xmlserializerbase.cpp.
| bool isPrimitivePointerType | ( | const std::type_info & | type | ) | const [protected] |
Returns if given type is a primitive data pointer type.
- Returns:
trueif it is a primitive data pointer type andfalseotherwise.
Definition at line 113 of file xmlserializerbase.cpp.
| bool isPrimitiveType | ( | const std::type_info & | type | ) | const [protected] |
Returns if given type is a primitive data type.
- Returns:
trueif it is a primitive data type andfalseotherwise
Definition at line 91 of file xmlserializerbase.cpp.
| void raise | ( | const T & | exception | ) | throw (SerializationException) [inline] |
Adds the error message from the given exception to the error list and raise the exception afterwards.
- Template Parameters:
-
T exception type
- Parameters:
-
exception the exception
- Exceptions:
-
SerializationException the exception is always thrown
Definition at line 346 of file xmlserializerbase.h.
| void registerFactory | ( | SerializableFactory * | factory | ) |
Registers an SerializableFactory to support serialization of polymorphic classes.
- Attention:
- Ensure that the factory exists during the whole serialization process.
- Parameters:
-
factory the factory
Definition at line 135 of file xmlserializerbase.cpp.
| void setUseAttributes | ( | const bool & | useAttributes | ) |
Sets whether to serialize primitive data as XML attributes or XML nodes.
- Attention:
- All pointer references to primitive data which are serialized using XML attributes cannot be resolved. Furthermore using the same key for different values leads to a
XmlSerializationAttributeNamingException.
- Parameters:
-
useAttributes if trueserialize primitive data as XML attributes, otherwise as XML nodes
Definition at line 139 of file xmlserializerbase.cpp.
| void setUsePointerContentSerialization | ( | const bool & | usePointerContentSerialization | ) |
Sets whether to serialize pointer always as content instead of references.
- Attention:
- This is not a cascading setting, which means that contained pointers are not serialized as content.
- Serialization of all pointers as content can lead to redundant data.
- Parameters:
-
usePointerContentSerialization if truepointers are always serialized as content, otherwise as references when possible.
Definition at line 143 of file xmlserializerbase.cpp.
Member Data Documentation
TiXmlDocument document_ [protected] |
XML document that contains the already serialized or deserialized data.
- Attention:
- Keep in mind that may not all pointer references are already resolved.
Definition at line 304 of file xmlserializerbase.h.
FactoryListType factories_ [protected] |
List of registered SerializableFactory objects.
- Note:
SerializableFactoryobjects are necessary to support polymorphic class serialization.
Definition at line 337 of file xmlserializerbase.h.