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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef XNODE_H_
22#define XNODE_H_
23
24#include <variant>
25
26// quiet the deprecated warnings with 3 lines:
27#include <wx/defs.h>
28#undef wxDEPRECATED
29#define wxDEPRECATED(x) x
30
31#include <wx/xml/xml.h>
32#include <kicommon.h>
33
34class OUTPUTFORMATTER;
35class KIID;
36
37
45class KICOMMON_API XATTR : public wxXmlAttribute
46{
47public:
48 typedef std::variant<wxString, int, double> VALUE_TYPE;
49
51 {}
52
53 XATTR( const wxString& aName, const VALUE_TYPE& aValue );
54
55 void SetValue( const VALUE_TYPE& aValue ) { m_originalValue = aValue; }
56
58
59private:
61};
62
66class KICOMMON_API XNODE : public wxXmlNode
67{
68public:
70 wxXmlNode()
71 {
72 }
73
74 XNODE( wxXmlNodeType aType, const wxString& aName, const wxString& aContent = wxEmptyString ) :
75 wxXmlNode( nullptr, aType, aName, aContent )
76 {
77 }
78
79 XNODE( XNODE* aParent, wxXmlNodeType aType, const wxString& aName,
80 const wxString& aContent = wxEmptyString, XATTR* aProperties = nullptr ) :
81 wxXmlNode( aParent, aType, aName, aContent, aProperties )
82 {
83 }
84
85 void AddAttribute( const wxString& aName, const wxString& aValue ) override;
86
87 void AddAttribute( const wxString& aName, int aValue );
88
89 void AddAttribute( const wxString& aName, double aValue );
90
91 void AddAttribute( wxXmlAttribute* aAttr ) override
92 {
93 wxASSERT_MSG( dynamic_cast<XATTR*>( aAttr ), "use XATTR instead of wxXmlAttribute!" );
94 return wxXmlNode::AddAttribute( aAttr );
95 }
96
98 {
99 return static_cast<XNODE*>( wxXmlNode::GetChildren() );
100 }
101
102 XNODE* GetNext() const
103 {
104 return static_cast<XNODE*>( wxXmlNode::GetNext() );
105 }
106
108 {
109 return static_cast<XNODE*>( wxXmlNode::GetParent() );
110 }
111
112 void AddBool( const wxString& aKey, bool aValue );
113
120 void Format( OUTPUTFORMATTER* out ) const;
121
130 void FormatContents( OUTPUTFORMATTER* out ) const;
131
136 wxString Format() const;
137
138};
139
140#endif // XNODE_H_
Definition kiid.h:44
An interface used to output 8 bit text in a convenient way.
Definition richio.h:291
An extension of wxXmlAttribute that stores a variant type rather than just a string.
Definition xnode.h:46
std::variant< wxString, int, double > VALUE_TYPE
Definition xnode.h:48
VALUE_TYPE m_originalValue
Definition xnode.h:60
void SetValue(const VALUE_TYPE &aValue)
Definition xnode.h:55
VALUE_TYPE GetValue() const
Definition xnode.h:57
XATTR()
Definition xnode.h:50
XNODE * GetParent() const
Definition xnode.h:107
void AddAttribute(wxXmlAttribute *aAttr) override
Definition xnode.h:91
XNODE(wxXmlNodeType aType, const wxString &aName, const wxString &aContent=wxEmptyString)
Definition xnode.h:74
XNODE * GetChildren() const
Definition xnode.h:97
XNODE * GetNext() const
Definition xnode.h:102
XNODE()
Definition xnode.h:69
XNODE(XNODE *aParent, wxXmlNodeType aType, const wxString &aName, const wxString &aContent=wxEmptyString, XATTR *aProperties=nullptr)
Definition xnode.h:79
#define KICOMMON_API
Definition kicommon.h:27
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:194