cereal
A C++11 library for serialization
|
An output archive designed to load data from XML. More...
#include </home/shane/workspace/cereal/include/cereal/archives/xml.hpp>
Classes | |
struct | NodeInfo |
A struct that contains metadata about a node. More... | |
Public Member Functions | |
Common Functionality | |
Common use cases for directly interacting with an XMLInputArchive | |
XMLInputArchive (std::istream &stream) | |
Construct, reading in from the provided stream. More... | |
~XMLInputArchive () CEREAL_NOEXCEPT=default | |
void | loadBinaryValue (void *data, size_t size, const char *name=nullptr) |
Loads some binary data, encoded as a base64 string, optionally specified by some name. More... | |
Public Member Functions inherited from cereal::InputArchive< XMLInputArchive > | |
InputArchive (XMLInputArchive *const derived) | |
Construct the output archive. More... | |
InputArchive & | operator= (InputArchive const &)=delete |
XMLInputArchive & | operator() (Types &&... args) |
Serializes all passed in data. More... | |
void | serializeDeferments () |
Serializes any data marked for deferment using defer. More... | |
std::shared_ptr< void > | getSharedPointer (std::uint32_t const id) |
Retrieves a shared pointer given a unique key for it. More... | |
void | registerSharedPointer (std::uint32_t const id, std::shared_ptr< void > ptr) |
Registers a shared pointer to its unique identifier. More... | |
std::string | getPolymorphicName (std::uint32_t const id) |
Retrieves the string for a polymorphic type given a unique key for it. More... | |
void | registerPolymorphicName (std::uint32_t const id, std::string const &name) |
Registers a polymorphic name string to its unique identifier. More... | |
XMLInputArchive & | operator& (T &&arg) |
Serializes passed in data. More... | |
XMLInputArchive & | operator>> (T &&arg) |
Serializes passed in data. More... | |
Public Member Functions inherited from cereal::detail::InputArchiveBase | |
InputArchiveBase (InputArchiveBase &&) CEREAL_NOEXCEPT | |
InputArchiveBase & | operator= (InputArchiveBase &&) CEREAL_NOEXCEPT |
Internal Functionality | |
Functionality designed for use by those requiring control over the inner mechanisms of the XMLInputArchive | |
template<class T > | |
value | |
Loads a type best represented as an int from the current top node. | |
void | startNode () |
Prepares to start reading the next node. More... | |
void | finishNode () |
Finishes reading the current node. | |
const char * | getNodeName () const |
void | setNextName (const char *name) |
Sets the name for the next node created with startNode. | |
template<class T , traits::EnableIf< std::is_unsigned< T >::value, std::is_same< T, bool >::value > = traits::sfinae> | |
void | loadValue (T &value) |
Loads a bool from the current top node. | |
template<class T , traits::EnableIf< std::is_integral< T >::value, !std::is_same< T, bool >::value, sizeof(T)==sizeof(char)> = traits::sfinae> | |
void | loadValue (T &value) |
Loads a char (signed or unsigned) from the current top node. | |
void | loadValue (int8_t &value) |
Load an int8_t from the current top node (ensures we parse entire number) | |
void | loadValue (uint8_t &value) |
Load a uint8_t from the current top node (ensures we parse entire number) | |
template<class T , traits::EnableIf< std::is_unsigned< T >::value, !std::is_same< T, bool >::value, !std::is_same< T, char >::value, !std::is_same< T, unsigned char >::value, sizeof(T)< sizeof(long long)>=traits::sfinae > inline void loadValue(T &value) { value=static_cast< T >(std::stoul(itsNodes.top().node->value()));} template< class T, traits::EnableIf< std::is_unsigned< T >::value, !std::is_same< T, bool >::value, sizeof(T) >=sizeof(long long)> = traits::sfinae> | |
void | loadValue (T &value) |
Loads a type best represented as an unsigned long from the current top node. | |
if (std::fpclassify(value) !=FP_SUBNORMAL) throw | |
void | loadValue (long double &value) |
Loads a type best represented as a long double from the current top node. | |
template<class CharT , class Traits , class Alloc > | |
void | loadValue (std::basic_string< CharT, Traits, Alloc > &str) |
Loads a string from the current node from the current top node. | |
template<class T > | |
void | loadSize (T &value) |
Loads the size of the current top node. | |
static size_t | getNumChildren (rapidxml::xml_node<> *node) |
Gets the number of children (usually interpreted as size) for the specified node. | |
Additional Inherited Members | |
Public Types inherited from cereal::InputArchive< XMLInputArchive > | |
using | is_loading = std::true_type |
Indicates this archive is intended for loading. More... | |
using | is_saving = std::false_type |
Indicates this archive is not intended for saving. More... | |
An output archive designed to load data from XML.
This archive uses RapidXML to build an in memory XML tree of the data in the stream it is given before loading any types serialized.
As with the output XML archive, the preferred way to use this archive is in an RAII fashion, ensuring its destruction after all data has been read.
Input XML should have been produced by the XMLOutputArchive. Data can only be added to dynamically sized containers - the input archive will determine their size by looking at the number of child nodes. Data that did not originate from an XMLOutputArchive is not officially supported, but may be possible to use if properly formatted.
The XMLInputArchive does not require that nodes are loaded in the same order they were saved by XMLOutputArchive. Using name value pairs (NVPs), it is possible to load in an out of order fashion or otherwise skip/select specific nodes to load.
The default behavior of the input archive is to read sequentially starting with the first node and exploring its children. When a given NVP does not match the read in name for a node, the archive will search for that node at the current level and load it if it exists. After loading an out of order node, the archive will then proceed back to loading sequentially from its new position.
Consider this simple example where loading of some data is skipped:
|
inline |
Construct, reading in from the provided stream.
Reads in an entire XML document from some stream and parses it as soon as serialization starts
stream | The stream to read from. Can be a stringstream or a file. |
|
inline |
Retrieves the current node name will return nullptr
if the node does not have a name
|
inline |
Loads some binary data, encoded as a base64 string, optionally specified by some name.
This will automatically start and finish a node to load the data, and can be called directly by users.
Note that this follows the same ordering rules specified in the class description in regards to loading in/out of order
|
inline |
Prepares to start reading the next node.
This places the next node to be parsed onto the nodes stack.
By default our strategy is to start with the document root node and then recursively iterate through all children in the order they show up in the document. We don't need to know NVPs do to this; we'll just blindly load in the order things appear in.
We check to see if the specified NVP matches what the next automatically loaded node is. If they match, we just continue as normal, going in order. If they don't match, we attempt to find a node named after the NVP that is being loaded. If that NVP does not exist, we throw an exception.