aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
gum::XmlElement Class Reference

A non-owning handle to an XML element, opaque over ticpp::Element. More...

#include <XmlDocument.h>

Public Member Functions

 XmlElement ()=default
bool isNull () const noexcept
XmlElement firstChildElement (const std::string &tag) const
XmlElement firstChildElement (const std::string &tag, bool throwIfNotFound) const
 Returns a null XmlElement instead of throwing when throwIfNotFound is false.
std::vector< XmlElement > children (const std::string &tag) const
 All direct children with this tag, in document order.
std::string textOrDefault (const std::string &defaultValue) const
std::string attribute (const std::string &name) const
bool attribute (const std::string &name, std::string *out, bool throwIfNotFound=false) const
 Returns false instead of throwing when the attribute is missing and throwIfNotFound is false; *out is left untouched in that case.

Private Member Functions

 XmlElement (void *ticppElement) noexcept

Private Attributes

void * _handle_ = nullptr
 opaque ticpp::Element*, never exposed

Friends

class XmlDocument

Detailed Description

A non-owning handle to an XML element, opaque over ticpp::Element.

Default-constructed (or returned by a failed non-throwing lookup) as null: check with isNull() before use.

Definition at line 89 of file XmlDocument.h.

Constructor & Destructor Documentation

◆ XmlElement() [1/2]

gum::XmlElement::XmlElement ( )
default

References XmlElement(), attribute(), children(), firstChildElement(), isNull(), gum::MultiDimFunctionGraph< float >::defaultValue, and textOrDefault().

Referenced by XmlElement(), children(), gum::XmlDocument::firstChildElement(), firstChildElement(), firstChildElement(), and XmlDocument.

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

◆ XmlElement() [2/2]

gum::XmlElement::XmlElement ( void * ticppElement)
explicitprivatenoexcept

Definition at line 52 of file XmlDocument.cpp.

52: _handle_(ticppElement) {}
void * _handle_
opaque ticpp::Element*, never exposed

References _handle_.

Member Function Documentation

◆ attribute() [1/2]

std::string gum::XmlElement::attribute ( const std::string & name) const
Exceptions
XmlExceptionif the attribute is missing.

Definition at line 86 of file XmlDocument.cpp.

86 {
87 auto* self = static_cast< ticpp::Element* >(_handle_);
88 try {
89 return self->GetAttribute(name);
90 } catch (ticpp::Exception& e) { throw XmlException(e.what()); }
91 }
XmlException(std::string message)

References gum::XmlException::XmlException(), and _handle_.

Referenced by XmlElement().

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

◆ attribute() [2/2]

bool gum::XmlElement::attribute ( const std::string & name,
std::string * out,
bool throwIfNotFound = false ) const

Returns false instead of throwing when the attribute is missing and throwIfNotFound is false; *out is left untouched in that case.

Definition at line 94 of file XmlDocument.cpp.

94 {
95 auto* self = static_cast< ticpp::Element* >(_handle_);
96 // ticpp's GetAttribute(name, out, false) returns silently (no exception,
97 // *out untouched) when the attribute is missing, so the try/catch below
98 // never fires on that path -- HasAttribute is the only reliable signal.
99 const bool found = self->HasAttribute(name);
100 try {
101 self->GetAttribute(name, out, throwIfNotFound);
102 } catch (ticpp::Exception& e) { throw XmlException(e.what()); }
103 return found;
104 }

References gum::XmlException::XmlException(), and _handle_.

Here is the call graph for this function:

◆ children()

std::vector< XmlElement > gum::XmlElement::children ( const std::string & tag) const

All direct children with this tag, in document order.

Definition at line 70 of file XmlDocument.cpp.

70 {
71 std::vector< XmlElement > result;
72 if (_handle_ == nullptr) { return result; }
73 auto* parent = static_cast< ticpp::Element* >(_handle_);
74 ticpp::Iterator< ticpp::Element > it(tag);
75 for (it = it.begin(parent); it != it.end(); ++it) {
76 result.push_back(XmlElement(it.Get()));
77 }
78 return result;
79 }
XmlElement()=default

References XmlElement(), and _handle_.

Referenced by XmlElement().

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

◆ firstChildElement() [1/2]

XmlElement gum::XmlElement::firstChildElement ( const std::string & tag) const
Exceptions
XmlExceptionif no such child exists.

Definition at line 56 of file XmlDocument.cpp.

56 {
57 auto* self = static_cast< ticpp::Element* >(_handle_);
58 try {
59 return XmlElement(self->FirstChildElement(tag));
60 } catch (ticpp::Exception& e) { throw XmlException(e.what()); }
61 }

References XmlElement(), gum::XmlException::XmlException(), and _handle_.

Referenced by XmlElement().

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

◆ firstChildElement() [2/2]

XmlElement gum::XmlElement::firstChildElement ( const std::string & tag,
bool throwIfNotFound ) const

Returns a null XmlElement instead of throwing when throwIfNotFound is false.

Definition at line 63 of file XmlDocument.cpp.

63 {
64 auto* self = static_cast< ticpp::Element* >(_handle_);
65 try {
66 return XmlElement(self->FirstChildElement(tag, throwIfNotFound));
67 } catch (ticpp::Exception& e) { throw XmlException(e.what()); }
68 }

References XmlElement(), gum::XmlException::XmlException(), and _handle_.

Here is the call graph for this function:

◆ isNull()

bool gum::XmlElement::isNull ( ) const
noexcept

Definition at line 54 of file XmlDocument.cpp.

54{ return _handle_ == nullptr; }

References _handle_.

Referenced by XmlElement().

Here is the caller graph for this function:

◆ textOrDefault()

std::string gum::XmlElement::textOrDefault ( const std::string & defaultValue) const

Definition at line 81 of file XmlDocument.cpp.

81 {
82 auto* self = static_cast< ticpp::Element* >(_handle_);
83 return self->GetTextOrDefault(defaultValue);
84 }
const float MultiDimFunctionGraph< float >::defaultValue

References _handle_, and gum::MultiDimFunctionGraph< float >::defaultValue.

Referenced by XmlElement().

Here is the caller graph for this function:

◆ XmlDocument

friend class XmlDocument
friend

Definition at line 114 of file XmlDocument.h.

References XmlElement(), and XmlDocument.

Referenced by XmlDocument.

Member Data Documentation

◆ _handle_

void* gum::XmlElement::_handle_ = nullptr
private

opaque ticpp::Element*, never exposed

Definition at line 118 of file XmlDocument.h.

Referenced by XmlElement(), attribute(), attribute(), children(), firstChildElement(), firstChildElement(), isNull(), and textOrDefault().


The documentation for this class was generated from the following files: