| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#if !defined( INCLUDED_XML_XMLELEMENT_H ) |
| 23 |
#define INCLUDED_XML_XMLELEMENT_H |
| 24 |
|
| 25 |
#include "xml/ixml.h" |
| 26 |
#include "string/string.h" |
| 27 |
|
| 28 |
#include <map> |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
class StaticElement : public XMLElement |
| 33 |
{ |
| 34 |
typedef std::map<const char*, const char*, RawStringLess> attrs_t; |
| 35 |
public: |
| 36 |
StaticElement( const char* name ) |
| 37 |
: m_name( name ){ |
| 38 |
} |
| 39 |
void insertAttribute( const char* name, const char* value ){ |
| 40 |
m_attrs.insert( attrs_t::value_type( name, value ) ); |
| 41 |
} |
| 42 |
const char* name() const { |
| 43 |
return m_name; |
| 44 |
} |
| 45 |
const char* attribute( const char* name ) const { |
| 46 |
attrs_t::const_iterator i = m_attrs.find( name ); |
| 47 |
if ( i != m_attrs.end() ) { |
| 48 |
return i->second; |
| 49 |
} |
| 50 |
else{ |
| 51 |
return ""; |
| 52 |
} |
| 53 |
} |
| 54 |
void forEachAttribute( XMLAttrVisitor& visitor ) const { |
| 55 |
for ( attrs_t::const_iterator i = m_attrs.begin(); i != m_attrs.end(); ++i ) |
| 56 |
{ |
| 57 |
visitor.visit( i->first, i->second ); |
| 58 |
} |
| 59 |
} |
| 60 |
private: |
| 61 |
const char* m_name; |
| 62 |
attrs_t m_attrs; |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
class DynamicElement : public XMLElement |
| 67 |
{ |
| 68 |
typedef std::map<CopiedString, CopiedString> attrs_t; |
| 69 |
public: |
| 70 |
DynamicElement( const char* name ) |
| 71 |
: m_name( name ){ |
| 72 |
} |
| 73 |
void insertAttribute( const char* name, const char* value ){ |
| 74 |
m_attrs.insert( attrs_t::value_type( name, value ) ); |
| 75 |
} |
| 76 |
const char* name() const { |
| 77 |
return m_name.c_str(); |
| 78 |
} |
| 79 |
const char* attribute( const char* name ) const { |
| 80 |
attrs_t::const_iterator i = m_attrs.find( name ); |
| 81 |
if ( i != m_attrs.end() ) { |
| 82 |
return i->second.c_str(); |
| 83 |
} |
| 84 |
else{ |
| 85 |
return ""; |
| 86 |
} |
| 87 |
} |
| 88 |
void forEachAttribute( XMLAttrVisitor& visitor ) const { |
| 89 |
for ( attrs_t::const_iterator i = m_attrs.begin(); i != m_attrs.end(); ++i ) |
| 90 |
{ |
| 91 |
visitor.visit( i->first.c_str(), i->second.c_str() ); |
| 92 |
} |
| 93 |
} |
| 94 |
private: |
| 95 |
CopiedString m_name; |
| 96 |
attrs_t m_attrs; |
| 97 |
}; |
| 98 |
|
| 99 |
#endif |