CppUnit - The Unit Testing Library

CppUnit project page | FAQ

XmlElement.h
Go to the documentation of this file.
1#ifndef CPPUNIT_TOOLS_XMLELEMENT_H
2#define CPPUNIT_TOOLS_XMLELEMENT_H
3
4#include <cppunit/Portability.h>
5
6#if CPPUNIT_NEED_DLL_DECL
7#pragma warning( push )
8#pragma warning( disable: 4251 ) // X needs to have dll-interface to be used by clients of class Z
9#endif
10
11#include <deque>
12#include <string>
13
14
15 CPPUNIT_NS_BEGIN
16
17
18class XmlElement;
19
20#if CPPUNIT_NEED_DLL_DECL
21// template class CPPUNIT_API std::deque<XmlElement *>;
22#endif
23
24
33 class CPPUNIT_API XmlElement
34{
35public:
40 XmlElement( std::string elementName,
41 std::string content ="" );
42
47 XmlElement( std::string elementName,
48 int numericContent );
49
52 virtual ~XmlElement();
53
57 std::string name() const;
58
62 std::string content() const;
63
67 void setName( const std::string &name );
68
72 void setContent( const std::string &content );
73
76 void setContent( int numericContent );
77
82 void addAttribute( std::string attributeName,
83 std::string value );
84
89 void addAttribute( std::string attributeName,
90 int numericValue );
91
95 void addElement( XmlElement *element );
96
100 int elementCount() const;
101
107 XmlElement *elementAt( int index ) const;
108
115 XmlElement *elementFor( const std::string &name ) const;
116
122 std::string toString( const std::string &indent = "" ) const;
123
124private:
125 typedef std::pair<std::string,std::string> Attribute;
126
127 std::string attributesAsString() const;
128 std::string escape( std::string value ) const;
129
130private:
131 std::string m_name;
132 std::string m_content;
133
134 typedef std::deque<Attribute> Attributes;
135 Attributes m_attributes;
136
137 typedef std::deque<XmlElement *> Elements;
138 Elements m_elements;
139};
140
141
142 CPPUNIT_NS_END
143
144#if CPPUNIT_NEED_DLL_DECL
145#pragma warning( pop )
146#endif
147
148
149#endif // CPPUNIT_TOOLS_XMLELEMENT_H
CPPUNIT_API
#define CPPUNIT_API
Definition CppUnitApi.h:27
Portability.h
CPPUNIT_NS_END
#define CPPUNIT_NS_END
Definition Portability.h:106
CPPUNIT_NS_BEGIN
#define CPPUNIT_NS_BEGIN
Definition Portability.h:105
XmlElement
A XML Element.
Definition XmlElement.h:34
XmlElement::setName
void setName(const std::string &name)
Sets the name of the element.
Definition XmlElement.cpp:56
XmlElement::addAttribute
void addAttribute(std::string attributeName, std::string value)
Adds an attribute with the specified string value.
Definition XmlElement.cpp:77
XmlElement::Attributes
std::deque< Attribute > Attributes
Definition XmlElement.h:134
XmlElement::escape
std::string escape(std::string value) const
Definition XmlElement.cpp:198
XmlElement::attributesAsString
std::string attributesAsString() const
Definition XmlElement.cpp:178
XmlElement::m_attributes
Attributes m_attributes
Definition XmlElement.h:135
XmlElement::addElement
void addElement(XmlElement *element)
Adds a child element to the element.
Definition XmlElement.cpp:93
XmlElement::content
std::string content() const
Returns the content of the element.
Definition XmlElement.cpp:49
XmlElement::m_name
std::string m_name
Definition XmlElement.h:131
XmlElement::elementFor
XmlElement * elementFor(const std::string &name) const
Returns the first child element with the specified name.
Definition XmlElement.cpp:117
XmlElement::elementAt
XmlElement * elementAt(int index) const
Returns the child element at the specified index.
Definition XmlElement.cpp:107
XmlElement::Elements
std::deque< XmlElement * > Elements
Definition XmlElement.h:137
XmlElement::setContent
void setContent(const std::string &content)
Sets the content of the element.
Definition XmlElement.cpp:63
XmlElement::m_content
std::string m_content
Definition XmlElement.h:132
XmlElement::name
std::string name() const
Returns the name of the element.
Definition XmlElement.cpp:42
XmlElement::toString
std::string toString(const std::string &indent="") const
Returns a XML string that represents the element.
Definition XmlElement.cpp:132
XmlElement::XmlElement
XmlElement(std::string elementName, std::string content="")
Constructs an element with the specified name and string content.
Definition XmlElement.cpp:9
XmlElement::elementCount
int elementCount() const
Returns the number of child elements.
Definition XmlElement.cpp:100
XmlElement::Attribute
std::pair< std::string, std::string > Attribute
Definition XmlElement.h:125
XmlElement::m_elements
Elements m_elements
Definition XmlElement.h:138

| Send comments to: CppUnit Developers