From 70c442063276dda50353f2cba8bc79dab7f62098 Mon Sep 17 00:00:00 2001 From: Shane Grant Date: Sun, 12 Feb 2017 00:25:30 -0800 Subject: [PATCH 1/3] Update README.md add appveyor badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c4aaf2a03..1001f502a 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ cereal is licensed under the [BSD license](http://opensource.org/licenses/BSD-3- ## cereal build status * develop : [![Build Status](https://travis-ci.org/USCiLab/cereal.png?branch=develop)](https://travis-ci.org/USCiLab/cereal) +[![Build status](https://ci.appveyor.com/api/projects/status/91aou6smj36or0vb/branch/develop?svg=true)](https://ci.appveyor.com/project/AzothAmmo/cereal/branch/develop) --- From 52b03d58c5000c94a78f7474fc62f0823509c7fe Mon Sep 17 00:00:00 2001 From: Robin Hoens Date: Mon, 10 Apr 2017 17:13:39 +0200 Subject: [PATCH 2/3] Add option to turn off the size=dynamic attributes of lists --- include/cereal/archives/xml.hpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/include/cereal/archives/xml.hpp b/include/cereal/archives/xml.hpp index c520f02e2..a6c3a0ffb 100644 --- a/include/cereal/archives/xml.hpp +++ b/include/cereal/archives/xml.hpp @@ -119,13 +119,22 @@ namespace cereal bool outputType = false ) : itsPrecision( precision ), itsIndent( indent ), - itsOutputType( outputType ) { } + itsOutputType( outputType ), + itsSizeAttributes(true) + { } + + Options& NoSizeAttributes() + { + itsSizeAttributes = false; + return *this; + } private: friend class XMLOutputArchive; int itsPrecision; bool itsIndent; bool itsOutputType; + bool itsSizeAttributes; }; //! Construct, outputting to the provided stream upon destruction @@ -137,7 +146,8 @@ namespace cereal OutputArchive(this), itsStream(stream), itsOutputType( options.itsOutputType ), - itsIndent( options.itsIndent ) + itsIndent( options.itsIndent ), + itsSizeAttributes(options.itsSizeAttributes) { // rapidxml will delete all allocations when xml_document is cleared auto node = itsXML.allocate_node( rapidxml::node_declaration ); @@ -289,6 +299,8 @@ namespace cereal itsNodes.top().node->append_attribute( itsXML.allocate_attribute( namePtr, valuePtr ) ); } + bool hasSizeAttributes() const { return itsSizeAttributes; } + protected: //! A struct that contains metadata about a node struct NodeInfo @@ -330,6 +342,7 @@ namespace cereal std::ostringstream itsOS; //!< Used to format strings internally bool itsOutputType; //!< Controls whether type information is printed bool itsIndent; //!< Controls whether indenting is used + bool itsSizeAttributes; //!< Controls whether lists have a size attribute }; // XMLOutputArchive // ###################################################################### @@ -764,7 +777,10 @@ namespace cereal template inline void prologue( XMLOutputArchive & ar, SizeTag const & ) { - ar.appendAttribute( "size", "dynamic" ); + if (ar.hasSizeAttributes()) + { + ar.appendAttribute("size", "dynamic"); + } } template inline From 35a36afb97a0dfb04464c8ccdfe864247a4b5002 Mon Sep 17 00:00:00 2001 From: Shane Grant Date: Fri, 5 May 2017 10:54:25 -0700 Subject: [PATCH 3/3] Standardize interface for options (xml) see #401 --- include/cereal/archives/xml.hpp | 38 +++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/include/cereal/archives/xml.hpp b/include/cereal/archives/xml.hpp index a6c3a0ffb..58f51c9c9 100644 --- a/include/cereal/archives/xml.hpp +++ b/include/cereal/archives/xml.hpp @@ -101,33 +101,49 @@ namespace cereal //! @{ //! A class containing various advanced options for the XML archive + /*! Options can either be directly passed to the constructor, or chained using the + modifier functions for an interface analogous to named parameters */ class Options { public: //! Default options static Options Default(){ return Options(); } - //! Default options with no indentation - static Options NoIndent(){ return Options( std::numeric_limits::max_digits10, false ); } - //! Specify specific options for the XMLOutputArchive /*! @param precision The precision used for floating point numbers @param indent Whether to indent each line of XML - @param outputType Whether to output the type of each serialized object as an attribute */ + @param outputType Whether to output the type of each serialized object as an attribute + @param sizeAttributes Whether dynamically sized containers output the size=dynamic attribute */ explicit Options( int precision = std::numeric_limits::max_digits10, bool indent = true, - bool outputType = false ) : + bool outputType = false, + bool sizeAttributes = true ) : itsPrecision( precision ), itsIndent( indent ), itsOutputType( outputType ), - itsSizeAttributes(true) + itsSizeAttributes( sizeAttributes ) { } - Options& NoSizeAttributes() - { - itsSizeAttributes = false; - return *this; - } + /*! @name Option Modifiers + An interface for setting option settings analogous to named parameters. + + @code{cpp} + cereal::XMLOutputArchive ar( myStream, + cereal::XMLOutputArchive::Options() + .indent(true) + .sizeAttributes(false) ); + @endcode + */ + //! @{ + + //! Whether to indent each line of XML + Options & indent( bool enable ){ itsIndent = enable; return *this; } + //! Whether to output the type of each serialized object as an attribute + Options & outputType( bool enable ){ itsOutputType = enable; return *this; } + //! Whether dynamically sized containers (e.g. vector) output the size=dynamic attribute + Options & sizeAttributes( bool enable ){ itsSizeAttributes = enable; return *this; } + + //! @} private: friend class XMLOutputArchive;