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

Public Member Functions

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

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++ )

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.

References ticpp::Iterator< T >::Iterator(), and ticpp::Iterator< T >::m_p.

Referenced by ticpp::Iterator< T >::Iterator().

1153  : m_p(0)
1154  , m_value(value) {}
std::string m_value
Value for NextSibling calls.
Definition: ticpp.h:1115
T * m_p
Internal Pointer.
Definition: ticpp.h:1114
+ Here is the call graph for this function:
+ 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.

References ticpp::Iterator< T >::Iterator(), and ticpp::Iterator< T >::m_p.

Referenced by ticpp::Iterator< T >::Iterator().

1158  : m_p(node)
1159  , m_value(value) {}
std::string m_value
Value for NextSibling calls.
Definition: ticpp.h:1115
T * m_p
Internal Pointer.
Definition: ticpp.h:1114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

References ticpp::Iterator< T >::Iterator(), and ticpp::Iterator< T >::m_p.

Referenced by ticpp::Iterator< T >::Iterator().

1163  : m_p(it.m_p)
1164  , m_value(it.m_value) {}
std::string m_value
Value for NextSibling calls.
Definition: ticpp.h:1115
T * m_p
Internal Pointer.
Definition: ticpp.h:1114
+ Here is the call graph for this function:
+ Here is the caller 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  }
std::string m_value
Value for NextSibling calls.
Definition: ticpp.h:1115

◆ 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.

References ticpp::Iterator< T >::m_p.

1170 { return m_p; }
T * m_p
Internal Pointer.
Definition: ticpp.h:1114

◆ operator!=() [1/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.

References ticpp::Iterator< T >::m_p.

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  }
T * m_p
Internal Pointer.
Definition: ticpp.h:1114

◆ operator!=() [2/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

◆ 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.

References ticpp::Iterator< T >::m_p.

1255 { return *m_p; }
T * m_p
Internal Pointer.
Definition: ticpp.h:1114

◆ 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  }
std::string m_value
Value for NextSibling calls.
Definition: ticpp.h:1115
T * m_p
Internal Pointer.
Definition: ticpp.h:1114

◆ 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

◆ 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  }
std::string m_value
Value for NextSibling calls.
Definition: ticpp.h:1115
T * m_p
Internal Pointer.
Definition: ticpp.h:1114

◆ 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  }
Iterator(const std::string &value="")
Constructor.
Definition: ticpp.h:1152

◆ 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.

References ticpp::Iterator< T >::m_p.

1252 { return m_p; }
T * m_p
Internal Pointer.
Definition: ticpp.h:1114

◆ 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.

References ticpp::Iterator< T >::m_p.

1173  {
1174  m_p = it.m_p;
1175  m_value = it.m_value;
1176  return *this;
1177  }
std::string m_value
Value for NextSibling calls.
Definition: ticpp.h:1115
T * m_p
Internal Pointer.
Definition: ticpp.h:1114

◆ 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.

References ticpp::Iterator< T >::m_p.

1180  {
1181  m_p = p;
1182  return *this;
1183  }
T * m_p
Internal Pointer.
Definition: ticpp.h:1114

◆ operator==() [1/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.

References ticpp::Iterator< T >::m_p.

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  }
T * m_p
Internal Pointer.
Definition: ticpp.h:1114

◆ operator==() [2/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

Member Data Documentation

◆ m_p

◆ 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.


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