aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
ticpp::Iterator< T > Class Template Reference

Iterator for conveniently stepping through Nodes and Attributes. More...

#include <ticpp.h>

Collaboration diagram for ticpp::Iterator< T >:

Public Member Functions

T * begin (const Node *parent) const
 For for loop comparisons.
T * end () const
 For for loop comparisons.
 Iterator (const std::string &value="")
 Constructor.
 Iterator (T *node, const std::string &value="")
 Constructor.
 Iterator (const Iterator &it)
 Constructor.
T * Get () const
 Gets internal pointer.
Iteratoroperator= (const Iterator &it)
 Sets internal pointer.
Iteratoroperator= (T *p)
 Sets internal pointer.
Iteratoroperator++ ()
 Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings.
Iterator operator++ (int)
 Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings.
Iteratoroperator-- ()
 Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings.
Iterator operator-- (int)
 Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings.
bool operator!= (const T *p) const
 Compares internal pointer.
bool operator!= (const Iterator &it) const
 Compares internal pointer.
bool operator== (T *p) const
 Compares internal pointer*.
bool operator== (const Iterator &it) const
 Compares internal pointer.
T * operator-> () const
 So Iterator behaves like a STL iterator.
T & operator* () const
 So Iterator behaves like a STL iterator.

Private Attributes

T * m_p
 Internal Pointer.
std::string m_value
 Value for NextSibling calls.

Detailed Description

template<class T = Node>
class ticpp::Iterator< T >

Iterator for conveniently stepping through Nodes and Attributes.

TinyXML++ introduces iterators:

for ( child = child.begin( parent ); child != child.end(); child++ )
Iterator for conveniently stepping through Nodes and Attributes.
Definition ticpp.h:1112
T * end() const
For for loop comparisons.
Definition ticpp.h:1141
T * begin(const Node *parent) const
For for loop comparisons.
Definition ticpp.h:1127

Iterators have the added advantage of filtering by type:

// Only iterates through Comment nodes
for ( child = child.begin( parent ); child != child.end(); child++ )
// Only iterates through Element nodes with value "ElementValue"
ticpp::Iterator< ticpp::Element > child( "ElementValue" );
for ( child = child.begin( parent ); child != child.end(); child++ )

Finally, Iterators also work with Attributes

for ( attribute = attribute.begin( element ); attribute != attribute.end();
attribute++ )

Definition at line 1112 of file ticpp.h.

Constructor & Destructor Documentation

◆ Iterator() [1/3]

template<class T = Node>
ticpp::Iterator< T >::Iterator ( const std::string & value = "")
inline

Constructor.

Parameters
valueIf not empty, this iterator will only visit nodes with matching value.
// Only iterates through Element nodes with value "ElementValue"
ticpp::Iterator< ticpp::Element > child( "ElementValue" );
for ( child = child.begin( parent ); child != child.end(); child++ )

Definition at line 1152 of file ticpp.h.

1153 : m_p(0)
1154 , m_value(value) {}
T * m_p
Internal Pointer.
Definition ticpp.h:1114
std::string m_value
Value for NextSibling calls.
Definition ticpp.h:1115

References m_p, and m_value.

Referenced by Iterator(), operator!=(), operator++(), operator++(), operator--(), operator--(), operator=(), operator=(), and operator==().

Here is the caller graph for this function:

◆ Iterator() [2/3]

template<class T = Node>
ticpp::Iterator< T >::Iterator ( T * node,
const std::string & value = "" )
inline

Constructor.

Definition at line 1157 of file ticpp.h.

1158 : m_p(node)
1159 , m_value(value) {}

References m_p, and m_value.

◆ Iterator() [3/3]

template<class T = Node>
ticpp::Iterator< T >::Iterator ( const Iterator< T > & it)
inline

Constructor.

Definition at line 1162 of file ticpp.h.

1163 : m_p(it.m_p)
1164 , m_value(it.m_value) {}

References Iterator(), m_p, and m_value.

Here is the call graph for this function:

Member Function Documentation

◆ begin()

template<class T = Node>
T * ticpp::Iterator< T >::begin ( const Node * parent) const
inline

For for loop comparisons.

Parameters
parentThe parent of the nodes to iterate.
Returns
The first child of type T.
for ( child = child.begin( parent ); child != child.end(); child++ )

Definition at line 1127 of file ticpp.h.

1127 {
1128 T* pointer;
1129 parent->IterateFirst(m_value, &pointer);
1130 return pointer;
1131 }

References ticpp::Node::IterateFirst(), and m_value.

Here is the call graph for this function:

◆ end()

template<class T = Node>
T * ticpp::Iterator< T >::end ( ) const
inline

For for loop comparisons.

Returns
nullptr
for ( child = child.begin( parent ); child != child.end(); child++ )

Definition at line 1141 of file ticpp.h.

1141{ return 0; }

◆ Get()

template<class T = Node>
T * ticpp::Iterator< T >::Get ( ) const
inline

Gets internal pointer.

Returns
The internal pointer.

Definition at line 1170 of file ticpp.h.

1170{ return m_p; }

References m_p.

◆ operator!=() [1/2]

template<class T = Node>
bool ticpp::Iterator< T >::operator!= ( const Iterator< T > & it) const
inline

Compares internal pointer.

Definition at line 1233 of file ticpp.h.

1233{ return operator!=(it.m_p); }
bool operator!=(const T *p) const
Compares internal pointer.
Definition ticpp.h:1220

References Iterator(), m_p, and operator!=().

Referenced by operator!=().

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

◆ operator!=() [2/2]

template<class T = Node>
bool ticpp::Iterator< T >::operator!= ( const T * p) const
inline

Compares internal pointer.

Definition at line 1220 of file ticpp.h.

1220 {
1221 if (m_p == p) {
1222 return false;
1223 }
1224
1225 if (0 == m_p || 0 == p) {
1226 return true;
1227 }
1228
1229 return *m_p != *p;
1230 }

References m_p.

◆ operator*()

template<class T = Node>
T & ticpp::Iterator< T >::operator* ( ) const
inline

So Iterator behaves like a STL iterator.

Definition at line 1255 of file ticpp.h.

1255{ return *m_p; }

References m_p.

◆ operator++() [1/2]

template<class T = Node>
Iterator & ticpp::Iterator< T >::operator++ ( )
inline

Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings.

Definition at line 1188 of file ticpp.h.

1188 {
1189 m_p->IterateNext(m_value, &m_p);
1190 return *this;
1191 }

References Iterator(), m_p, and m_value.

Here is the call graph for this function:

◆ operator++() [2/2]

template<class T = Node>
Iterator ticpp::Iterator< T >::operator++ ( int )
inline

Sets internal pointer to the Next Sibling, or Iterator::END, if there are no more siblings.

Definition at line 1196 of file ticpp.h.

1196 {
1197 Iterator tmp(*this);
1198 ++(*this);
1199 return tmp;
1200 }
Iterator(const std::string &value="")
Constructor.
Definition ticpp.h:1152

References Iterator().

Here is the call graph for this function:

◆ operator--() [1/2]

template<class T = Node>
Iterator & ticpp::Iterator< T >::operator-- ( )
inline

Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings.

Definition at line 1205 of file ticpp.h.

1205 {
1206 m_p->IteratePrevious(m_value, &m_p);
1207 return *this;
1208 }

References Iterator(), m_p, and m_value.

Here is the call graph for this function:

◆ operator--() [2/2]

template<class T = Node>
Iterator ticpp::Iterator< T >::operator-- ( int )
inline

Sets internal pointer to the Previous Sibling, or Iterator::END, if there are no prior siblings.

Definition at line 1213 of file ticpp.h.

1213 {
1214 Iterator tmp(*this);
1215 --(*this);
1216 return tmp;
1217 }

References Iterator().

Here is the call graph for this function:

◆ operator->()

template<class T = Node>
T * ticpp::Iterator< T >::operator-> ( ) const
inline

So Iterator behaves like a STL iterator.

Definition at line 1252 of file ticpp.h.

1252{ return m_p; }

References m_p.

◆ operator=() [1/2]

template<class T = Node>
Iterator & ticpp::Iterator< T >::operator= ( const Iterator< T > & it)
inline

Sets internal pointer.

Definition at line 1173 of file ticpp.h.

1173 {
1174 m_p = it.m_p;
1175 m_value = it.m_value;
1176 return *this;
1177 }

References Iterator(), m_p, and m_value.

Here is the call graph for this function:

◆ operator=() [2/2]

template<class T = Node>
Iterator & ticpp::Iterator< T >::operator= ( T * p)
inline

Sets internal pointer.

Definition at line 1180 of file ticpp.h.

1180 {
1181 m_p = p;
1182 return *this;
1183 }

References Iterator(), and m_p.

Here is the call graph for this function:

◆ operator==() [1/2]

template<class T = Node>
bool ticpp::Iterator< T >::operator== ( const Iterator< T > & it) const
inline

Compares internal pointer.

Definition at line 1249 of file ticpp.h.

1249{ return operator==(it.m_p); }
bool operator==(T *p) const
Compares internal pointer*.
Definition ticpp.h:1236

References Iterator(), m_p, and operator==().

Referenced by operator==().

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

◆ operator==() [2/2]

template<class T = Node>
bool ticpp::Iterator< T >::operator== ( T * p) const
inline

Compares internal pointer*.

Definition at line 1236 of file ticpp.h.

1236 {
1237 if (m_p == p) {
1238 return true;
1239 }
1240
1241 if (0 == m_p || 0 == p) {
1242 return false;
1243 }
1244
1245 return *m_p == *p;
1246 }

References m_p.

Member Data Documentation

◆ m_p

template<class T = Node>
T* ticpp::Iterator< T >::m_p
private

◆ m_value

template<class T = Node>
std::string ticpp::Iterator< T >::m_value
private

Value for NextSibling calls.

Definition at line 1115 of file ticpp.h.

Referenced by Iterator(), Iterator(), Iterator(), begin(), operator++(), operator--(), and operator=().


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