g4tools  5.4.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
tools::xml::element Class Reference
Inheritance diagram for tools::xml::element:
Inheritance graph
[legend]
Collaboration diagram for tools::xml::element:
Collaboration graph
[legend]

Public Types

typedef std::pair< std::string, std::string > atb
 

Public Member Functions

virtual void * cast (cid a_class) const
 
 element (const std::string &a_name, const std::vector< atb > &a_atbs, const std::string &a_value)
 
virtual ~element ()
 
 element (const element &a_from)
 
elementoperator= (const element &a_from)
 
const std::string & name () const
 
const std::vector< atb > & attributes () const
 
const std::string & value () const
 
void set_value (const std::string &a_value)
 
bool is_attribute (const std::string &a_name) const
 
void add_attribute (const std::string &a_name, const std::string &a_value)
 
bool attribute_value (const std::string &a_atb, std::string &a_value) const
 
template<class T >
bool attribute_value (const std::string &a_atb, T &a_value) const
 
bool set_attribute_value (const std::string &a_atb, const std::string &a_value)
 
void remove_attributes (const std::string &a_atb)
 
void replace (const std::string &a_old, const std::string &a_new)
 
- Public Member Functions inherited from tools::xml::ielem
virtual ~ielem ()
 

Static Public Member Functions

static cid id_class ()
 

Protected Attributes

std::string m_name
 
std::vector< atbm_atbs
 
std::string m_value
 

Detailed Description

Definition at line 26 of file element.

Member Typedef Documentation

◆ atb

typedef std::pair<std::string,std::string> tools::xml::element::atb

Definition at line 37 of file element.

Constructor & Destructor Documentation

◆ element() [1/2]

tools::xml::element::element ( const std::string &  a_name,
const std::vector< atb > &  a_atbs,
const std::string &  a_value 
)
inline

Definition at line 39 of file element.

41  {
42 #ifdef TOOLS_MEM
43  mem::increment(s_class().c_str());
44 #endif
45  m_name = a_name;
46  m_atbs = a_atbs;
47  m_value = a_value;
48  }

◆ ~element()

virtual tools::xml::element::~element ( )
inlinevirtual

Definition at line 49 of file element.

49  {
50 #ifdef TOOLS_MEM
51  mem::decrement(s_class().c_str());
52 #endif
53  }

◆ element() [2/2]

tools::xml::element::element ( const element a_from)
inline

Definition at line 55 of file element.

56  :ielem(a_from) {
57 #ifdef TOOLS_MEM
58  mem::increment(s_class().c_str());
59 #endif
60  m_name = a_from.m_name;
61  m_atbs = a_from.m_atbs;
62  m_value = a_from.m_value;
63  }

Member Function Documentation

◆ add_attribute()

void tools::xml::element::add_attribute ( const std::string &  a_name,
const std::string &  a_value 
)
inline

Definition at line 82 of file element.

82  {
83  // No check is done about an existing a_name.
84  m_atbs.push_back(atb(a_name,a_value));
85  }

◆ attribute_value() [1/2]

bool tools::xml::element::attribute_value ( const std::string &  a_atb,
std::string &  a_value 
) const
inline

Definition at line 87 of file element.

87  {
89  if((*it).first==a_atb) {
90  a_value = (*it).second;
91  return true;
92  }
93  }
94  a_value.clear();
95  return false;
96  }

◆ attribute_value() [2/2]

template<class T >
bool tools::xml::element::attribute_value ( const std::string &  a_atb,
T &  a_value 
) const
inline

Definition at line 99 of file element.

99  {
100  std::string sv;
101  if(!attribute_value(a_atb,sv)) {a_value=T();return false;}
102  return to<T>(sv,a_value);
103  }

◆ attributes()

const std::vector<atb>& tools::xml::element::attributes ( ) const
inline

Definition at line 72 of file element.

72 {return m_atbs;}

◆ cast()

virtual void* tools::xml::element::cast ( cid  a_class) const
inlinevirtual

Implements tools::xml::ielem.

Definition at line 32 of file element.

32  {
33  if(void* p = cmp_cast<element>(this,a_class)) {return p;}
34  else return 0;
35  }

◆ id_class()

static cid tools::xml::element::id_class ( )
inlinestatic

Definition at line 31 of file element.

31 {return 0;}

◆ is_attribute()

bool tools::xml::element::is_attribute ( const std::string &  a_name) const
inline

Definition at line 76 of file element.

76  {
78  if((*it).first==a_name) return true;
79  }
80  return false;
81  }

◆ name()

const std::string& tools::xml::element::name ( ) const
inline

Definition at line 71 of file element.

71 {return m_name;}

◆ operator=()

element& tools::xml::element::operator= ( const element a_from)
inline

Definition at line 64 of file element.

64  {
65  m_name = a_from.m_name;
66  m_atbs = a_from.m_atbs;
67  m_value = a_from.m_value;
68  return *this;
69  }

◆ remove_attributes()

void tools::xml::element::remove_attributes ( const std::string &  a_atb)
inline

Definition at line 118 of file element.

118  {
119  std::vector<atb>::iterator it;
120  for(it=m_atbs.begin();it!=m_atbs.end();) {
121  if((*it).first==a_atb) {
122  it = m_atbs.erase(it);
123  } else {
124  ++it;
125  }
126  }
127  }

◆ replace()

void tools::xml::element::replace ( const std::string &  a_old,
const std::string &  a_new 
)
inline

Definition at line 129 of file element.

129  {
130  // Used by the obuild template system.
131  tools_vforit(atb,m_atbs,it) {
132  replace_((*it).second,a_old,a_new);
133  }
134  replace_(m_value,a_old,a_new);
135  }

◆ set_attribute_value()

bool tools::xml::element::set_attribute_value ( const std::string &  a_atb,
const std::string &  a_value 
)
inline

Definition at line 106 of file element.

106  {
107  tools_vforit(atb,m_atbs,it) {
108  if((*it).first==a_atb) {
109  (*it).second = a_value;
110  return true;
111  }
112  }
113  // Not found, add one :
114  m_atbs.push_back(atb(a_atb,a_value));
115  return true;
116  }

◆ set_value()

void tools::xml::element::set_value ( const std::string &  a_value)
inline

Definition at line 75 of file element.

75 {m_value = a_value;}

◆ value()

const std::string& tools::xml::element::value ( ) const
inline

Definition at line 73 of file element.

73 {return m_value;}

Member Data Documentation

◆ m_atbs

std::vector<atb> tools::xml::element::m_atbs
protected

Definition at line 139 of file element.

◆ m_name

std::string tools::xml::element::m_name
protected

Definition at line 138 of file element.

◆ m_value

std::string tools::xml::element::m_value
protected

Definition at line 140 of file element.


The documentation for this class was generated from the following file:
tools::xml::element::m_atbs
std::vector< atb > m_atbs
Definition: element:139
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools::replace_
bool replace_(std::string &a_string, const std::string &a_old, const std::string &a_new)
Definition: srep:44
tools::xml::element::atb
std::pair< std::string, std::string > atb
Definition: element:37
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::xml::element::attribute_value
bool attribute_value(const std::string &a_atb, std::string &a_value) const
Definition: element:87
tools::xml::element::m_value
std::string m_value
Definition: element:140
tools::xml::element::m_name
std::string m_name
Definition: element:138