KiCad PCB EDA Suite
Loading...
Searching...
No Matches
xnode.h
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#ifndef XNODE_H_
26#define XNODE_H_
27
28#include <variant>
29
30// quiet the deprecated warnings with 3 lines:
31#include <wx/defs.h>
32#undef wxDEPRECATED
33#define wxDEPRECATED(x) x
34
35#include <wx/xml/xml.h>
36#include <kicommon.h>
37
38class OUTPUTFORMATTER;
39class KIID;
40
41
49class KICOMMON_API XATTR : public wxXmlAttribute
50{
51public:
52 typedef std::variant<wxString, int, double> VALUE_TYPE;
53
55 {}
56
57 XATTR( const wxString& aName, const VALUE_TYPE& aValue );
58
59 void SetValue( const VALUE_TYPE& aValue ) { m_originalValue = aValue; }
60
62
63private:
65};
66
70class KICOMMON_API XNODE : public wxXmlNode
71{
72public:
74 wxXmlNode()
75 {
76 }
77
78 XNODE( wxXmlNodeType aType, const wxString& aName, const wxString& aContent = wxEmptyString ) :
79 wxXmlNode( nullptr, aType, aName, aContent )
80 {
81 }
82
83 XNODE( XNODE* aParent, wxXmlNodeType aType, const wxString& aName,
84 const wxString& aContent = wxEmptyString, XATTR* aProperties = nullptr ) :
85 wxXmlNode( aParent, aType, aName, aContent, aProperties )
86 {
87 }
88
89 void AddAttribute( const wxString& aName, const wxString& aValue ) override;
90
91 void AddAttribute( const wxString& aName, int aValue );
92
93 void AddAttribute( const wxString& aName, double aValue );
94
95 void AddAttribute( wxXmlAttribute* aAttr ) override
96 {
97 wxASSERT_MSG( dynamic_cast<XATTR*>( aAttr ), "use XATTR instead of wxXmlAttribute!" );
98 return wxXmlNode::AddAttribute( aAttr );
99 }
100
102 {
103 return static_cast<XNODE*>( wxXmlNode::GetChildren() );
104 }
105
106 XNODE* GetNext() const
107 {
108 return static_cast<XNODE*>( wxXmlNode::GetNext() );
109 }
110
112 {
113 return static_cast<XNODE*>( wxXmlNode::GetParent() );
114 }
115
116 void AddBool( const wxString& aKey, bool aValue );
117
124 void Format( OUTPUTFORMATTER* out ) const;
125
134 void FormatContents( OUTPUTFORMATTER* out ) const;
135
140 wxString Format() const;
141
142};
143
144#endif // XNODE_H_
Definition kiid.h:49
An interface used to output 8 bit text in a convenient way.
Definition richio.h:323
An extension of wxXmlAttribute that stores a variant type rather than just a string.
Definition xnode.h:50
std::variant< wxString, int, double > VALUE_TYPE
Definition xnode.h:52
VALUE_TYPE m_originalValue
Definition xnode.h:64
void SetValue(const VALUE_TYPE &aValue)
Definition xnode.h:59
VALUE_TYPE GetValue() const
Definition xnode.h:61
XATTR()
Definition xnode.h:54
XNODE * GetParent() const
Definition xnode.h:111
void AddAttribute(wxXmlAttribute *aAttr) override
Definition xnode.h:95
XNODE(wxXmlNodeType aType, const wxString &aName, const wxString &aContent=wxEmptyString)
Definition xnode.h:78
XNODE * GetChildren() const
Definition xnode.h:101
XNODE * GetNext() const
Definition xnode.h:106
XNODE()
Definition xnode.h:73
XNODE(XNODE *aParent, wxXmlNodeType aType, const wxString &aName, const wxString &aContent=wxEmptyString, XATTR *aProperties=nullptr)
Definition xnode.h:83
#define KICOMMON_API
Definition kicommon.h:28
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition ptree.cpp:198