Skip to content

Commit

Permalink
Add option to turn off the size=dynamic attributes of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Hoens committed Apr 12, 2017
1 parent 51cbda5 commit 52b03d5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions include/cereal/archives/xml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -137,7 +146,8 @@ namespace cereal
OutputArchive<XMLOutputArchive>(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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

// ######################################################################
Expand Down Expand Up @@ -764,7 +777,10 @@ namespace cereal
template <class T> inline
void prologue( XMLOutputArchive & ar, SizeTag<T> const & )
{
ar.appendAttribute( "size", "dynamic" );
if (ar.hasSizeAttributes())
{
ar.appendAttribute("size", "dynamic");
}
}

template <class T> inline
Expand Down

0 comments on commit 52b03d5

Please sign in to comment.