#include <s11n_node.hpp>
Public Types | |
typedef std::map< std::string, std::string > | map_type |
The map type this object uses to store properties. | |
typedef map_type::value_type | value_type |
A pair type used to store key/value properties internally. | |
typedef map_type::key_type | key_type |
The type used to store property keys. | |
typedef map_type::mapped_type | mapped_type |
The type used to internally store property values. | |
typedef std::vector< s11n_node * > | child_list_type |
The container type used to store this object's children. | |
Public Member Functions | |
s11n_node () | |
Creates a new node with an empty name() and an class_name() of "s11n::s11n_node". | |
s11n_node (const std::string &name) | |
Creates a new node with the given name() and an class_name() of "s11n::s11n_node". | |
s11n_node (const std::string &name, const std::string implclass) | |
Creates a new node with the given name() and and class_name(). | |
~s11n_node () | |
Destroys all child objects owned by this object, freeing up their resources. | |
void | swap (s11n_node &rhs) |
Swaps all publically-visible internal state with rhs. | |
s11n_node & | operator= (const s11n_node &rhs) |
Copies the properties, name, class name and children of rhs. | |
s11n_node (const s11n_node &rhs) | |
See copy(). | |
child_list_type & | children () |
Returns a list of the s11n_node children of this object. | |
const child_list_type & | children () const |
The const form of children(). | |
void | clear () |
Removes all properties and deletes all children from this object, freeing up their resources. | |
void | class_name (const std::string &n) |
Defines the class name which should be used as the implementation class when this node is deserialize()d. | |
std::string | class_name () const |
Returns the implementation class name set via class_name(). | |
void | name (const std::string &n) |
The name which should be used as the key for storing the node. | |
std::string | name () const |
Returns this node's name, as set via name(string). | |
bool | empty () const |
Returns true if this object has no properties and no children. | |
template<typename T> | |
void | set (const std::string &key, const T &val) |
Lexically casts val to a string and stores it as a property. | |
template<typename T> | |
T | get (const std::string &key, const T &defaultval) const |
Tries to get a property named key and lexically cast it to type T. | |
bool | is_set (const std::string &key) const |
Returns true if this object contains the given property, else false. | |
void | unset (const std::string &key) |
Removes the given property from this object. | |
map_type & | properties () |
Returns the map of properties contained by this node. | |
const map_type & | properties () const |
Const overload. |
It will become the standard node type for s11nlite in 1.1/1.2.
Definition at line 24 of file s11n_node.hpp.
typedef std::map< std::string, std::string > s11n::s11n_node::map_type |
typedef map_type::value_type s11n::s11n_node::value_type |
A pair type used to store key/value properties internally.
Definition at line 37 of file s11n_node.hpp.
typedef map_type::key_type s11n::s11n_node::key_type |
The type used to store property keys.
For compatibility with std::map.
Definition at line 42 of file s11n_node.hpp.
typedef map_type::mapped_type s11n::s11n_node::mapped_type |
The type used to internally store property values.
For compatibility with std::map.
Definition at line 47 of file s11n_node.hpp.
typedef std::vector<s11n_node *> s11n::s11n_node::child_list_type |
The container type used to store this object's children.
It contains (s11n_node *).
While the exact type is not guaranteed, it is guaranteed to obey the most-commonly-used std::list/vector conventions: push_back(), erase(), etc.
Definition at line 58 of file s11n_node.hpp.
s11n::s11n_node::s11n_node | ( | ) |
Creates a new node with an empty name() and an class_name() of "s11n::s11n_node".
This node is functionally useless until it's name is set, as nodes with empty names are not supported by any current i/o parsers.
s11n::s11n_node::s11n_node | ( | const std::string & | name | ) | [explicit] |
Creates a new node with the given name() and an class_name() of "s11n::s11n_node".
s11n::s11n_node::s11n_node | ( | const std::string & | name, | |
const std::string | implclass | |||
) |
Creates a new node with the given name() and and class_name().
Does not throw.
s11n::s11n_node::~s11n_node | ( | ) |
Destroys all child objects owned by this object, freeing up their resources.
Does not throw.
s11n::s11n_node::s11n_node | ( | const s11n_node & | rhs | ) |
See copy().
Does not throw.
void s11n::s11n_node::swap | ( | s11n_node & | rhs | ) |
Swaps all publically-visible internal state with rhs.
This includes:
Complexity is, in theory, constant time. For all data we use their member swap() implementations, which should be constant-time for the containers. The C++ Standard apparently guarantees O(1) swap() for strings, too. (Josuttis, The C++ Standard Library, section 11.2.8, page 490.)
Added in version 1.1.3.
Copies the properties, name, class name and children of rhs.
If rhs is this object then this function does nothing.
Does not throw.
child_list_type& s11n::s11n_node::children | ( | ) |
Returns a list of the s11n_node children of this object.
The caller should not delete any pointers from this list unless he also removes the pointers from the list, or else they will get double-deleted later. In practice it is (almost) never necessary for client code to manipulate this list directly.
const child_list_type& s11n::s11n_node::children | ( | ) | const |
The const form of children().
void s11n::s11n_node::clear | ( | ) |
Removes all properties and deletes all children from this object, freeing up their resources.
Any pointers to children of this object become invalided by a call to this function (they get deleted).
void s11n::s11n_node::class_name | ( | const std::string & | n | ) |
Defines the class name which should be used as the implementation class when this node is deserialize()d.
Client Serializable types should call this one time from their serialize() method, after calling the parent class' serialize() method (if indeed that is called at all), passing it the name of their class, using the name expected by the classloader. By convention the class name is the same as it's C++ name, thus Serializable class foo::FooBar should call:
node.class_name( "foo::FooBar" );
from it's serialize() function.
If classes to not set this then the serialized data will not have a proper implementation class name. That is likely to break deserialization.
TODO: consider returning the old value, to simplify swap() operations.
Added in 1.1.3.
std::string s11n::s11n_node::class_name | ( | ) | const |
Returns the implementation class name set via class_name().
void s11n::s11n_node::name | ( | const std::string & | n | ) |
The name which should be used as the key for storing the node.
This is normally translated to something like an XML element name (e.g., <name>), and should not contain spaces or other characters which may not be usable as key names. To be safe, stick to alphanumeric and underscores, starting with a letter or underscore. (This class does no enforce any naming conventions, but your data file parsers very well may.)
std::string s11n::s11n_node::name | ( | ) | const |
Returns this node's name, as set via name(string).
bool s11n::s11n_node::empty | ( | ) | const |
Returns true if this object has no properties and no children.
The name() and class_name() are *not* considered.
void s11n::s11n_node::set | ( | const std::string & | key, | |
const T & | val | |||
) | [inline] |
Lexically casts val to a string and stores it as a property.
If this type conversion is not possible it will fail at compile time. A value-conversion failure, on the other hand, is not caught at compile time. T must support complementary ostream<< and istream>> operators.
Definition at line 227 of file s11n_node.hpp.
T s11n::s11n_node::get | ( | const std::string & | key, | |
const T & | defaultval | |||
) | const [inline] |
Tries to get a property named key and lexically cast it to type T.
If this type conversion is not possible it will fail at compile time. A value-conversion failure, on the other hand, is not caught at compile time. If value conversion fails, or if the requested property is not set, then defaultval is returned. This can be interpretted as an error value if the client so chooses, and it is often helpful to pass a known-invalid value here for that purpose.
Definition at line 246 of file s11n_node.hpp.
bool s11n::s11n_node::is_set | ( | const std::string & | key | ) | const |
Returns true if this object contains the given property, else false.
void s11n::s11n_node::unset | ( | const std::string & | key | ) |
Removes the given property from this object.
map_type& s11n::s11n_node::properties | ( | ) |
Returns the map of properties contained by this node.
const map_type& s11n::s11n_node::properties | ( | ) | const |
Const overload.