iterate over the _aggregated_ objects: this does not include the initial pointer.
1.1 --- a/src/core/object.cc Wed Apr 09 17:35:18 2008 -0700
1.2 +++ b/src/core/object.cc Thu Apr 10 09:23:24 2008 -0700
1.3 @@ -45,10 +45,6 @@
1.4 bool
1.5 Object::AggregateIterator::HasNext (void) const
1.6 {
1.7 - if (m_current == 0 && m_first != 0)
1.8 - {
1.9 - return true;
1.10 - }
1.11 if (m_current != 0 && m_current->m_next != PeekPointer (m_first))
1.12 {
1.13 return true;
1.14 @@ -58,19 +54,12 @@
1.15 Ptr<const Object>
1.16 Object::AggregateIterator::Next (void)
1.17 {
1.18 - if (m_current == 0)
1.19 - {
1.20 - m_current = m_first;
1.21 - }
1.22 - else
1.23 - {
1.24 - m_current = m_current->m_next;
1.25 - }
1.26 + m_current = m_current->m_next;
1.27 return m_current;
1.28 }
1.29 Object::AggregateIterator::AggregateIterator (Ptr<const Object> first)
1.30 : m_first (first),
1.31 - m_current (0)
1.32 + m_current (first)
1.33 {}
1.34
1.35
2.1 --- a/src/core/object.h Wed Apr 09 17:35:18 2008 -0700
2.2 +++ b/src/core/object.h Thu Apr 10 09:23:24 2008 -0700
2.3 @@ -47,12 +47,28 @@
2.4 public:
2.5 static TypeId GetTypeId (void);
2.6
2.7 + /**
2.8 + * \brief Iterate over the objects aggregated to an ns3::Object.
2.9 + *
2.10 + * This iterator does not allow you to iterate over the initial
2.11 + * object used to call Object::GetAggregateIterator.
2.12 + *
2.13 + * Note: this is a java-style iterator.
2.14 + */
2.15 class AggregateIterator
2.16 {
2.17 public:
2.18 AggregateIterator ();
2.19
2.20 + /**
2.21 + * \returns true if HasNext can be called and return a non-null
2.22 + * pointer, false otherwise.
2.23 + */
2.24 bool HasNext (void) const;
2.25 +
2.26 + /**
2.27 + * \returns the next aggregated object.
2.28 + */
2.29 Ptr<const Object> Next (void);
2.30 private:
2.31 friend class Object;
2.32 @@ -114,6 +130,14 @@
2.33 */
2.34 void AggregateObject (Ptr<Object> other);
2.35
2.36 + /**
2.37 + * \returns an iterator to the first object aggregated to this
2.38 + * object.
2.39 + *
2.40 + * If no objects are aggregated to this object, then, the returned
2.41 + * iterator will be empty and AggregateIterator::HasNext will
2.42 + * always return false.
2.43 + */
2.44 AggregateIterator GetAggregateIterator (void) const;
2.45
2.46 protected: