Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to turn off the size=dynamic attributes of lists #401

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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