iterate over the _aggregated_ objects: this does not include the initial pointer.
--- a/src/core/object.cc Wed Apr 09 17:35:18 2008 -0700
+++ b/src/core/object.cc Thu Apr 10 09:23:24 2008 -0700
@@ -45,10 +45,6 @@
bool
Object::AggregateIterator::HasNext (void) const
{
- if (m_current == 0 && m_first != 0)
- {
- return true;
- }
if (m_current != 0 && m_current->m_next != PeekPointer (m_first))
{
return true;
@@ -58,19 +54,12 @@
Ptr<const Object>
Object::AggregateIterator::Next (void)
{
- if (m_current == 0)
- {
- m_current = m_first;
- }
- else
- {
- m_current = m_current->m_next;
- }
+ m_current = m_current->m_next;
return m_current;
}
Object::AggregateIterator::AggregateIterator (Ptr<const Object> first)
: m_first (first),
- m_current (0)
+ m_current (first)
{}
--- a/src/core/object.h Wed Apr 09 17:35:18 2008 -0700
+++ b/src/core/object.h Thu Apr 10 09:23:24 2008 -0700
@@ -47,12 +47,28 @@
public:
static TypeId GetTypeId (void);
+ /**
+ * \brief Iterate over the objects aggregated to an ns3::Object.
+ *
+ * This iterator does not allow you to iterate over the initial
+ * object used to call Object::GetAggregateIterator.
+ *
+ * Note: this is a java-style iterator.
+ */
class AggregateIterator
{
public:
AggregateIterator ();
+ /**
+ * \returns true if HasNext can be called and return a non-null
+ * pointer, false otherwise.
+ */
bool HasNext (void) const;
+
+ /**
+ * \returns the next aggregated object.
+ */
Ptr<const Object> Next (void);
private:
friend class Object;
@@ -114,6 +130,14 @@
*/
void AggregateObject (Ptr<Object> other);
+ /**
+ * \returns an iterator to the first object aggregated to this
+ * object.
+ *
+ * If no objects are aggregated to this object, then, the returned
+ * iterator will be empty and AggregateIterator::HasNext will
+ * always return false.
+ */
AggregateIterator GetAggregateIterator (void) const;
protected: