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 The KiCad Developers, see AUTHORS.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
28#include <richio.h>
29#include <string_utils.h>
30
31
32typedef wxXmlAttribute XATTR;
33
34
35void XNODE::Format( OUTPUTFORMATTER* out, int nestLevel )
36{
37 switch( GetType() )
38 {
39 case wxXML_ELEMENT_NODE:
40 out->Print( nestLevel, "(%s", TO_UTF8( GetName() ) );
41 FormatContents( out, nestLevel );
42
43 if( GetNext() )
44 out->Print( 0, ")\n" );
45 else
46 out->Print( 0, ")" );
47
48 break;
49
50 default:
51 FormatContents( out, nestLevel );
52 }
53}
54
55
56void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel )
57{
58 // output attributes first if they exist
59 for( XATTR* attr = (XATTR*) GetAttributes(); attr; attr = (XATTR*) attr->GetNext() )
60 {
61 out->Print( 0, " (%s %s)",
62 TO_UTF8( attr->GetName() ),
63 out->Quotew( attr->GetValue() ).c_str() );
64 }
65
66 // we only expect to have used one of two types here:
67 switch( GetType() )
68 {
69 case wxXML_ELEMENT_NODE:
70
71 // output children if they exist.
72 for( XNODE* kid = (XNODE*) GetChildren(); kid; kid = (XNODE*) kid->GetNext() )
73 {
74 if( kid->GetType() != wxXML_TEXT_NODE )
75 {
76 if( kid == GetChildren() )
77 out->Print( 0, "\n" );
78
79 kid->Format( out, nestLevel+1 );
80 }
81 else
82 {
83 kid->Format( out, 0 );
84 }
85 }
86
87 break;
88
89 case wxXML_TEXT_NODE:
90 out->Print( 0, " %s", out->Quotew( GetContent() ).c_str() );
91 break;
92
93 default:
94 ; // not supported
95 }
96}
97
98// 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:545
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:460
Hold an XML or S-expression element.
Definition: xnode.h:43
XNODE * GetChildren() const
Definition: xnode.h:61
XNODE * GetNext() const
Definition: xnode.h:66
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:56
virtual void Format(OUTPUTFORMATTER *out, int nestLevel)
Write this object as UTF8 out to an OUTPUTFORMATTER as an S-expression.
Definition: xnode.cpp:35
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:398
wxXmlAttribute XATTR
Definition: xnode.cpp:32