|
Functionality designed for use by those requiring control over the inner mechanisms of the JSONInputArchive
|
void | startNode () |
| Starts a new node, going into its proper iterator. More...
|
|
void | finishNode () |
| Finishes the most recently started node. More...
|
|
const char * | getNodeName () const |
| Retrieves the current node name. More...
|
|
void | setNextName (const char *name) |
| Sets the name for the next node created with startNode. More...
|
|
template<class T , traits::EnableIf< std::is_signed< T >::value, sizeof(T)< sizeof(int64_t)>=traits::sfinae > inline void loadValue(T &val) { search();val=static_cast< T >(itsIteratorStack.back().value().GetInt());++itsIteratorStack.back();} template< class T, traits::EnableIf< std::is_unsigned< T >::value, sizeof(T)< sizeof(uint64_t), !std::is_same< bool, T >::value >=traits::sfinae > inline void loadValue(T &val) { search();val=static_cast< T >(itsIteratorStack.back().value().GetUint());++itsIteratorStack.back();} void loadValue(bool &val) { search();val=itsIteratorStack.back().value().GetBool();++itsIteratorStack.back();} void loadValue(int64_t &val) { search();val=itsIteratorStack.back().value().GetInt64();++itsIteratorStack.back();} void loadValue(uint64_t &val) { search();val=itsIteratorStack.back().value().GetUint64();++itsIteratorStack.back();} void loadValue(float &val) { search();val=static_cast< float >(itsIteratorStack.back().value().GetDouble());++itsIteratorStack.back();} void loadValue(double &val) { search();val=itsIteratorStack.back().value().GetDouble();++itsIteratorStack.back();} void loadValue(std::string &val) { search();val=itsIteratorStack.back().value().GetString();++itsIteratorStack.back();} void loadValue(std::nullptr_t &) { search();CEREAL_RAPIDJSON_ASSERT(itsIteratorStack.back().value().IsNull());++itsIteratorStack.back();} template< class T > inline typename std::enable_if<!std::is_same< T, int64_t >::value &&std::is_same< T, long long >::value, void >::type loadValue(T &val) { search();val=itsIteratorStack.back().value().GetInt64();++itsIteratorStack.back();} template< class T > inline typename std::enable_if<!std::is_same< T, uint64_t >::value &&std::is_same< T, unsigned long long >::value, void >::type loadValue(T &val) { search();val=itsIteratorStack.back().value().GetUint64();++itsIteratorStack.back();} private:template< class T > inline typename std::enable_if< sizeof(T)==sizeof(std::int32_t) &&std::is_signed< T >::value, void >::type loadLong(T &l){ loadValue(reinterpret_cast< std::int32_t & >(l));} template< class T > inline typename std::enable_if< sizeof(T)==sizeof(std::int64_t) &&std::is_signed< T >::value, void >::type loadLong(T &l){ loadValue(reinterpret_cast< std::int64_t & >(l));} template< class T > inline typename std::enable_if< sizeof(T)==sizeof(std::uint32_t) &&!std::is_signed< T >::value, void >::type loadLong(T &lu){ loadValue(reinterpret_cast< std::uint32_t & >(lu));} template< class T > inline typename std::enable_if< sizeof(T)==sizeof(std::uint64_t) &&!std::is_signed< T >::value, void >::type loadLong(T &lu){ loadValue(reinterpret_cast< std::uint64_t & >(lu));} public:template< class T > inline typename std::enable_if< std::is_same< T, long >::value &&sizeof(T) >=sizeof(std::int64_t) &&!std::is_same< T, std::int64_t >::value, void >::type loadValue(T &t){ loadLong(t);} template< class T > inline typename std::enable_if< std::is_same< T, unsigned long >::value &&sizeof(T) > = sizeof(std::uint64_t) && !std::is_same<T, std::uint64_t>::value, void > |
::type | loadValue (T &t) |
| Loads a value from the current node - small signed overload. More...
|
|
template<class T , traits::EnableIf< std::is_arithmetic< T >::value, !std::is_same< T, long >::value, !std::is_same< T, unsigned long >::value, !std::is_same< T, std::int64_t >::value, !std::is_same< T, std::uint64_t >::value, !std::is_same< T, long long >::value, !std::is_same< T, unsigned long long >::value,(sizeof(T) >=sizeof(long double)||sizeof(T) >=sizeof(long long))> = traits::sfinae> |
void | loadValue (T &val) |
| Loads a value from the current node - long double and long long overloads. More...
|
|
void | loadSize (size_type &size) |
| Loads the size for a SizeTag. More...
|
|
void | search () |
| Searches for the expectedName node if it doesn't match the actualName. More...
|
|
void | stringToNumber (std::string const &str, long long &val) |
| Convert a string to a long long. More...
|
|
void | stringToNumber (std::string const &str, unsigned long long &val) |
| Convert a string to an unsigned long long. More...
|
|
void | stringToNumber (std::string const &str, long double &val) |
| Convert a string to a long double. More...
|
|
An input archive designed to load data from JSON.
This archive uses RapidJSON to read in a JSON archive.
As with the output JSON archive, the preferred way to use this archive is in an RAII fashion, ensuring its destruction after all data has been read.
Input JSON should have been produced by the JSONOutputArchive. Data can only be added to dynamically sized containers (marked by JSON arrays) - the input archive will determine their size by looking at the number of child nodes. Only JSON originating from a JSONOutputArchive is officially supported, but data from other sources may work if properly formatted.
The JSONInputArchive does not require that nodes are loaded in the same order they were saved by JSONOutputArchive. 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:
ar( someData1, someData2, someData3 );
ar( cereal::make_nvp( "hello", someData6 ) );
ar( someData7, someData8, someData9 );
template<class T , traits::EnableIf< std::is_signed< T >::value, sizeof(T)< sizeof(int64_t)>=traits::sfinae > inline void loadValue(T &val) { search();val=static_cast< T >(itsIteratorStack.back().value().GetInt());++itsIteratorStack.back();} template< class T, traits::EnableIf< std::is_unsigned< T >::value, sizeof(T)< sizeof(uint64_t), !std::is_same< bool, T >::value >=traits::sfinae > inline void loadValue(T &val) { search();val=static_cast< T >(itsIteratorStack.back().value().GetUint());++itsIteratorStack.back();} void loadValue(bool &val) { search();val=itsIteratorStack.back().value().GetBool();++itsIteratorStack.back();} void loadValue(int64_t &val) { search();val=itsIteratorStack.back().value().GetInt64();++itsIteratorStack.back();} void loadValue(uint64_t &val) { search();val=itsIteratorStack.back().value().GetUint64();++itsIteratorStack.back();} void loadValue(float &val) { search();val=static_cast< float >(itsIteratorStack.back().value().GetDouble());++itsIteratorStack.back();} void loadValue(double &val) { search();val=itsIteratorStack.back().value().GetDouble();++itsIteratorStack.back();} void loadValue(std::string &val) { search();val=itsIteratorStack.back().value().GetString();++itsIteratorStack.back();} void loadValue(std::nullptr_t &) { search();CEREAL_RAPIDJSON_ASSERT(itsIteratorStack.back().value().IsNull());++itsIteratorStack.back();} template< class T > inline typename std::enable_if<!std::is_same< T, int64_t >::value &&std::is_same< T, long long >::value, void >::type loadValue(T &val) { search();val=itsIteratorStack.back().value().GetInt64();++itsIteratorStack.back();} template< class T > inline typename std::enable_if<!std::is_same< T, uint64_t >::value &&std::is_same< T, unsigned long long >::value, void >::type loadValue(T &val) { search();val=itsIteratorStack.back().value().GetUint64();++itsIteratorStack.back();} private:template< class T > inline typename std::enable_if< sizeof(T)==sizeof(std::int32_t) &&std::is_signed< T >::value, void >::type loadLong(T &l){ loadValue(reinterpret_cast< std::int32_t & >(l));} template< class T > inline typename std::enable_if< sizeof(T)==sizeof(std::int64_t) &&std::is_signed< T >::value, void >::type loadLong(T &l){ loadValue(reinterpret_cast< std::int64_t & >(l));} template< class T > inline typename std::enable_if< sizeof(T)==sizeof(std::uint32_t) &&!std::is_signed< T >::value, void >::type loadLong(T &lu){ loadValue(reinterpret_cast< std::uint32_t & >(lu));} template< class T > inline typename std::enable_if< sizeof(T)==sizeof(std::uint64_t) &&!std::is_signed< T >::value, void >::type loadLong(T &lu){ loadValue(reinterpret_cast< std::uint64_t & >(lu));} public:template< class T > inline typename std::enable_if< std::is_same< T, long >::value &&sizeof(T) >=sizeof(std::int64_t) &&!std::is_same< T, std::int64_t >::value, void >::type loadValue(T &t){ loadLong(t);} template< class T > inline typename std::enable_if< std::is_same< T, unsigned long >::value &&sizeof(T) > = sizeof(std::uint64_t) && !std::is_same<T, std::uint64_t>::value, void >
::type cereal::JSONInputArchive::loadValue |
( |
T & |
t | ) |
|
|
inline |
Loads a value from the current node - small signed overload.
template<class T , traits::EnableIf< std::is_arithmetic< T >::value, !std::is_same< T, long >::value, !std::is_same< T, unsigned long >::value, !std::is_same< T, std::int64_t >::value, !std::is_same< T, std::uint64_t >::value, !std::is_same< T, long long >::value, !std::is_same< T, unsigned long long >::value,(sizeof(T) >=sizeof(long double)||sizeof(T) >=sizeof(long long))> = traits::sfinae>
void cereal::JSONInputArchive::loadValue |
( |
T & |
val | ) |
|
|
inline |
Loads a value from the current node - long double and long long overloads.
void cereal::JSONInputArchive::startNode |
( |
| ) |
|
|
inline |
Starts a new node, going into its proper iterator.
This places an iterator for the next node to be parsed onto the iterator stack. If the next node is an array, this will be a value iterator, otherwise it will be a member iterator.
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 to do this; we'll just blindly load in the order things appear in.
If we were given an NVP, we will search for it if it does not match our the name of the next node that would normally be loaded. This functionality is provided by search().