iterate over the _aggregated_ objects: this does not include the initial pointer.

This commit is contained in:
Mathieu Lacage
2008-04-10 09:23:24 -07:00
parent 923b1180f9
commit 4a556dbf91
2 changed files with 26 additions and 13 deletions

View File

@@ -45,10 +45,6 @@ Object::AggregateIterator::AggregateIterator ()
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 @@ Object::AggregateIterator::HasNext (void) const
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)
{}

View File

@@ -47,12 +47,28 @@ class Object : public ObjectBase
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 @@ public:
*/
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: