aGrUM 3.2.0
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

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

Here is the caller graph for this function:

◆ XmlElement() [2/2]

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

Definition at line 116 of file XmlDocument.h.

116: _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 82 of file XmlDocument.cpp.

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

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

Here is the call 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 90 of file XmlDocument.cpp.

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

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 66 of file XmlDocument.cpp.

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

References XmlElement(), and _handle_.

Here is the call 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 52 of file XmlDocument.cpp.

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

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

Here is the call 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 59 of file XmlDocument.cpp.

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

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

Here is the call graph for this function:

◆ isNull()

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

Definition at line 93 of file XmlDocument.h.

93{ return _handle_ == nullptr; }

References _handle_.

◆ textOrDefault()

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

Definition at line 77 of file XmlDocument.cpp.

77 {
78 auto* self = static_cast< ticpp::Element* >(_handle_);
79 return self->GetTextOrDefault(defaultValue);
80 }
const float MultiDimFunctionGraph< float >::defaultValue

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

◆ XmlDocument

friend class XmlDocument
friend

Definition at line 114 of file XmlDocument.h.

References 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: