KiCad PCB EDA Suite
XNODE Class Reference

XNODE holds an XML or S-expression element. More...

#include <xnode.h>

Inheritance diagram for XNODE:

Public Member Functions

 XNODE ()
 
 XNODE (wxXmlNodeType aType, const wxString &aName, const wxString &aContent=wxEmptyString)
 
 XNODE (XNODE *aParent, wxXmlNodeType aType, const wxString &aName, const wxString &aContent=wxEmptyString, wxXmlAttribute *aProperties=NULL)
 
XNODEGetChildren () const
 
XNODEGetNext () const
 
XNODEGetParent () const
 
virtual void Format (OUTPUTFORMATTER *out, int nestLevel)
 Function Format writes this object as UTF8 out to an OUTPUTFORMATTER as an S-expression. More...
 
virtual void FormatContents (OUTPUTFORMATTER *out, int nestLevel)
 Function FormatContents writes the contents of object as UTF8 out to an OUTPUTFORMATTER as an S-expression. More...
 

Detailed Description

XNODE holds an XML or S-expression element.

It is used for eXporting a document tree in EITHER XML or S-expression.

Definition at line 43 of file xnode.h.

Constructor & Destructor Documentation

◆ XNODE() [1/3]

XNODE::XNODE ( )
inline

Definition at line 47 of file xnode.h.

47  :
48  wxXmlNode()
49  {
50  }

◆ XNODE() [2/3]

XNODE::XNODE ( wxXmlNodeType  aType,
const wxString &  aName,
const wxString &  aContent = wxEmptyString 
)
inline

Definition at line 52 of file xnode.h.

52  :
53  wxXmlNode( NULL, aType, aName, aContent )
54  {
55  }
#define NULL

◆ XNODE() [3/3]

XNODE::XNODE ( XNODE aParent,
wxXmlNodeType  aType,
const wxString &  aName,
const wxString &  aContent = wxEmptyString,
wxXmlAttribute *  aProperties = NULL 
)
inline

Definition at line 57 of file xnode.h.

58  :
59  wxXmlNode( aParent, aType, aName, aContent, aProperties )
60  {
61  }

Member Function Documentation

◆ Format()

void XNODE::Format ( OUTPUTFORMATTER out,
int  nestLevel 
)
virtual

Function Format writes this object as UTF8 out to an OUTPUTFORMATTER as an S-expression.

Parameters
outThe formatter to write to.
nestLevelA multiple of the number of spaces to preceed the output with.
Exceptions
IO_ERRORif a system error writing the output, such as a full disk.

Definition at line 32 of file xnode.cpp.

33 {
34  switch( GetType() )
35  {
36  case wxXML_ELEMENT_NODE:
37  out->Print( nestLevel, "(%s", TO_UTF8( GetName() ) );
38  FormatContents( out, nestLevel );
39  if( GetNext() )
40  out->Print( 0, ")\n" );
41  else
42  out->Print( 0, ")" );
43  break;
44 
45  default:
46  FormatContents( out, nestLevel );
47  }
48 }
virtual void FormatContents(OUTPUTFORMATTER *out, int nestLevel)
Function FormatContents writes the contents of object as UTF8 out to an OUTPUTFORMATTER as an S-expre...
Definition: xnode.cpp:51
XNODE * GetNext() const
Definition: xnode.h:68
#define TO_UTF8(wxstring)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References FormatContents(), GetNext(), OUTPUTFORMATTER::Print(), and TO_UTF8.

◆ FormatContents()

void XNODE::FormatContents ( OUTPUTFORMATTER out,
int  nestLevel 
)
virtual

Function FormatContents writes the contents of object as UTF8 out to an OUTPUTFORMATTER as an S-expression.

This is the same as Format() except that the outer wrapper is not included.

Parameters
outThe formatter to write to.
nestLevelA multiple of the number of spaces to preceed the output with.
Exceptions
IO_ERRORif a system error writing the output, such as a full disk.

Definition at line 51 of file xnode.cpp.

52 {
53  // output attributes first if they exist
54  for( XATTR* attr = (XATTR*) GetAttributes(); attr; attr = (XATTR*) attr->GetNext() )
55  {
56  out->Print( 0, " (%s %s)",
57  TO_UTF8( attr->GetName() ),
58  out->Quotew( attr->GetValue() ).c_str() );
59  }
60 
61  // we only expect to have used one of two types here:
62  switch( GetType() )
63  {
64  case wxXML_ELEMENT_NODE:
65 
66  // output children if they exist.
67  for( XNODE* kid = (XNODE*) GetChildren(); kid; kid = (XNODE*) kid->GetNext() )
68  {
69  if( kid->GetType() != wxXML_TEXT_NODE )
70  {
71  if( kid == GetChildren() )
72  out->Print( 0, "\n" );
73  kid->Format( out, nestLevel+1 );
74  }
75  else
76  {
77  kid->Format( out, 0 );
78  }
79  }
80  break;
81 
82  case wxXML_TEXT_NODE:
83  out->Print( 0, " %s", out->Quotew( GetContent() ).c_str() );
84  break;
85 
86  default:
87  ; // not supported
88  }
89 }
XNODE * GetChildren() const
Definition: xnode.h:63
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
#define TO_UTF8(wxstring)
wxXmlAttribute XATTR
Definition: xnode.cpp:29
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References GetChildren(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and TO_UTF8.

Referenced by Format().

◆ GetChildren()

XNODE* XNODE::GetChildren ( ) const
inline

◆ GetNext()

◆ GetParent()

XNODE* XNODE::GetParent ( void  ) const
inline

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