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

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.

References buffer, depth, simpleTextPrint, and TiXmlPrinter().

Referenced by TiXmlPrinter().

2073  : depth(0)
2074  , simpleTextPrint(false)
2075  , buffer()
2076  , indent(" ")
2077  , lineBreak("\n") {}
TIXML_STRING lineBreak
Definition: tinyxml.h:2137
TIXML_STRING buffer
Definition: tinyxml.h:2135
TIXML_STRING indent
Definition: tinyxml.h:2136
bool simpleTextPrint
Definition: tinyxml.h:2134
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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(); }
TIXML_STRING buffer
Definition: tinyxml.h:2135

◆ DoIndent()

void TiXmlPrinter::DoIndent ( )
inlineprivate

Definition at line 2127 of file tinyxml.h.

References buffer, depth, and indent.

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

2127  {
2128  for (int i = 0; i < depth; ++i)
2129  buffer += indent;
2130  }
TIXML_STRING buffer
Definition: tinyxml.h:2135
TIXML_STRING indent
Definition: tinyxml.h:2136
+ Here is the caller graph for this function:

◆ DoLineBreak()

void TiXmlPrinter::DoLineBreak ( )
inlineprivate

Definition at line 2131 of file tinyxml.h.

References buffer, and lineBreak.

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

2131 { buffer += lineBreak; }
TIXML_STRING lineBreak
Definition: tinyxml.h:2137
TIXML_STRING buffer
Definition: tinyxml.h:2135
+ 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(); }
TIXML_STRING indent
Definition: tinyxml.h:2136

◆ 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(); }
TIXML_STRING lineBreak
Definition: tinyxml.h:2137

◆ 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 : ""; }
TIXML_STRING indent
Definition: tinyxml.h:2136

◆ 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  }
TIXML_STRING lineBreak
Definition: tinyxml.h:2137

◆ 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.

Referenced by operator<<().

2112  {
2113  indent = "";
2114  lineBreak = "";
2115  }
TIXML_STRING lineBreak
Definition: tinyxml.h:2137
TIXML_STRING indent
Definition: tinyxml.h:2136
+ 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(); }
TIXML_STRING buffer
Definition: tinyxml.h:2135

◆ Str()

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

Return the result.

Definition at line 2123 of file tinyxml.h.

References buffer.

2123 { return buffer; }
TIXML_STRING buffer
Definition: tinyxml.h:2135

◆ Visit() [1/5]

bool TiXmlPrinter::Visit ( const TiXmlDeclaration )
virtual

Visit a declaration.

Reimplemented from TiXmlVisitor.

Definition at line 1715 of file tinyxml.cpp.

References DoIndent(), and DoLineBreak().

1715  {
1716  DoIndent();
1717  declaration.Print(0, 0, &buffer);
1718  DoLineBreak();
1719  return true;
1720 }
void DoLineBreak()
Definition: tinyxml.h:2131
void DoIndent()
Definition: tinyxml.h:2127
TIXML_STRING buffer
Definition: tinyxml.h:2135
+ Here is the call graph for this function:

◆ Visit() [2/5]

bool TiXmlPrinter::Visit ( const TiXmlText )
virtual

Visit a text node.

Reimplemented from TiXmlVisitor.

Definition at line 1693 of file tinyxml.cpp.

References TiXmlText::CDATA(), DoIndent(), DoLineBreak(), and simpleTextPrint.

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 }
void DoLineBreak()
Definition: tinyxml.h:2131
void DoIndent()
Definition: tinyxml.h:2127
TIXML_STRING buffer
Definition: tinyxml.h:2135
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
bool simpleTextPrint
Definition: tinyxml.h:2134
+ Here is the call graph for this function:

◆ Visit() [3/5]

bool TiXmlPrinter::Visit ( const TiXmlComment )
virtual

Visit a comment node.

Reimplemented from TiXmlVisitor.

Definition at line 1722 of file tinyxml.cpp.

References DoIndent(), and DoLineBreak().

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
TIXML_STRING buffer
Definition: tinyxml.h:2135
+ Here is the call graph for this function:

◆ Visit() [4/5]

bool TiXmlPrinter::Visit ( const TiXmlUnknown )
virtual

Visit an unknow node.

Reimplemented from TiXmlVisitor.

Definition at line 1731 of file tinyxml.cpp.

References DoIndent(), and DoLineBreak().

1731  {
1732  DoIndent();
1733  buffer += "<";
1734  buffer += unknown.Value();
1735  buffer += ">";
1736  DoLineBreak();
1737  return true;
1738 }
void DoLineBreak()
Definition: tinyxml.h:2131
void DoIndent()
Definition: tinyxml.h:2127
TIXML_STRING buffer
Definition: tinyxml.h:2135
+ Here is the call graph for this function:

◆ Visit() [5/5]

bool TiXmlPrinter::Visit ( const TiXmlStylesheetReference )
virtual

Visit a stylesheet reference.

Reimplemented from TiXmlVisitor.

Definition at line 1740 of file tinyxml.cpp.

References DoIndent(), and DoLineBreak().

1740  {
1741  DoIndent();
1742  stylesheet.Print(0, 0, &buffer);
1743  DoLineBreak();
1744  return true;
1745 }
void DoLineBreak()
Definition: tinyxml.h:2131
void DoIndent()
Definition: tinyxml.h:2127
TIXML_STRING buffer
Definition: tinyxml.h:2135
+ 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.

References depth, DoIndent(), DoLineBreak(), TiXmlAttribute::Next(), and simpleTextPrint.

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 }
void DoLineBreak()
Definition: tinyxml.h:2131
An attribute is a name-value pair.
Definition: tinyxml.h:915
void DoIndent()
Definition: tinyxml.h:2127
TIXML_STRING buffer
Definition: tinyxml.h:2135
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition: tinyxml.cpp:1043
bool simpleTextPrint
Definition: tinyxml.h:2134
+ 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.

References depth, DoIndent(), DoLineBreak(), and simpleTextPrint.

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 }
void DoLineBreak()
Definition: tinyxml.h:2131
void DoIndent()
Definition: tinyxml.h:2127
TIXML_STRING buffer
Definition: tinyxml.h:2135
bool simpleTextPrint
Definition: tinyxml.h:2134
+ Here is the call graph for this function:

Member Data Documentation

◆ buffer

TIXML_STRING TiXmlPrinter::buffer
private

Definition at line 2135 of file tinyxml.h.

Referenced by DoIndent(), DoLineBreak(), Str(), and TiXmlPrinter().

◆ depth

int TiXmlPrinter::depth
private

Definition at line 2133 of file tinyxml.h.

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

◆ indent

TIXML_STRING TiXmlPrinter::indent
private

Definition at line 2136 of file tinyxml.h.

Referenced by DoIndent().

◆ lineBreak

TIXML_STRING TiXmlPrinter::lineBreak
private

Definition at line 2137 of file tinyxml.h.

Referenced by DoLineBreak().

◆ 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: