removed ^M from some files, skeleton of input json

This commit is contained in:
Shane Grant
2013-07-08 11:42:34 -07:00
parent f70f34ae6e
commit 8d4a4194e2
5 changed files with 1723 additions and 1673 deletions

View File

@@ -34,6 +34,7 @@
#include <cereal/external/rapidjson/prettywriter.h> #include <cereal/external/rapidjson/prettywriter.h>
#include <cereal/external/rapidjson/genericstream.h> #include <cereal/external/rapidjson/genericstream.h>
#include <cereal/external/rapidjson/reader.h>
#include <cereal/external/base64.hpp> #include <cereal/external/base64.hpp>
#include <sstream> #include <sstream>
@@ -135,6 +136,11 @@ namespace cereal
the data encoded as a base64 string */ the data encoded as a base64 string */
void saveBinaryValue( const void * data, size_t size, const char * name = nullptr ) 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 setOutputType(bool outputType) void setOutputType(bool outputType)
@@ -142,8 +148,6 @@ namespace cereal
itsOutputType = outputType; itsOutputType = outputType;
} }
protected:
private: private:
WriteStream itsWriteStream; //!< Rapidjson write stream WriteStream itsWriteStream; //!< Rapidjson write stream
JSONWriter itsWriter; //!< Rapidjson writer JSONWriter itsWriter; //!< Rapidjson writer
@@ -153,18 +157,28 @@ namespace cereal
std::stack<uint32_t> itsNameCounter; //!< Counter for creating unique names for unnamed nodes std::stack<uint32_t> itsNameCounter; //!< Counter for creating unique names for unnamed nodes
}; // JSONOutputArchive }; // JSONOutputArchive
// ###################################################################### // ######################################################################
//! An input archive designed to load data from JSON //! An input archive designed to load data from JSON
/*! \note Not working yet! /*! \note Not working yet!
\ingroup Archives */ \ingroup Archives */
class JSONInputArchive class JSONInputArchive : public InputArchive<JSONInputArchive>
{ {
//typedef rapidjson::GenericWriteStream WriteStream;
//typedef rapidjson::PrettyWriter<WriteStream> JSONWriter;
public:
//! Construct, outputting to the provided stream
/*! @param stream The stream to output to. Can be a stringstream, a file stream, or
even cout! */
JSONInputArchive(std::istream & ) :
InputArchive<JSONInputArchive>(this)
{
}
}; };
// ###################################################################### // ######################################################################
// JSONArchive prologue and epilogue functions // JSONArchive prologue and epilogue functions
// ######################################################################
//! Prologue for NVPs for JSON archives //! Prologue for NVPs for JSON archives
/*! NVPs do not start or finish nodes - they just set up the names */ /*! NVPs do not start or finish nodes - they just set up the names */
@@ -235,6 +249,7 @@ namespace cereal
// ###################################################################### // ######################################################################
// Common JSONArchive serialization functions // Common JSONArchive serialization functions
// ######################################################################
//! Serializing NVP types to JSON //! Serializing NVP types to JSON
template <class Archive, class T> inline template <class Archive, class T> inline
@@ -248,7 +263,7 @@ namespace cereal
//! Serializing SizeTags to JSON //! Serializing SizeTags to JSON
template <class Archive, class T> inline template <class Archive, class T> inline
CEREAL_ARCHIVE_RESTRICT(JSONInputArchive, JSONOutputArchive) CEREAL_ARCHIVE_RESTRICT(JSONInputArchive, JSONOutputArchive)
serialize( Archive & ar, SizeTag<T> & ) serialize( Archive &, SizeTag<T> & )
{ } { }
//! Saving for arithmetic to JSON //! Saving for arithmetic to JSON
@@ -265,11 +280,10 @@ namespace cereal
{ {
ar.saveValue( str ); ar.saveValue( str );
} }
} // namespace cereal } // namespace cereal
// register archives for polymorphic support // register archives for polymorphic support
CEREAL_REGISTER_ARCHIVE(cereal::JSONInputArchive);
CEREAL_REGISTER_ARCHIVE(cereal::JSONOutputArchive); CEREAL_REGISTER_ARCHIVE(cereal::JSONOutputArchive);
#endif // CEREAL_ARCHIVES_JSON_HPP_ #endif // CEREAL_ARCHIVES_JSON_HPP_

View File

@@ -273,6 +273,14 @@ struct SubFixture
CEREAL_NVP(d), CEREAL_NVP(d),
CEREAL_NVP(s) ); CEREAL_NVP(s) );
} }
void change()
{
a = 4;
b = 4;
c = 4;
d = 4;
s = "4";
}
}; };
struct Fixture struct Fixture
@@ -286,6 +294,12 @@ struct Fixture
f3 ); f3 );
} }
void change()
{
f1.change();
f2.change();
f3.change();
}
}; };
void foo(int t) void foo(int t)
@@ -307,12 +321,34 @@ int main()
cereal::JSONOutputArchive oar( std::cout ); cereal::JSONOutputArchive oar( std::cout );
Fixture fixture; Fixture fixture;
oar( CEREAL_NVP(fixture) ); oar( CEREAL_NVP(fixture) );
std::vector<double> vecD = {1.23, 4.56, 7,89};
oar( CEREAL_NVP(vecD) );
bool b = true;
oar( cereal::make_nvp("coolean boolean", b) );
std::shared_ptr<std::string> sPtr = std::make_shared<std::string>("i'm a shared pointer");
oar( CEREAL_NVP(sPtr) );
int xxx[] = {-1, 95, 3};
oar.saveBinaryValue( xxx, sizeof(int)*3, "xxxbinary" );
oar.saveBinaryValue( xxx, sizeof(int)*3 );
} }
std::cout << std::endl; std::cout << std::endl;
{
cereal::JSONInputArchive iar( std::cin );
Fixture fixture; fixture.change();
//iar( fixture );
std::vector<double> vecD;
//iar( vecD );
}
return 0; return 0;
} }