KiCad PCB EDA Suite
Loading...
Searching...
No Matches
xnode.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26#include <xnode.h>
27#include <string_utils.h>
28
29typedef wxXmlAttribute XATTR;
30
31
32void XNODE::Format( OUTPUTFORMATTER* out, int nestLevel )
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}
49
50
51void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel )
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}
90
91// EOF
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:526
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:458
Hold an XML or S-expression element.
Definition: xnode.h:44
XNODE * GetChildren() const
Definition: xnode.h:62
XNODE * GetNext() const
Definition: xnode.h:67
virtual void FormatContents(OUTPUTFORMATTER *out, int nestLevel)
Write the contents of object as UTF8 out to an OUTPUTFORMATTER as an S-expression.
Definition: xnode.cpp:51
virtual void Format(OUTPUTFORMATTER *out, int nestLevel)
Write this object as UTF8 out to an OUTPUTFORMATTER as an S-expression.
Definition: xnode.cpp:32
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:391
wxXmlAttribute XATTR
Definition: xnode.cpp:29