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/genericstream.h>
#include <cereal/external/rapidjson/reader.h>
#include <cereal/external/base64.hpp>
#include <sstream>
@@ -135,6 +136,11 @@ namespace cereal
the data encoded as a base64 string */
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)
@@ -142,8 +148,6 @@ namespace cereal
itsOutputType = outputType;
}
protected:
private:
WriteStream itsWriteStream; //!< Rapidjson write stream
JSONWriter itsWriter; //!< Rapidjson writer
@@ -153,18 +157,28 @@ namespace cereal
std::stack<uint32_t> itsNameCounter; //!< Counter for creating unique names for unnamed nodes
}; // JSONOutputArchive
// ######################################################################
//! An input archive designed to load data from JSON
/*! \note Not working yet!
\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
// ######################################################################
//! Prologue for NVPs for JSON archives
/*! NVPs do not start or finish nodes - they just set up the names */
@@ -235,6 +249,7 @@ namespace cereal
// ######################################################################
// Common JSONArchive serialization functions
// ######################################################################
//! Serializing NVP types to JSON
template <class Archive, class T> inline
@@ -248,7 +263,7 @@ namespace cereal
//! Serializing SizeTags to JSON
template <class Archive, class T> inline
CEREAL_ARCHIVE_RESTRICT(JSONInputArchive, JSONOutputArchive)
serialize( Archive & ar, SizeTag<T> & )
serialize( Archive &, SizeTag<T> & )
{ }
//! Saving for arithmetic to JSON
@@ -265,11 +280,10 @@ namespace cereal
{
ar.saveValue( str );
}
} // namespace cereal
// register archives for polymorphic support
CEREAL_REGISTER_ARCHIVE(cereal::JSONInputArchive);
CEREAL_REGISTER_ARCHIVE(cereal::JSONOutputArchive);
#endif // CEREAL_ARCHIVES_JSON_HPP_

View File

@@ -273,6 +273,14 @@ struct SubFixture
CEREAL_NVP(d),
CEREAL_NVP(s) );
}
void change()
{
a = 4;
b = 4;
c = 4;
d = 4;
s = "4";
}
};
struct Fixture
@@ -286,6 +294,12 @@ struct Fixture
f3 );
}
void change()
{
f1.change();
f2.change();
f3.change();
}
};
void foo(int t)
@@ -307,12 +321,34 @@ int main()
cereal::JSONOutputArchive oar( std::cout );
Fixture 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;
{
cereal::JSONInputArchive iar( std::cin );
Fixture fixture; fixture.change();
//iar( fixture );
std::vector<double> vecD;
//iar( vecD );
}
return 0;
}