mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
Making makefile a bit nicer, moving some code around in xml.hpp to better organize it
This commit is contained in:
17
Makefile
17
Makefile
@@ -1,27 +1,27 @@
|
|||||||
CPPFLAGS=-std=c++11 -I./include -Wall -Werror -g
|
CPPFLAGS=-std=c++11 -I./include -Wall -Werror -g
|
||||||
CC=g++
|
CXX=g++
|
||||||
COVERAGE_OUTPUT=out
|
COVERAGE_OUTPUT=out
|
||||||
|
|
||||||
all: unittests sandbox performance sandbox_rtti sandbox_json
|
all: unittests sandbox performance sandbox_rtti sandbox_json
|
||||||
|
|
||||||
sandbox: sandbox.cpp
|
sandbox: sandbox.cpp
|
||||||
${CC} sandbox.cpp -o sandbox ${CPPFLAGS}
|
${CXX} sandbox.cpp -o sandbox ${CPPFLAGS}
|
||||||
|
|
||||||
sandbox_json: sandbox_json.cpp
|
sandbox_json: sandbox_json.cpp
|
||||||
${CC} sandbox_json.cpp -o sandbox_json ${CPPFLAGS}
|
${CXX} sandbox_json.cpp -o sandbox_json ${CPPFLAGS}
|
||||||
|
|
||||||
sandbox_rtti: sandbox_rtti.cpp
|
sandbox_rtti: sandbox_rtti.cpp
|
||||||
${CC} sandbox_rtti.cpp -o sandbox_rtti ${CPPFLAGS} -O3
|
${CXX} sandbox_rtti.cpp -o sandbox_rtti ${CPPFLAGS} -O3
|
||||||
|
|
||||||
sandbox_vs: sandbox_vs.cpp
|
sandbox_vs: sandbox_vs.cpp
|
||||||
${CC} sandbox_vs.cpp -o sandbox_vs ${CPPFLAGS}
|
${CXX} sandbox_vs.cpp -o sandbox_vs ${CPPFLAGS}
|
||||||
|
|
||||||
unittests: unittests.cpp
|
unittests: unittests.cpp
|
||||||
${CC} unittests.cpp -o unittests -lboost_unit_test_framework ${CPPFLAGS}
|
${CXX} unittests.cpp -o unittests -lboost_unit_test_framework ${CPPFLAGS}
|
||||||
./unittests --show_progress
|
./unittests --show_progress
|
||||||
|
|
||||||
performance: performance.cpp
|
performance: performance.cpp
|
||||||
${CC} performance.cpp -o performance -lboost_serialization ${CPPFLAGS} -O3
|
${CXX} performance.cpp -o performance -lboost_serialization ${CPPFLAGS} -O3
|
||||||
|
|
||||||
.PHONY: coverage
|
.PHONY: coverage
|
||||||
coverage:
|
coverage:
|
||||||
@@ -35,5 +35,6 @@ coverage:
|
|||||||
doc:
|
doc:
|
||||||
@doxygen ./doc/doxygen.cfg
|
@doxygen ./doc/doxygen.cfg
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm sandbox; rm unittests; rm performance; rm sandbox_rtti; rm sandbox_json;
|
-@rm *.o sandbox unittests performance sandbox_rtti sandbox_json 2>/dev/null || true
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ namespace cereal
|
|||||||
class XMLOutputArchive : public OutputArchive<XMLOutputArchive>
|
class XMLOutputArchive : public OutputArchive<XMLOutputArchive>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/*! @name External Functionality
|
||||||
|
Common use cases for directly interacting with an XMLOutputArchive */
|
||||||
|
//! @{
|
||||||
|
|
||||||
//! Construct, outputting to the provided stream upon destruction
|
//! Construct, outputting to the provided stream upon destruction
|
||||||
/*! @param stream The stream to output to. Can be a stringstream, a file stream, or
|
/*! @param stream The stream to output to. Can be a stringstream, a file stream, or
|
||||||
even cout! Note that since this archive builds a tree in memory,
|
even cout! Note that since this archive builds a tree in memory,
|
||||||
@@ -117,6 +121,30 @@ namespace cereal
|
|||||||
itsXML.clear();
|
itsXML.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Saves some binary data, encoded as a base64 string, with an optional name
|
||||||
|
/*! This will create a new node, optionally named, and insert a value that consists of
|
||||||
|
the data encoded as a base64 string */
|
||||||
|
void saveBinaryValue( const void * data, size_t size, const char * name = nullptr )
|
||||||
|
{
|
||||||
|
itsNodes.top().name = name;
|
||||||
|
|
||||||
|
startNode();
|
||||||
|
|
||||||
|
auto base64string = base64::encode( reinterpret_cast<const unsigned char *>( data ), size );
|
||||||
|
saveValue( base64string );
|
||||||
|
|
||||||
|
if( itsOutputType )
|
||||||
|
itsNodes.top().node->append_attribute( itsXML.allocate_attribute( "type", "cereal binary data" ) );
|
||||||
|
|
||||||
|
finishNode();
|
||||||
|
};
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
/*! @name Internal Functionality
|
||||||
|
Functionality designed for use by those requiring control over the inner mechanisms of
|
||||||
|
the XMLOutputArchive */
|
||||||
|
//! @{
|
||||||
|
|
||||||
//! Creates a new node that is a child of the node at the top of the stack
|
//! Creates a new node that is a child of the node at the top of the stack
|
||||||
/*! Nodes will be given a name that has either been pre-set by a name value pair,
|
/*! Nodes will be given a name that has either been pre-set by a name value pair,
|
||||||
or generated based upon a counter unique to the parent node.
|
or generated based upon a counter unique to the parent node.
|
||||||
@@ -177,24 +205,6 @@ namespace cereal
|
|||||||
saveValue( static_cast<int32_t>( value ) );
|
saveValue( static_cast<int32_t>( value ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Saves some binary data, encoded as a base64 string, with an optional name
|
|
||||||
/*! This will create a new node, optionally named, and insert a value that consists of
|
|
||||||
the data encoded as a base64 string */
|
|
||||||
void saveBinaryValue( const void * data, size_t size, const char * name = nullptr )
|
|
||||||
{
|
|
||||||
itsNodes.top().name = name;
|
|
||||||
|
|
||||||
startNode();
|
|
||||||
|
|
||||||
auto base64string = base64::encode( reinterpret_cast<const unsigned char *>( data ), size );
|
|
||||||
saveValue( base64string );
|
|
||||||
|
|
||||||
if( itsOutputType )
|
|
||||||
itsNodes.top().node->append_attribute( itsXML.allocate_attribute( "type", "cereal binary data" ) );
|
|
||||||
|
|
||||||
finishNode();
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Causes the type to be appended to the most recently made node if output type is set to true
|
//! Causes the type to be appended to the most recently made node if output type is set to true
|
||||||
template <class T> inline
|
template <class T> inline
|
||||||
void insertType()
|
void insertType()
|
||||||
@@ -251,6 +261,8 @@ namespace cereal
|
|||||||
}
|
}
|
||||||
}; // NodeInfo
|
}; // NodeInfo
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ostream & itsStream; //!< The output stream
|
std::ostream & itsStream; //!< The output stream
|
||||||
rapidxml::xml_document<> itsXML; //!< The XML document
|
rapidxml::xml_document<> itsXML; //!< The XML document
|
||||||
|
|||||||
@@ -313,15 +313,23 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
cereal::JSONOutputArchive archive( std::cout );
|
cereal::JSONOutputArchive archive( std::cout );
|
||||||
bool arr[] = {true, false};
|
bool arr[] = {true, false};
|
||||||
std::vector<int> vec = {1, 2, 3, 4, 5};
|
std::vector<int> vec = {1, 2, 3, 4, 5};
|
||||||
archive( CEREAL_NVP(vec),
|
archive( CEREAL_NVP(vec),
|
||||||
arr );
|
arr );
|
||||||
auto f = std::make_shared<Fixture>();
|
auto f = std::make_shared<Fixture>();
|
||||||
auto f2 = f;
|
auto f2 = f;
|
||||||
archive( f );
|
archive( f );
|
||||||
archive( f2 );
|
archive( f2 );
|
||||||
|
|
||||||
|
enum Bla
|
||||||
|
{
|
||||||
|
x,
|
||||||
|
y
|
||||||
|
};
|
||||||
|
|
||||||
|
archive( Bla::x );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user