aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
ticpp::Attribute Class Reference

Wrapper around TiXmlAttribute. More...

#include <ticpp.h>

Inheritance diagram for ticpp::Attribute:
Collaboration diagram for ticpp::Attribute:

Public Member Functions

 Attribute ()
 Construct an empty attribute.
 Attribute (const std::string &name, const std::string &value)
 Construct an attribute with name and value.
 Attribute (TiXmlAttribute *attribute)
template<class T>
void GetValue (T *value) const
 Get the value of this attribute Uses Base::FromString to convert TiXmlAttribute::ValueStr from a std::string, and puts it in the passed pointer.
std::string Value () const
 Get the value of this attribute.
template<class T>
void SetValue (const T &value)
 Set the value of this node.
template<class T>
void GetName (T *name) const
 Get the value of this attribute Uses Base::FromString to convert TiXmlAttribute::Name from a std::string, and puts it in the passed pointer.
std::string Name () const
 Get the value of this attribute.
template<class T>
void SetName (const T &name)
 Set the value of this attribute.
void operator= (const Attribute &copy)
 Attribute (const Attribute &copy)
 ~Attribute ()
AttributeNext (bool throwIfNoAttribute=true) const
 Get the next sibling attribute in the DOM.
AttributePrevious (bool throwIfNoAttribute=true) const
 Get the previous sibling attribute in the DOM.
void IterateNext (const std::string &, Attribute **next) const
void IteratePrevious (const std::string &, Attribute **previous) const
virtual void Print (FILE *file, int depth) const
 All TinyXml classes can print themselves to a filestream.
template<class T>
std::string ToString (const T &value) const
 Converts any class with a proper overload of the << opertor to a std::string.
std::string ToString (const std::string &value) const
template<class T>
void FromString (const std::string &temp, T *out) const
 Converts a std::string to any class with a proper overload of the >> opertor.
void FromString (const std::string &temp, std::string *out) const
 Specialization for std::string.
int Row () const
 Return the position, in the original source file, of this node or attribute.
int Column () const
 Return the position, in the original source file, of this node or attribute.
bool operator== (const Base &rhs) const
 Compare internal TiXml pointers to determine is both are wrappers around the same node.
bool operator!= (const Base &rhs) const
 Compare internal TiXml pointers to determine is both are wrappers around the same node.
std::string BuildDetailedErrorString () const
 Builds detailed error string using TiXmlDocument::Error() and others.

Protected Member Functions

void SetImpRC (TiXmlBase *nodeBase)
void ValidatePointer () const

Protected Attributes

TiCppRCImpm_impRC
 Holds status of internal TiXmlPointer - use this to determine if object has been deleted already.

Private Member Functions

TiXmlBaseGetBasePointer () const
void SetTiXmlPointer (TiXmlAttribute *newPointer)

Private Attributes

TiXmlAttributem_tiXmlPointer

Detailed Description

Wrapper around TiXmlAttribute.

Definition at line 297 of file ticpp.h.

Constructor & Destructor Documentation

◆ Attribute() [1/4]

Attribute::Attribute ( )

Construct an empty attribute.

Definition at line 75 of file ticpp.cpp.

75 {
76 SetTiXmlPointer(new TiXmlAttribute());
77 m_impRC->InitRef();
78}
void SetTiXmlPointer(TiXmlAttribute *newPointer)
Definition ticpp.cpp:174
TiCppRCImp * m_impRC
Holds status of internal TiXmlPointer - use this to determine if object has been deleted already.
Definition ticpp.h:267

References ticpp::Base::m_impRC, and SetTiXmlPointer().

Referenced by Attribute(), IterateNext(), IteratePrevious(), Next(), operator=(), and Previous().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Attribute() [2/4]

Attribute::Attribute ( const std::string & name,
const std::string & value )

Construct an attribute with name and value.

Parameters
nameThe name of the attribute
valueThe value of the attribute

Definition at line 85 of file ticpp.cpp.

85 {
86 SetTiXmlPointer(new TiXmlAttribute(name, value));
87 m_impRC->InitRef();
88}

References ticpp::Base::m_impRC, and SetTiXmlPointer().

Here is the call graph for this function:

◆ Attribute() [3/4]

Attribute::Attribute ( TiXmlAttribute * attribute)

Definition at line 80 of file ticpp.cpp.

80 {
81 SetTiXmlPointer(attribute);
82 m_impRC->IncRef();
83}

References ticpp::Base::m_impRC, and SetTiXmlPointer().

Here is the call graph for this function:

◆ Attribute() [4/4]

Attribute::Attribute ( const Attribute & copy)

Definition at line 101 of file ticpp.cpp.

102 : Base() {
103 // Dropping the reference to the old object
104 if (m_impRC!=nullptr) m_impRC->DecRef();
105
106 // Pointing to the new Object
108
109 // The internal tixml pointer changed in the above line
110 m_impRC->IncRef();
111}
TiXmlAttribute * m_tiXmlPointer
Definition ticpp.h:299

References Attribute(), ticpp::Base::m_impRC, m_tiXmlPointer, and SetTiXmlPointer().

Here is the call graph for this function:

◆ ~Attribute()

Attribute::~Attribute ( )

Definition at line 113 of file ticpp.cpp.

113{ m_impRC->DecRef(); }

References ticpp::Base::m_impRC.

Member Function Documentation

◆ BuildDetailedErrorString()

std::string ticpp::Base::BuildDetailedErrorString ( ) const
inlineinherited

Builds detailed error string using TiXmlDocument::Error() and others.

Definition at line 238 of file ticpp.h.

238 {
239 std::ostringstream full_message;
240#ifndef TICPP_NO_RTTI
241 TiXmlNode* node = dynamic_cast< TiXmlNode* >(GetBasePointer());
242
243 if (node != 0) {
244 TiXmlDocument* doc = node->GetDocument();
245
246 if (doc != 0) {
247 if (doc->Error()) {
248 full_message << "\nDescription: " << doc->ErrorDesc() << "\nFile: "
249 << (strlen(doc->Value()) > 0 ? doc->Value()
250 : "<unnamed-file>")
251 << "\nLine: " << doc->ErrorRow()
252 << "\nColumn: " << doc->ErrorCol();
253 }
254 }
255 }
256
257#endif
258 return full_message.str();
259 }
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition tinyxml.h:1743
int ErrorRow() const
Returns the location (if known) of the error.
Definition tinyxml.h:1761
bool Error() const
If an error occurs, Error will be set to true.
Definition tinyxml.h:1740
int ErrorCol() const
The column where the error occured. See ErrorRow().
Definition tinyxml.h:1762
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
Definition tinyxml.h:517
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
Definition tinyxml.cpp:424
virtual TiXmlBase * GetBasePointer() const =0

References TiXmlDocument::Error(), TiXmlDocument::ErrorCol(), TiXmlDocument::ErrorDesc(), TiXmlDocument::ErrorRow(), GetBasePointer(), TiXmlNode::GetDocument(), and TiXmlNode::Value().

Here is the call graph for this function:

◆ Column()

int ticpp::Base::Column ( ) const
inlineinherited

Return the position, in the original source file, of this node or attribute.

Wrapper around TiXmlBase::Row()

Definition at line 215 of file ticpp.h.

215{ return GetBasePointer()->Column(); }
int Column() const
See Row().
Definition tinyxml.h:276

References TiXmlBase::Column(), and GetBasePointer().

Here is the call graph for this function:

◆ FromString() [1/2]

void ticpp::Base::FromString ( const std::string & temp,
std::string * out ) const
inlineinherited

Specialization for std::string.

Definition at line 201 of file ticpp.h.

201 {
202 *out = temp;
203 }

◆ FromString() [2/2]

template<class T>
void ticpp::Base::FromString ( const std::string & temp,
T * out ) const
inlineinherited

Converts a std::string to any class with a proper overload of the >> opertor.

Parameters
tempThe string to be converted
out[OUT] The container for the returned value
Exceptions
ExceptionWhen temp cannot be converted to the target type

Definition at line 189 of file ticpp.h.

189 {
190 std::istringstream val(temp);
191 val >> *out;
192
193 if (val.fail()) {
194 TICPPTHROW("Could not convert \"" << temp << "\" to target type");
195 }
196 }
#define TICPPTHROW(message)
This allows you to stream your exceptions in.
Definition ticpp.h:92

References TICPPTHROW.

Referenced by ticpp::Attribute::GetName(), ticpp::Attribute::GetValue(), and ticpp::Node::GetValue().

Here is the caller graph for this function:

◆ GetBasePointer()

TiXmlBase * ticpp::Attribute::GetBasePointer ( ) const
inlineprivatevirtual

Implements ticpp::Base.

Definition at line 300 of file ticpp.h.

300 {
302 return m_tiXmlPointer;
303 }
void ValidatePointer() const
Definition ticpp.h:281

References m_tiXmlPointer, and ticpp::Base::ValidatePointer().

Here is the call graph for this function:

◆ GetName()

template<class T>
void ticpp::Attribute::GetName ( T * name) const
inline

Get the value of this attribute Uses Base::FromString to convert TiXmlAttribute::Name from a std::string, and puts it in the passed pointer.

Parameters
name[OUT] A pointer to fill with the name

Definition at line 370 of file ticpp.h.

370 {
372 FromString(m_tiXmlPointer->Name(), name);
373 }
void FromString(const std::string &temp, T *out) const
Converts a std::string to any class with a proper overload of the >> opertor.
Definition ticpp.h:189

References ticpp::Base::FromString(), m_tiXmlPointer, and ticpp::Base::ValidatePointer().

Here is the call graph for this function:

◆ GetValue()

template<class T>
void ticpp::Attribute::GetValue ( T * value) const
inline

Get the value of this attribute Uses Base::FromString to convert TiXmlAttribute::ValueStr from a std::string, and puts it in the passed pointer.

Parameters
value[OUT] A pointer to fill with the value

Definition at line 336 of file ticpp.h.

336 {
338 FromString(m_tiXmlPointer->ValueStr(), value);
339 }

References ticpp::Base::FromString(), m_tiXmlPointer, and ticpp::Base::ValidatePointer().

Here is the call graph for this function:

◆ IterateNext()

void Attribute::IterateNext ( const std::string & ,
Attribute ** next ) const

Definition at line 161 of file ticpp.cpp.

161 {
162 *next = Next(false);
163}
Attribute * Next(bool throwIfNoAttribute=true) const
Get the next sibling attribute in the DOM.
Definition ticpp.cpp:125

References Attribute(), and Next().

Here is the call graph for this function:

◆ IteratePrevious()

void Attribute::IteratePrevious ( const std::string & ,
Attribute ** previous ) const

Definition at line 165 of file ticpp.cpp.

165 {
166 *previous = Previous(false);
167}
Attribute * Previous(bool throwIfNoAttribute=true) const
Get the previous sibling attribute in the DOM.
Definition ticpp.cpp:143

References Attribute(), and Previous().

Here is the call graph for this function:

◆ Name()

std::string Attribute::Name ( ) const

Get the value of this attribute.

Simple wrapper for TiXmlAttribute::Name.

See also
GetName

Definition at line 120 of file ticpp.cpp.

120 {
122 return m_tiXmlPointer->Name();
123}

References m_tiXmlPointer, and ticpp::Base::ValidatePointer().

Here is the call graph for this function:

◆ Next()

Attribute * Attribute::Next ( bool throwIfNoAttribute = true) const

Get the next sibling attribute in the DOM.

Definition at line 125 of file ticpp.cpp.

125 {
127 TiXmlAttribute* attribute = m_tiXmlPointer->Next();
128
129 if (0 == attribute) {
130 if (throwIfNoAttribute) {
131 TICPPTHROW("No more attributes found")
132 } else {
133 return 0;
134 }
135 }
136
137 Attribute* temp = new Attribute(attribute);
138 attribute->m_spawnedWrappers.push_back(temp);
139
140 return temp;
141}
std::vector< ticpp::Base * > m_spawnedWrappers
Remember all wrappers that we've created with 'new' - ( e.g.
Definition ticpprc.h:63
Attribute()
Construct an empty attribute.
Definition ticpp.cpp:75

References Attribute(), TiCppRC::m_spawnedWrappers, m_tiXmlPointer, TICPPTHROW, and ticpp::Base::ValidatePointer().

Referenced by ticpp::Element::IterateFirst(), and IterateNext().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

bool ticpp::Base::operator!= ( const Base & rhs) const
inlineinherited

Compare internal TiXml pointers to determine is both are wrappers around the same node.

Definition at line 231 of file ticpp.h.

231 {
232 return (GetBasePointer() != rhs.GetBasePointer());
233 }

References GetBasePointer().

Here is the call graph for this function:

◆ operator=()

void Attribute::operator= ( const Attribute & copy)

Definition at line 90 of file ticpp.cpp.

90 {
91 // Dropping the reference to the old object
92 this->m_impRC->DecRef();
93
94 // Pointing to the new Object
96
97 // The internal tixml pointer changed in the above line
98 this->m_impRC->IncRef();
99}

References Attribute(), ticpp::Base::m_impRC, m_tiXmlPointer, and SetTiXmlPointer().

Here is the call graph for this function:

◆ operator==()

bool ticpp::Base::operator== ( const Base & rhs) const
inlineinherited

Compare internal TiXml pointers to determine is both are wrappers around the same node.

Definition at line 222 of file ticpp.h.

222 {
223 return (GetBasePointer() == rhs.GetBasePointer());
224 }

References GetBasePointer().

Here is the call graph for this function:

◆ Previous()

Attribute * Attribute::Previous ( bool throwIfNoAttribute = true) const

Get the previous sibling attribute in the DOM.

Definition at line 143 of file ticpp.cpp.

143 {
145 TiXmlAttribute* attribute = m_tiXmlPointer->Previous();
146
147 if (0 == attribute) {
148 if (throwIfNoAttribute) {
149 TICPPTHROW("No more attributes found")
150 } else {
151 return 0;
152 }
153 }
154
155 Attribute* temp = new Attribute(attribute);
156 attribute->m_spawnedWrappers.push_back(temp);
157
158 return temp;
159}

References Attribute(), TiCppRC::m_spawnedWrappers, m_tiXmlPointer, TICPPTHROW, and ticpp::Base::ValidatePointer().

Referenced by IteratePrevious().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Print()

void Attribute::Print ( FILE * file,
int depth ) const
virtual

All TinyXml classes can print themselves to a filestream.

Definition at line 169 of file ticpp.cpp.

169 {
171 m_tiXmlPointer->Print(file, depth);
172}

References m_tiXmlPointer, and ticpp::Base::ValidatePointer().

Here is the call graph for this function:

◆ Row()

int ticpp::Base::Row ( ) const
inlineinherited

Return the position, in the original source file, of this node or attribute.

Wrapper around TiXmlBase::Row()

Definition at line 209 of file ticpp.h.

209{ return GetBasePointer()->Row(); }
int Row() const
Return the position, in the original source file, of this node or attribute.
Definition tinyxml.h:275

References GetBasePointer(), and TiXmlBase::Row().

Here is the call graph for this function:

◆ SetImpRC()

void ticpp::Base::SetImpRC ( TiXmlBase * nodeBase)
inlineprotectedinherited

Definition at line 279 of file ticpp.h.

279{ m_impRC = nodeBase->m_tiRC; }
TiCppRCImp * m_tiRC
Pointer to reference counter.
Definition ticpprc.h:46

References m_impRC, and TiCppRC::m_tiRC.

Referenced by ticpp::Attribute::SetTiXmlPointer(), and ticpp::NodeImp< T >::SetTiXmlPointer().

Here is the caller graph for this function:

◆ SetName()

template<class T>
void ticpp::Attribute::SetName ( const T & name)
inline

Set the value of this attribute.

Uses Base::ToString to convert name to a std::string, then calls TiXmlAttribute::SetName.

Parameters
nameThe name to set

Definition at line 391 of file ticpp.h.

391 {
393 m_tiXmlPointer->SetName(ToString(name));
394 }
std::string ToString(const T &value) const
Converts any class with a proper overload of the << opertor to a std::string.
Definition ticpp.h:169

References m_tiXmlPointer, ticpp::Base::ToString(), and ticpp::Base::ValidatePointer().

Here is the call graph for this function:

◆ SetTiXmlPointer()

void Attribute::SetTiXmlPointer ( TiXmlAttribute * newPointer)
private

Definition at line 174 of file ticpp.cpp.

174 {
175 m_tiXmlPointer = newPointer;
176 SetImpRC(newPointer);
177}
void SetImpRC(TiXmlBase *nodeBase)
Definition ticpp.h:279

References m_tiXmlPointer, and ticpp::Base::SetImpRC().

Referenced by Attribute(), Attribute(), Attribute(), Attribute(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetValue()

template<class T>
void ticpp::Attribute::SetValue ( const T & value)
inline

Set the value of this node.

Uses Base::ToString to convert value to a std::string, then calls TiXmlAttribute::SetValue.

Parameters
valueThe value to set

Definition at line 357 of file ticpp.h.

357 {
359 m_tiXmlPointer->SetValue(ToString(value));
360 }

References m_tiXmlPointer, ticpp::Base::ToString(), and ticpp::Base::ValidatePointer().

Here is the call graph for this function:

◆ ToString() [1/2]

std::string ticpp::Base::ToString ( const std::string & value) const
inlineinherited

Definition at line 180 of file ticpp.h.

180{ return value; }

◆ ToString() [2/2]

template<class T>
std::string ticpp::Base::ToString ( const T & value) const
inlineinherited

Converts any class with a proper overload of the << opertor to a std::string.

Parameters
valueThe value to be converted
Exceptions
ExceptionWhen value cannot be converted to a std::string

Definition at line 169 of file ticpp.h.

169 {
170 std::stringstream convert;
171 convert << value;
172
173 if (convert.fail()) {
174 TICPPTHROW("Could not convert value to text");
175 }
176
177 return convert.str();
178 }

References TICPPTHROW.

Referenced by ticpp::Attribute::SetName(), ticpp::Attribute::SetValue(), and ticpp::Node::SetValue().

Here is the caller graph for this function:

◆ ValidatePointer()

void ticpp::Base::ValidatePointer ( ) const
inlineprotectedinherited

Definition at line 281 of file ticpp.h.

281 {
282 if (m_impRC->IsNull()) {
283 TICPPTHROW("Internal TiXml Pointer is nullptr");
284 }
285 }

References m_impRC, and TICPPTHROW.

Referenced by ticpp::Attribute::GetBasePointer(), ticpp::Attribute::GetName(), ticpp::NodeImp< T >::GetTiXmlPointer(), ticpp::Attribute::GetValue(), ticpp::Attribute::Name(), ticpp::Attribute::Next(), ticpp::Attribute::Previous(), ticpp::Attribute::Print(), ticpp::Attribute::SetName(), ticpp::Attribute::SetValue(), and ticpp::Attribute::Value().

Here is the caller graph for this function:

◆ Value()

std::string Attribute::Value ( ) const

Get the value of this attribute.

Simple wrapper for TiXmlAttribute::ValueStr.

See also
GetValue

Definition at line 115 of file ticpp.cpp.

115 {
117 return m_tiXmlPointer->ValueStr();
118}

References m_tiXmlPointer, and ticpp::Base::ValidatePointer().

Here is the call graph for this function:

Member Data Documentation

◆ m_impRC

◆ m_tiXmlPointer

TiXmlAttribute* ticpp::Attribute::m_tiXmlPointer
private

The documentation for this class was generated from the following files:
  • agrum/base/external/tinyxml/ticpp/ticpp.h
  • agrum/base/external/tinyxml/ticpp/ticpp.cpp