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
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 if( GetNext() )
43 out->Print( 0, ")\n" );
44 else
45 out->Print( 0, ")" );
46 break;
47
48 default:
49 FormatContents( out, nestLevel );
50 }
51}
52
53
54void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel )
55{
56 // output attributes first if they exist
57 for( XATTR* attr = (XATTR*) GetAttributes(); attr; attr = (XATTR*) attr->GetNext() )
58 {
59 out->Print( 0, " (%s %s)",
60 TO_UTF8( attr->GetName() ),
61 out->Quotew( attr->GetValue() ).c_str() );
62 }
63
64 // we only expect to have used one of two types here:
65 switch( GetType() )
66 {
67 case wxXML_ELEMENT_NODE:
68
69 // output children if they exist.
70 for( XNODE* kid = (XNODE*) GetChildren(); kid; kid = (XNODE*) kid->GetNext() )
71 {
72 if( kid->GetType() != wxXML_TEXT_NODE )
73 {
74 if( kid == GetChildren() )
75 out->Print( 0, "\n" );
76 kid->Format( out, nestLevel+1 );
77 }
78 else
79 {
80 kid->Format( out, 0 );
81 }
82 }
83 break;
84
85 case wxXML_TEXT_NODE:
86 out->Print( 0, " %s", out->Quotew( GetContent() ).c_str() );
87 break;
88
89 default:
90 ; // not supported
91 }
92}
93
94// 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: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:54
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