aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
TiXmlPrinter Class Reference

Print to memory functionality. More...

#include <tinyxml.h>

Inheritance diagram for TiXmlPrinter:
Collaboration diagram for TiXmlPrinter:

Public Member Functions

 TiXmlPrinter ()
virtual bool VisitEnter (const TiXmlDocument &doc)
 Visit a document.
virtual bool VisitExit (const TiXmlDocument &doc)
 Visit a document.
virtual bool VisitEnter (const TiXmlElement &element, const TiXmlAttribute *firstAttribute)
 Visit an element.
virtual bool VisitExit (const TiXmlElement &element)
 Visit an element.
virtual bool Visit (const TiXmlDeclaration &declaration)
 Visit a declaration.
virtual bool Visit (const TiXmlText &text)
 Visit a text node.
virtual bool Visit (const TiXmlComment &comment)
 Visit a comment node.
virtual bool Visit (const TiXmlUnknown &unknown)
 Visit an unknow node.
virtual bool Visit (const TiXmlStylesheetReference &stylesheet)
 Visit a stylesheet reference.
void SetIndent (const char *_indent)
 Set the indent characters for printing.
const char * Indent ()
 Query the indention string.
void SetLineBreak (const char *_lineBreak)
 Set the line breaking string.
const char * LineBreak ()
 Query the current line breaking string.
void SetStreamPrinting ()
 Switch over to "stream printing" which is the most dense formatting without linebreaks.
const char * CStr ()
 Return the result.
size_t Size ()
 Return the length of the result string.
const std::string & Str ()
 Return the result.

Private Member Functions

void DoIndent ()
void DoLineBreak ()

Private Attributes

int depth
bool simpleTextPrint
TIXML_STRING buffer
TIXML_STRING indent
TIXML_STRING lineBreak

Detailed Description

Print to memory functionality.

The TiXmlPrinter is useful when you need to:

  1. Print to memory (especially in non-STL mode)
  2. Control formatting (line endings, etc.)

When constructed, the TiXmlPrinter is in its default "pretty printing" mode. Before calling Accept() you can call methods to control the printing of the XML document. After TiXmlNode::Accept() is called, the printed document can be accessed via the CStr(), Str(), and Size() methods.

TiXmlPrinter uses the Visitor API.

TiXmlPrinter printer;
printer.SetIndent( "\t" );

doc.Accept( &printer );
fprintf( stdout, "%s", printer.CStr() );

Definition at line 2070 of file tinyxml.h.

Constructor & Destructor Documentation

◆ TiXmlPrinter()

TiXmlPrinter::TiXmlPrinter ( )
inline

Definition at line 2072 of file tinyxml.h.

2073 : depth(0)
2074 , simpleTextPrint(false)
2075 , buffer()
2076 , indent(" ")
2077 , lineBreak("\n") {}
TIXML_STRING lineBreak
Definition tinyxml.h:2137
bool simpleTextPrint
Definition tinyxml.h:2134
TIXML_STRING indent
Definition tinyxml.h:2136
TIXML_STRING buffer
Definition tinyxml.h:2135

References buffer, depth, indent, lineBreak, and simpleTextPrint.

Member Function Documentation

◆ CStr()

const char * TiXmlPrinter::CStr ( )
inline

Return the result.

Definition at line 2117 of file tinyxml.h.

2117{ return buffer.c_str(); }

References buffer.

◆ DoIndent()

void TiXmlPrinter::DoIndent ( )
inlineprivate

Definition at line 2127 of file tinyxml.h.

2127 {
2128 for (int i = 0; i < depth; ++i)
2129 buffer += indent;
2130 }

References buffer, depth, and indent.

Referenced by Visit(), Visit(), Visit(), Visit(), Visit(), VisitEnter(), and VisitExit().

Here is the caller graph for this function:

◆ DoLineBreak()

void TiXmlPrinter::DoLineBreak ( )
inlineprivate

Definition at line 2131 of file tinyxml.h.

2131{ buffer += lineBreak; }

References buffer, and lineBreak.

Referenced by Visit(), Visit(), Visit(), Visit(), Visit(), VisitEnter(), and VisitExit().

Here is the caller graph for this function:

◆ Indent()

const char * TiXmlPrinter::Indent ( )
inline

Query the indention string.

Definition at line 2097 of file tinyxml.h.

2097{ return indent.c_str(); }

References indent.

◆ LineBreak()

const char * TiXmlPrinter::LineBreak ( )
inline

Query the current line breaking string.

Definition at line 2106 of file tinyxml.h.

2106{ return lineBreak.c_str(); }

References lineBreak.

◆ SetIndent()

void TiXmlPrinter::SetIndent ( const char * _indent)
inline

Set the indent characters for printing.

By default 4 spaces but tab is also useful, or null/empty string for no indentation.

Definition at line 2095 of file tinyxml.h.

2095{ indent = _indent ? _indent : ""; }

References indent.

◆ SetLineBreak()

void TiXmlPrinter::SetLineBreak ( const char * _lineBreak)
inline

Set the line breaking string.

By default set to newline (
). Some operating systems prefer other characters, or can be set to the null/empty string for no indenation.

Definition at line 2102 of file tinyxml.h.

2102 {
2103 lineBreak = _lineBreak ? _lineBreak : "";
2104 }

References lineBreak.

◆ SetStreamPrinting()

void TiXmlPrinter::SetStreamPrinting ( )
inline

Switch over to "stream printing" which is the most dense formatting without linebreaks.

Common when the XML is needed for network transmission.

Definition at line 2112 of file tinyxml.h.

2112 {
2113 indent = "";
2114 lineBreak = "";
2115 }

References indent, and lineBreak.

Referenced by TiXmlNode::operator<<, and TiXmlNode::operator<<.

Here is the caller graph for this function:

◆ Size()

size_t TiXmlPrinter::Size ( )
inline

Return the length of the result string.

Definition at line 2119 of file tinyxml.h.

2119{ return buffer.size(); }

References buffer.

◆ Str()

const std::string & TiXmlPrinter::Str ( )
inline

Return the result.

Definition at line 2123 of file tinyxml.h.

2123{ return buffer; }

References buffer.

Referenced by TiXmlNode::operator<<, and TiXmlNode::operator<<.

Here is the caller graph for this function:

◆ Visit() [1/5]

bool TiXmlPrinter::Visit ( const TiXmlComment & )
virtual

Visit a comment node.

Reimplemented from TiXmlVisitor.

Definition at line 1722 of file tinyxml.cpp.

1722 {
1723 DoIndent();
1724 buffer += "<!--";
1725 buffer += comment.Value();
1726 buffer += "-->";
1727 DoLineBreak();
1728 return true;
1729}
void DoLineBreak()
Definition tinyxml.h:2131
void DoIndent()
Definition tinyxml.h:2127

References buffer, DoIndent(), DoLineBreak(), and TiXmlNode::Value().

Here is the call graph for this function:

◆ Visit() [2/5]

bool TiXmlPrinter::Visit ( const TiXmlDeclaration & )
virtual

Visit a declaration.

Reimplemented from TiXmlVisitor.

Definition at line 1715 of file tinyxml.cpp.

1715 {
1716 DoIndent();
1717 declaration.Print(0, 0, &buffer);
1718 DoLineBreak();
1719 return true;
1720}

References buffer, DoIndent(), DoLineBreak(), and TiXmlDeclaration::Print().

Here is the call graph for this function:

◆ Visit() [3/5]

bool TiXmlPrinter::Visit ( const TiXmlStylesheetReference & )
virtual

Visit a stylesheet reference.

Reimplemented from TiXmlVisitor.

Definition at line 1740 of file tinyxml.cpp.

1740 {
1741 DoIndent();
1742 stylesheet.Print(0, 0, &buffer);
1743 DoLineBreak();
1744 return true;
1745}

References buffer, DoIndent(), DoLineBreak(), and TiXmlStylesheetReference::Print().

Here is the call graph for this function:

◆ Visit() [4/5]

bool TiXmlPrinter::Visit ( const TiXmlText & )
virtual

Visit a text node.

Reimplemented from TiXmlVisitor.

Definition at line 1693 of file tinyxml.cpp.

1693 {
1694 if (text.CDATA()) {
1695 DoIndent();
1696 buffer += "<![CDATA[";
1697 buffer += text.Value();
1698 buffer += "]]>";
1699 DoLineBreak();
1700 } else if (simpleTextPrint) {
1701 TIXML_STRING str;
1702 TiXmlBase::EncodeString(text.ValueTStr(), &str);
1703 buffer += str;
1704 } else {
1705 DoIndent();
1706 TIXML_STRING str;
1707 TiXmlBase::EncodeString(text.ValueTStr(), &str);
1708 buffer += str;
1709 DoLineBreak();
1710 }
1711
1712 return true;
1713}
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
Expands entities in a string.
Definition tinyxml.cpp:50
#define TIXML_STRING
Definition tinyxml.h:60

References buffer, TiXmlText::CDATA(), DoIndent(), DoLineBreak(), TiXmlBase::EncodeString(), simpleTextPrint, TIXML_STRING, TiXmlNode::Value(), and TiXmlNode::ValueTStr().

Here is the call graph for this function:

◆ Visit() [5/5]

bool TiXmlPrinter::Visit ( const TiXmlUnknown & )
virtual

Visit an unknow node.

Reimplemented from TiXmlVisitor.

Definition at line 1731 of file tinyxml.cpp.

1731 {
1732 DoIndent();
1733 buffer += "<";
1734 buffer += unknown.Value();
1735 buffer += ">";
1736 DoLineBreak();
1737 return true;
1738}

References buffer, DoIndent(), DoLineBreak(), and TiXmlNode::Value().

Here is the call graph for this function:

◆ VisitEnter() [1/2]

bool TiXmlPrinter::VisitEnter ( const TiXmlDocument & )
virtual

Visit a document.

Reimplemented from TiXmlVisitor.

Definition at line 1636 of file tinyxml.cpp.

1636{ return true; }

◆ VisitEnter() [2/2]

bool TiXmlPrinter::VisitEnter ( const TiXmlElement & ,
const TiXmlAttribute *  )
virtual

Visit an element.

Reimplemented from TiXmlVisitor.

Definition at line 1640 of file tinyxml.cpp.

1641 {
1642 DoIndent();
1643 buffer += "<";
1644 buffer += element.Value();
1645
1646 for (const TiXmlAttribute* attrib = firstAttribute; attrib;
1647 attrib = attrib->Next()) {
1648 buffer += " ";
1649 attrib->Print(0, 0, &buffer);
1650 }
1651
1652 if (!element.FirstChild()) {
1653 buffer += " />";
1654 DoLineBreak();
1655 } else {
1656 buffer += ">";
1657
1658 if (element.FirstChild()->ToText() &&
1659 element.LastChild() == element.FirstChild() &&
1660 element.FirstChild()->ToText()->CDATA() == false) {
1661 simpleTextPrint = true;
1662 // no DoLineBreak()!
1663 } else {
1664 DoLineBreak();
1665 }
1666 }
1667
1668 ++depth;
1669 return true;
1670}

References buffer, TiXmlText::CDATA(), depth, DoIndent(), DoLineBreak(), TiXmlNode::FirstChild(), TiXmlNode::LastChild(), TiXmlAttribute::Next(), simpleTextPrint, TiXmlNode::ToText(), and TiXmlNode::Value().

Here is the call graph for this function:

◆ VisitExit() [1/2]

bool TiXmlPrinter::VisitExit ( const TiXmlDocument & )
virtual

Visit a document.

Reimplemented from TiXmlVisitor.

Definition at line 1638 of file tinyxml.cpp.

1638{ return true; }

◆ VisitExit() [2/2]

bool TiXmlPrinter::VisitExit ( const TiXmlElement & )
virtual

Visit an element.

Reimplemented from TiXmlVisitor.

Definition at line 1672 of file tinyxml.cpp.

1672 {
1673 --depth;
1674
1675 if (!element.FirstChild()) {
1676 // nothing.
1677 } else {
1678 if (simpleTextPrint) {
1679 simpleTextPrint = false;
1680 } else {
1681 DoIndent();
1682 }
1683
1684 buffer += "</";
1685 buffer += element.Value();
1686 buffer += ">";
1687 DoLineBreak();
1688 }
1689
1690 return true;
1691}

References buffer, depth, DoIndent(), DoLineBreak(), TiXmlNode::FirstChild(), simpleTextPrint, and TiXmlNode::Value().

Here is the call graph for this function:

Member Data Documentation

◆ buffer

TIXML_STRING TiXmlPrinter::buffer
private

◆ depth

int TiXmlPrinter::depth
private

Definition at line 2133 of file tinyxml.h.

Referenced by TiXmlPrinter(), DoIndent(), VisitEnter(), and VisitExit().

◆ indent

TIXML_STRING TiXmlPrinter::indent
private

Definition at line 2136 of file tinyxml.h.

Referenced by TiXmlPrinter(), DoIndent(), Indent(), SetIndent(), and SetStreamPrinting().

◆ lineBreak

TIXML_STRING TiXmlPrinter::lineBreak
private

Definition at line 2137 of file tinyxml.h.

Referenced by TiXmlPrinter(), DoLineBreak(), LineBreak(), SetLineBreak(), and SetStreamPrinting().

◆ simpleTextPrint

bool TiXmlPrinter::simpleTextPrint
private

Definition at line 2134 of file tinyxml.h.

Referenced by TiXmlPrinter(), Visit(), VisitEnter(), and VisitExit().


The documentation for this class was generated from the following files: