diff --git a/src/network/helper/node-container.cc b/src/network/helper/node-container.cc index 6e1d66770..52fd8d14d 100644 --- a/src/network/helper/node-container.cc +++ b/src/network/helper/node-container.cc @@ -41,14 +41,14 @@ NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b) Add (a); Add (b); } -NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, +NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c) { Add (a); Add (b); Add (c); } -NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, +NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d) { Add (a); @@ -57,7 +57,7 @@ NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, Add (d); } -NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, +NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d, const NodeContainer &e) { @@ -68,28 +68,68 @@ NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b, Add (e); } -NodeContainer::Iterator +NodeContainer::Iterator NodeContainer::Begin (void) const { return m_nodes.begin (); } -NodeContainer::Iterator + +NodeContainer::const_iterator +NodeContainer::begin () const +{ + return m_nodes.begin (); +} + +NodeContainer::iterator +NodeContainer::begin () +{ + return m_nodes.begin (); +} + + +NodeContainer::Iterator NodeContainer::End (void) const { return m_nodes.end (); } -uint32_t +NodeContainer::const_iterator +NodeContainer::end () const +{ + return m_nodes.end (); +} + +NodeContainer::iterator +NodeContainer::end () +{ + return m_nodes.end (); +} + +uint32_t NodeContainer::GetN (void) const { return m_nodes.size (); } -Ptr + +uint32_t +NodeContainer::size () const +{ + return m_nodes.size (); +} + +Ptr NodeContainer::Get (uint32_t i) const { return m_nodes[i]; } -void + +Ptr & +NodeContainer::operator [] (uint32_t i) +{ + return m_nodes [i]; +} + +void NodeContainer::Create (uint32_t n) { for (uint32_t i = 0; i < n; i++) @@ -97,7 +137,7 @@ NodeContainer::Create (uint32_t n) m_nodes.push_back (CreateObject ()); } } -void +void NodeContainer::Create (uint32_t n, uint32_t systemId) { for (uint32_t i = 0; i < n; i++) @@ -105,7 +145,7 @@ NodeContainer::Create (uint32_t n, uint32_t systemId) m_nodes.push_back (CreateObject (systemId)); } } -void +void NodeContainer::Add (NodeContainer other) { for (Iterator i = other.Begin (); i != other.End (); i++) @@ -113,19 +153,19 @@ NodeContainer::Add (NodeContainer other) m_nodes.push_back (*i); } } -void +void NodeContainer::Add (Ptr node) { m_nodes.push_back (node); } -void +void NodeContainer::Add (std::string nodeName) { Ptr node = Names::Find (nodeName); m_nodes.push_back (node); } -NodeContainer +NodeContainer NodeContainer::GetGlobal (void) { NodeContainer c; diff --git a/src/network/helper/node-container.h b/src/network/helper/node-container.h index 80e40bf06..634e61647 100644 --- a/src/network/helper/node-container.h +++ b/src/network/helper/node-container.h @@ -39,6 +39,8 @@ class NodeContainer { public: typedef std::vector >::const_iterator Iterator; + typedef std::vector >::iterator iterator; + typedef std::vector >::const_iterator const_iterator; /** * Create an empty NodeContainer. @@ -54,9 +56,9 @@ public: NodeContainer (Ptr node); /** - * Create a NodeContainer with exactly one node which has been previously - * instantiated and assigned a name using the Object Name Service. This - * Node is then specified by its assigned name. + * Create a NodeContainer with exactly one node which has been previously + * instantiated and assigned a name using the Object Name Service. This + * Node is then specified by its assigned name. * * \param nodeName The name of the Node Object to add to the container. */ @@ -70,11 +72,11 @@ public: * \param b The second NodeContainer * * \note A frequently seen idiom that uses these constructors involves the - * implicit conversion by constructor of Ptr. When used, two + * implicit conversion by constructor of Ptr. When used, two * Ptr will be passed to this constructor instead of NodeContainer&. - * C++ will notice the implicit conversion path that goes through the + * C++ will notice the implicit conversion path that goes through the * NodeContainer (Ptr node) constructor above. Using this conversion - * one may provide optionally provide arguments of Ptr to these + * one may provide optionally provide arguments of Ptr to these * constructors. */ NodeContainer (const NodeContainer &a, const NodeContainer &b); @@ -88,11 +90,11 @@ public: * \param c The third NodeContainer * * \note A frequently seen idiom that uses these constructors involves the - * implicit conversion by constructor of Ptr. When used, two + * implicit conversion by constructor of Ptr. When used, two * Ptr will be passed to this constructor instead of NodeContainer&. - * C++ will notice the implicit conversion path that goes through the + * C++ will notice the implicit conversion path that goes through the * NodeContainer (Ptr node) constructor above. Using this conversion - * one may provide optionally provide arguments of Ptr to these + * one may provide optionally provide arguments of Ptr to these * constructors. */ NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c); @@ -107,11 +109,11 @@ public: * \param d The fourth NodeContainer * * \note A frequently seen idiom that uses these constructors involves the - * implicit conversion by constructor of Ptr. When used, two + * implicit conversion by constructor of Ptr. When used, two * Ptr will be passed to this constructor instead of NodeContainer&. - * C++ will notice the implicit conversion path that goes through the + * C++ will notice the implicit conversion path that goes through the * NodeContainer (Ptr node) constructor above. Using this conversion - * one may provide optionally provide arguments of Ptr to these + * one may provide optionally provide arguments of Ptr to these * constructors. */ NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d); @@ -127,23 +129,23 @@ public: * \param e The fifth NodeContainer * * \note A frequently seen idiom that uses these constructors involves the - * implicit conversion by constructor of Ptr. When used, two + * implicit conversion by constructor of Ptr. When used, two * Ptr will be passed to this constructor instead of NodeContainer&. - * C++ will notice the implicit conversion path that goes through the + * C++ will notice the implicit conversion path that goes through the * NodeContainer (Ptr node) constructor above. Using this conversion - * one may provide optionally provide arguments of Ptr to these + * one may provide optionally provide arguments of Ptr to these * constructors. */ NodeContainer (const NodeContainer &a, const NodeContainer &b, const NodeContainer &c, const NodeContainer &d, const NodeContainer &e); /** - * \brief Get an iterator which refers to the first Node in the + * \brief Get an iterator which refers to the first Node in the * container. * * Nodes can be retrieved from the container in two ways. First, * directly by an index into the container, and second, using an iterator. - * This method is used in the iterator method and is typically used in a + * This method is used in the iterator method and is typically used in a * for-loop to run through the Nodes * * \code @@ -158,13 +160,16 @@ public: */ Iterator Begin (void) const; + const_iterator begin () const; /// @brief STL-like method, @see Begin + iterator begin (); /// @brief STL-like method, @see Begin + /** - * \brief Get an iterator which indicates past-the-last Node in the + * \brief Get an iterator which indicates past-the-last Node in the * container. * * Nodes can be retrieved from the container in two ways. First, * directly by an index into the container, and second, using an iterator. - * This method is used in the iterator method and is typically used in a + * This method is used in the iterator method and is typically used in a * for-loop to run through the Nodes * * \code @@ -179,6 +184,9 @@ public: */ Iterator End (void) const; + const_iterator end () const; /// @brief STL-like method, @see End + iterator end (); /// @brief STL-like method, @see End + /** * \brief Get the number of Ptr stored in this container. * @@ -201,6 +209,8 @@ public: */ uint32_t GetN (void) const; + uint32_t size () const; /// @brief STL-like method, @see GetN + /** * \brief Get the Ptr stored in this container at a given * index. @@ -222,10 +232,14 @@ public: * \param i the index of the requested node pointer. * \returns the requested node pointer. */ - Ptr Get (uint32_t i) const; + Ptr + Get (uint32_t i) const; + + Ptr & + operator [] (uint32_t i); /// @brief STL-like method, @see Get /** - * \brief Create n nodes and append pointers to them to the end of this + * \brief Create n nodes and append pointers to them to the end of this * NodeContainer. * * Nodes are at the heart of any ns-3 simulation. One of the first tasks that @@ -237,12 +251,12 @@ public: void Create (uint32_t n); /** - * \brief Create n nodes with specified systemId for distributed simulations + * \brief Create n nodes with specified systemId for distributed simulations * and append pointers to them to the end of this NodeContainer. * * Nodes are at the heart of any ns-3 simulation. One of the first tasks that * any simulation needs to do is to create a number of nodes. This method - * automates that task, and adds the ability to specify systemId for + * automates that task, and adds the ability to specify systemId for * distributed simulations. * * \param n The number of Nodes to create @@ -275,12 +289,12 @@ public: /** * \brief Create a NodeContainer that contains a list of _all_ nodes - * created through NodeContainer::Create() and stored in the + * created through NodeContainer::Create() and stored in the * ns3::NodeList. * * Whenever a Node is created, a Ptr is added to a global list of all * nodes in the system. It is sometimes useful to be able to get to all - * nodes in one place. This method creates a NodeContainer that is + * nodes in one place. This method creates a NodeContainer that is * initialized to contain all of the simulation nodes, * * \returns a NoceContainer which contains a list of all Nodes.