123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041 |
- #ifndef CEREAL_ARCHIVES_JSON_HPP_
- #define CEREAL_ARCHIVES_JSON_HPP_
- #include "cereal/cereal.hpp"
- #include "cereal/details/util.hpp"
- namespace cereal
- {
-
-
- struct RapidJSONException : Exception
- { RapidJSONException( const char * what_ ) : Exception( what_ ) {} };
- }
- #ifndef CEREAL_RAPIDJSON_ASSERT_THROWS
- #define CEREAL_RAPIDJSON_ASSERT_THROWS
- #endif
- #ifndef CEREAL_RAPIDJSON_ASSERT
- #define CEREAL_RAPIDJSON_ASSERT(x) if(!(x)){ \
- throw ::cereal::RapidJSONException("rapidjson internal assertion failure: " #x); }
- #endif
- #ifndef CEREAL_RAPIDJSON_WRITE_DEFAULT_FLAGS
- #define CEREAL_RAPIDJSON_WRITE_DEFAULT_FLAGS kWriteNanAndInfFlag
- #endif
- #ifndef CEREAL_RAPIDJSON_PARSE_DEFAULT_FLAGS
- #define CEREAL_RAPIDJSON_PARSE_DEFAULT_FLAGS kParseFullPrecisionFlag | kParseNanAndInfFlag
- #endif
- #include "cereal/external/rapidjson/prettywriter.h"
- #include "cereal/external/rapidjson/ostreamwrapper.h"
- #include "cereal/external/rapidjson/istreamwrapper.h"
- #include "cereal/external/rapidjson/document.h"
- #include "cereal/external/base64.hpp"
- #include <limits>
- #include <sstream>
- #include <stack>
- #include <vector>
- #include <string>
- namespace cereal
- {
-
-
-
- class JSONOutputArchive : public OutputArchive<JSONOutputArchive>, public traits::TextArchive
- {
- enum class NodeType { StartObject, InObject, StartArray, InArray };
- using WriteStream = CEREAL_RAPIDJSON_NAMESPACE::OStreamWrapper;
- using JSONWriter = CEREAL_RAPIDJSON_NAMESPACE::PrettyWriter<WriteStream>;
- public:
-
-
-
- class Options
- {
- public:
-
- static Options Default(){ return Options(); }
-
- static Options NoIndent(){ return Options( JSONWriter::kDefaultMaxDecimalPlaces, IndentChar::space, 0 ); }
-
- enum class IndentChar : char
- {
- space = ' ',
- tab = '\t',
- newline = '\n',
- carriage_return = '\r'
- };
-
-
- explicit Options( int precision = JSONWriter::kDefaultMaxDecimalPlaces,
- IndentChar indentChar = IndentChar::space,
- unsigned int indentLength = 4 ) :
- itsPrecision( precision ),
- itsIndentChar( static_cast<char>(indentChar) ),
- itsIndentLength( indentLength ) { }
- private:
- friend class JSONOutputArchive;
- int itsPrecision;
- char itsIndentChar;
- unsigned int itsIndentLength;
- };
-
-
- JSONOutputArchive(std::ostream & stream, Options const & options = Options::Default() ) :
- OutputArchive<JSONOutputArchive>(this),
- itsWriteStream(stream),
- itsWriter(itsWriteStream),
- itsNextName(nullptr)
- {
- itsWriter.SetMaxDecimalPlaces( options.itsPrecision );
- itsWriter.SetIndent( options.itsIndentChar, options.itsIndentLength );
- itsNameCounter.push(0);
- itsNodeStack.push(NodeType::StartObject);
- }
-
- ~JSONOutputArchive() CEREAL_NOEXCEPT
- {
- if (itsNodeStack.top() == NodeType::InObject)
- itsWriter.EndObject();
- else if (itsNodeStack.top() == NodeType::InArray)
- itsWriter.EndArray();
- }
-
-
- void saveBinaryValue( const void * data, size_t size, const char * name = nullptr )
- {
- setNextName( name );
- writeName();
- auto base64string = base64::encode( reinterpret_cast<const unsigned char *>( data ), size );
- saveValue( base64string );
- }
-
-
-
-
-
- void startNode()
- {
- writeName();
- itsNodeStack.push(NodeType::StartObject);
- itsNameCounter.push(0);
- }
-
- void finishNode()
- {
-
-
-
-
-
- switch(itsNodeStack.top())
- {
- case NodeType::StartArray:
- itsWriter.StartArray();
-
- case NodeType::InArray:
- itsWriter.EndArray();
- break;
- case NodeType::StartObject:
- itsWriter.StartObject();
-
- case NodeType::InObject:
- itsWriter.EndObject();
- break;
- }
- itsNodeStack.pop();
- itsNameCounter.pop();
- }
-
- void setNextName( const char * name )
- {
- itsNextName = name;
- }
-
- void saveValue(bool b) { itsWriter.Bool(b); }
-
- void saveValue(int i) { itsWriter.Int(i); }
-
- void saveValue(unsigned u) { itsWriter.Uint(u); }
-
- void saveValue(int64_t i64) { itsWriter.Int64(i64); }
-
- void saveValue(uint64_t u64) { itsWriter.Uint64(u64); }
-
- void saveValue(double d) { itsWriter.Double(d); }
-
- void saveValue(std::string const & s) { itsWriter.String(s.c_str(), static_cast<CEREAL_RAPIDJSON_NAMESPACE::SizeType>( s.size() )); }
-
- void saveValue(char const * s) { itsWriter.String(s); }
-
- void saveValue(std::nullptr_t) { itsWriter.Null(); }
- template <class T> inline
- typename std::enable_if<!std::is_same<T, int64_t>::value && std::is_same<T, long long>::value, void>::type
- saveValue(T val) { itsWriter.Int64(val); }
- 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
- saveValue(T val) { itsWriter.Uint64(val); }
- private:
-
-
-
- template <class T, traits::EnableIf<sizeof(T) == sizeof(std::int32_t),
- std::is_signed<T>::value> = traits::sfinae> inline
- void saveLong(T l){ saveValue( static_cast<std::int32_t>( l ) ); }
-
- template <class T, traits::EnableIf<sizeof(T) != sizeof(std::int32_t),
- std::is_signed<T>::value> = traits::sfinae> inline
- void saveLong(T l){ saveValue( static_cast<std::int64_t>( l ) ); }
-
- template <class T, traits::EnableIf<sizeof(T) == sizeof(std::int32_t),
- std::is_unsigned<T>::value> = traits::sfinae> inline
- void saveLong(T lu){ saveValue( static_cast<std::uint32_t>( lu ) ); }
-
- template <class T, traits::EnableIf<sizeof(T) != sizeof(std::int32_t),
- std::is_unsigned<T>::value> = traits::sfinae> inline
- void saveLong(T lu){ saveValue( static_cast<std::uint64_t>( lu ) ); }
- public:
- #if defined(_MSC_VER) && _MSC_VER < 1916
-
- void saveValue( unsigned long lu ){ saveLong( lu ); };
- #else
-
- template <class T, traits::EnableIf<std::is_same<T, long>::value,
- !std::is_same<T, int>::value,
- !std::is_same<T, std::int64_t>::value> = traits::sfinae> inline
- void saveValue( T t ){ saveLong( t ); }
-
- template <class T, traits::EnableIf<std::is_same<T, unsigned long>::value,
- !std::is_same<T, unsigned>::value,
- !std::is_same<T, std::uint64_t>::value> = traits::sfinae> inline
- void saveValue( T t ){ saveLong( t ); }
- #endif
-
-
- 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> inline
- void saveValue(T const & t)
- {
- std::stringstream ss; ss.precision( std::numeric_limits<long double>::max_digits10 );
- ss << t;
- saveValue( ss.str() );
- }
-
-
- void writeName()
- {
- NodeType const & nodeType = itsNodeStack.top();
-
- if(nodeType == NodeType::StartArray)
- {
- itsWriter.StartArray();
- itsNodeStack.top() = NodeType::InArray;
- }
- else if(nodeType == NodeType::StartObject)
- {
- itsNodeStack.top() = NodeType::InObject;
- itsWriter.StartObject();
- }
-
- if(nodeType == NodeType::InArray) return;
- if(itsNextName == nullptr)
- {
- std::string name = "value" + std::to_string( itsNameCounter.top()++ ) + "\0";
- saveValue(name);
- }
- else
- {
- saveValue(itsNextName);
- itsNextName = nullptr;
- }
- }
-
- void makeArray()
- {
- itsNodeStack.top() = NodeType::StartArray;
- }
-
- private:
- WriteStream itsWriteStream;
- JSONWriter itsWriter;
- char const * itsNextName;
- std::stack<uint32_t> itsNameCounter;
- std::stack<NodeType> itsNodeStack;
- };
-
-
-
- class JSONInputArchive : public InputArchive<JSONInputArchive>, public traits::TextArchive
- {
- private:
- using ReadStream = CEREAL_RAPIDJSON_NAMESPACE::IStreamWrapper;
- typedef CEREAL_RAPIDJSON_NAMESPACE::GenericValue<CEREAL_RAPIDJSON_NAMESPACE::UTF8<>> JSONValue;
- typedef JSONValue::ConstMemberIterator MemberIterator;
- typedef JSONValue::ConstValueIterator ValueIterator;
- typedef CEREAL_RAPIDJSON_NAMESPACE::Document::GenericValue GenericValue;
- public:
-
-
-
-
- JSONInputArchive(std::istream & stream) :
- InputArchive<JSONInputArchive>(this),
- itsNextName( nullptr ),
- itsReadStream(stream)
- {
- itsDocument.ParseStream<>(itsReadStream);
- if (itsDocument.IsArray())
- itsIteratorStack.emplace_back(itsDocument.Begin(), itsDocument.End());
- else
- itsIteratorStack.emplace_back(itsDocument.MemberBegin(), itsDocument.MemberEnd());
- }
- ~JSONInputArchive() CEREAL_NOEXCEPT = default;
-
-
- void loadBinaryValue( void * data, size_t size, const char * name = nullptr )
- {
- itsNextName = name;
- std::string encoded;
- loadValue( encoded );
- auto decoded = base64::decode( encoded );
- if( size != decoded.size() )
- throw Exception("Decoded binary data size does not match specified size");
- std::memcpy( data, decoded.data(), decoded.size() );
- itsNextName = nullptr;
- }
- private:
-
-
-
-
-
- class Iterator
- {
- public:
- Iterator() : itsIndex( 0 ), itsType(Null_) {}
- Iterator(MemberIterator begin, MemberIterator end) :
- itsMemberItBegin(begin), itsMemberItEnd(end), itsIndex(0), itsSize(std::distance(begin, end)), itsType(Member)
- {
- if( itsSize == 0 )
- itsType = Null_;
- }
- Iterator(ValueIterator begin, ValueIterator end) :
- itsValueItBegin(begin), itsIndex(0), itsSize(std::distance(begin, end)), itsType(Value)
- {
- if( itsSize == 0 )
- itsType = Null_;
- }
-
- Iterator & operator++()
- {
- ++itsIndex;
- return *this;
- }
-
- GenericValue const & value()
- {
- if( itsIndex >= itsSize )
- throw cereal::Exception("No more objects in input");
- switch(itsType)
- {
- case Value : return itsValueItBegin[itsIndex];
- case Member: return itsMemberItBegin[itsIndex].value;
- default: throw cereal::Exception("JSONInputArchive internal error: null or empty iterator to object or array!");
- }
- }
-
- const char * name() const
- {
- if( itsType == Member && (itsMemberItBegin + itsIndex) != itsMemberItEnd )
- return itsMemberItBegin[itsIndex].name.GetString();
- else
- return nullptr;
- }
-
-
- inline void search( const char * searchName )
- {
- const auto len = std::strlen( searchName );
- size_t index = 0;
- for( auto it = itsMemberItBegin; it != itsMemberItEnd; ++it, ++index )
- {
- const auto currentName = it->name.GetString();
- if( ( std::strncmp( searchName, currentName, len ) == 0 ) &&
- ( std::strlen( currentName ) == len ) )
- {
- itsIndex = index;
- return;
- }
- }
- throw Exception("JSON Parsing failed - provided NVP (" + std::string(searchName) + ") not found");
- }
- private:
- MemberIterator itsMemberItBegin, itsMemberItEnd;
- ValueIterator itsValueItBegin;
- size_t itsIndex, itsSize;
- enum Type {Value, Member, Null_} itsType;
- };
-
-
- inline void search()
- {
-
- auto localNextName = itsNextName;
- itsNextName = nullptr;
-
- if( localNextName )
- {
-
- auto const actualName = itsIteratorStack.back().name();
-
- if( !actualName || std::strcmp( localNextName, actualName ) != 0 )
- itsIteratorStack.back().search( localNextName );
- }
- }
- public:
-
-
- void startNode()
- {
- search();
- if(itsIteratorStack.back().value().IsArray())
- itsIteratorStack.emplace_back(itsIteratorStack.back().value().Begin(), itsIteratorStack.back().value().End());
- else
- itsIteratorStack.emplace_back(itsIteratorStack.back().value().MemberBegin(), itsIteratorStack.back().value().MemberEnd());
- }
-
- void finishNode()
- {
- itsIteratorStack.pop_back();
- ++itsIteratorStack.back();
- }
-
-
- const char * getNodeName() const
- {
- return itsIteratorStack.back().name();
- }
-
- void setNextName( const char * name )
- {
- itsNextName = name;
- }
-
- 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(); }
-
-
- #ifndef _MSC_VER
- 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 ){ loadLong(t); }
- #endif
- private:
-
- void stringToNumber( std::string const & str, long long & val ) { val = std::stoll( str ); }
-
- void stringToNumber( std::string const & str, unsigned long long & val ) { val = std::stoull( str ); }
-
- void stringToNumber( std::string const & str, long double & val ) { val = std::stold( str ); }
- public:
-
- 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>
- inline void loadValue(T & val)
- {
- std::string encoded;
- loadValue( encoded );
- stringToNumber( encoded, val );
- }
-
- void loadSize(size_type & size)
- {
- if (itsIteratorStack.size() == 1)
- size = itsDocument.Size();
- else
- size = (itsIteratorStack.rbegin() + 1)->value().Size();
- }
-
- private:
- const char * itsNextName;
- ReadStream itsReadStream;
- std::vector<Iterator> itsIteratorStack;
- CEREAL_RAPIDJSON_NAMESPACE::Document itsDocument;
- };
-
-
-
-
-
-
- template <class T> inline
- void prologue( JSONOutputArchive &, NameValuePair<T> const & )
- { }
-
- template <class T> inline
- void prologue( JSONInputArchive &, NameValuePair<T> const & )
- { }
-
-
-
- template <class T> inline
- void epilogue( JSONOutputArchive &, NameValuePair<T> const & )
- { }
-
-
- template <class T> inline
- void epilogue( JSONInputArchive &, NameValuePair<T> const & )
- { }
-
-
-
- template <class T> inline
- void prologue( JSONOutputArchive &, DeferredData<T> const & )
- { }
-
- template <class T> inline
- void prologue( JSONInputArchive &, DeferredData<T> const & )
- { }
-
-
-
- template <class T> inline
- void epilogue( JSONOutputArchive &, DeferredData<T> const & )
- { }
-
-
- template <class T> inline
- void epilogue( JSONInputArchive &, DeferredData<T> const & )
- { }
-
-
-
- template <class T> inline
- void prologue( JSONOutputArchive & ar, SizeTag<T> const & )
- {
- ar.makeArray();
- }
-
- template <class T> inline
- void prologue( JSONInputArchive &, SizeTag<T> const & )
- { }
-
-
-
- template <class T> inline
- void epilogue( JSONOutputArchive &, SizeTag<T> const & )
- { }
-
- template <class T> inline
- void epilogue( JSONInputArchive &, SizeTag<T> const & )
- { }
-
-
-
- template <class T, traits::EnableIf<!std::is_arithmetic<T>::value,
- !traits::has_minimal_base_class_serialization<T, traits::has_minimal_output_serialization, JSONOutputArchive>::value,
- !traits::has_minimal_output_serialization<T, JSONOutputArchive>::value> = traits::sfinae>
- inline void prologue( JSONOutputArchive & ar, T const & )
- {
- ar.startNode();
- }
-
- template <class T, traits::EnableIf<!std::is_arithmetic<T>::value,
- !traits::has_minimal_base_class_serialization<T, traits::has_minimal_input_serialization, JSONInputArchive>::value,
- !traits::has_minimal_input_serialization<T, JSONInputArchive>::value> = traits::sfinae>
- inline void prologue( JSONInputArchive & ar, T const & )
- {
- ar.startNode();
- }
-
-
-
- template <class T, traits::EnableIf<!std::is_arithmetic<T>::value,
- !traits::has_minimal_base_class_serialization<T, traits::has_minimal_output_serialization, JSONOutputArchive>::value,
- !traits::has_minimal_output_serialization<T, JSONOutputArchive>::value> = traits::sfinae>
- inline void epilogue( JSONOutputArchive & ar, T const & )
- {
- ar.finishNode();
- }
-
- template <class T, traits::EnableIf<!std::is_arithmetic<T>::value,
- !traits::has_minimal_base_class_serialization<T, traits::has_minimal_input_serialization, JSONInputArchive>::value,
- !traits::has_minimal_input_serialization<T, JSONInputArchive>::value> = traits::sfinae>
- inline void epilogue( JSONInputArchive & ar, T const & )
- {
- ar.finishNode();
- }
-
-
- inline
- void prologue( JSONOutputArchive & ar, std::nullptr_t const & )
- {
- ar.writeName();
- }
-
- inline
- void prologue( JSONInputArchive &, std::nullptr_t const & )
- { }
-
-
- inline
- void epilogue( JSONOutputArchive &, std::nullptr_t const & )
- { }
-
- inline
- void epilogue( JSONInputArchive &, std::nullptr_t const & )
- { }
-
-
- template <class T, traits::EnableIf<std::is_arithmetic<T>::value> = traits::sfinae> inline
- void prologue( JSONOutputArchive & ar, T const & )
- {
- ar.writeName();
- }
-
- template <class T, traits::EnableIf<std::is_arithmetic<T>::value> = traits::sfinae> inline
- void prologue( JSONInputArchive &, T const & )
- { }
-
-
- template <class T, traits::EnableIf<std::is_arithmetic<T>::value> = traits::sfinae> inline
- void epilogue( JSONOutputArchive &, T const & )
- { }
-
- template <class T, traits::EnableIf<std::is_arithmetic<T>::value> = traits::sfinae> inline
- void epilogue( JSONInputArchive &, T const & )
- { }
-
-
- template<class CharT, class Traits, class Alloc> inline
- void prologue(JSONOutputArchive & ar, std::basic_string<CharT, Traits, Alloc> const &)
- {
- ar.writeName();
- }
-
- template<class CharT, class Traits, class Alloc> inline
- void prologue(JSONInputArchive &, std::basic_string<CharT, Traits, Alloc> const &)
- { }
-
-
- template<class CharT, class Traits, class Alloc> inline
- void epilogue(JSONOutputArchive &, std::basic_string<CharT, Traits, Alloc> const &)
- { }
-
- template<class CharT, class Traits, class Alloc> inline
- void epilogue(JSONInputArchive &, std::basic_string<CharT, Traits, Alloc> const &)
- { }
-
-
-
-
- template <class T> inline
- void CEREAL_SAVE_FUNCTION_NAME( JSONOutputArchive & ar, NameValuePair<T> const & t )
- {
- ar.setNextName( t.name );
- ar( t.value );
- }
- template <class T> inline
- void CEREAL_LOAD_FUNCTION_NAME( JSONInputArchive & ar, NameValuePair<T> & t )
- {
- ar.setNextName( t.name );
- ar( t.value );
- }
-
- inline
- void CEREAL_SAVE_FUNCTION_NAME(JSONOutputArchive & ar, std::nullptr_t const & t)
- {
- ar.saveValue( t );
- }
-
- inline
- void CEREAL_LOAD_FUNCTION_NAME(JSONInputArchive & ar, std::nullptr_t & t)
- {
- ar.loadValue( t );
- }
-
- template <class T, traits::EnableIf<std::is_arithmetic<T>::value> = traits::sfinae> inline
- void CEREAL_SAVE_FUNCTION_NAME(JSONOutputArchive & ar, T const & t)
- {
- ar.saveValue( t );
- }
-
- template <class T, traits::EnableIf<std::is_arithmetic<T>::value> = traits::sfinae> inline
- void CEREAL_LOAD_FUNCTION_NAME(JSONInputArchive & ar, T & t)
- {
- ar.loadValue( t );
- }
-
- template<class CharT, class Traits, class Alloc> inline
- void CEREAL_SAVE_FUNCTION_NAME(JSONOutputArchive & ar, std::basic_string<CharT, Traits, Alloc> const & str)
- {
- ar.saveValue( str );
- }
-
- template<class CharT, class Traits, class Alloc> inline
- void CEREAL_LOAD_FUNCTION_NAME(JSONInputArchive & ar, std::basic_string<CharT, Traits, Alloc> & str)
- {
- ar.loadValue( str );
- }
-
-
- template <class T> inline
- void CEREAL_SAVE_FUNCTION_NAME( JSONOutputArchive &, SizeTag<T> const & )
- {
-
- }
-
- template <class T> inline
- void CEREAL_LOAD_FUNCTION_NAME( JSONInputArchive & ar, SizeTag<T> & st )
- {
- ar.loadSize( st.size );
- }
- }
- CEREAL_REGISTER_ARCHIVE(cereal::JSONInputArchive)
- CEREAL_REGISTER_ARCHIVE(cereal::JSONOutputArchive)
- CEREAL_SETUP_ARCHIVE_TRAITS(cereal::JSONInputArchive, cereal::JSONOutputArchive)
- #endif
|