helper+tests: API change and test case improvements of FaceContainer
Change-Id: Idf0c15907b7492404b83c9eb78a4cbeb9c721951
diff --git a/helper/ndn-face-container.cpp b/helper/ndn-face-container.cpp
index 1c37be7..5e9c6e3 100644
--- a/helper/ndn-face-container.cpp
+++ b/helper/ndn-face-container.cpp
@@ -24,9 +24,7 @@
namespace ns3 {
namespace ndn {
-FaceContainer::FaceContainer()
-{
-}
+FaceContainer::FaceContainer() = default;
FaceContainer::FaceContainer(const FaceContainer& other)
{
@@ -51,7 +49,13 @@
void
FaceContainer::AddAll(const FaceContainer& other)
{
- m_faces.insert(m_faces.end(), other.m_faces.begin(), other.m_faces.end());
+ if (this == &other) { // adding self to self, need to make a copy
+ auto copyOfFaces = other.m_faces;
+ m_faces.insert(m_faces.end(), copyOfFaces.begin(), copyOfFaces.end());
+ }
+ else {
+ m_faces.insert(m_faces.end(), other.m_faces.begin(), other.m_faces.end());
+ }
}
FaceContainer::Iterator
@@ -72,27 +76,16 @@
return m_faces.size();
}
-// void
-// FaceContainer::SetMetricToAll (uint16_t metric)
-// {
-// for (FaceContainer::iterator it=m_faces.begin ();
-// it != m_faces.end ();
-// it++)
-// {
-// (*it)->SetMetric (metric);
-// }
-// }
-
void
-FaceContainer::Add(const shared_ptr<Face>& face)
+FaceContainer::Add(shared_ptr<Face> face)
{
m_faces.push_back(face);
}
shared_ptr<Face>
-FaceContainer::Get(FaceContainer::Iterator i) const
+FaceContainer::Get(size_t i) const
{
- return *i;
+ return m_faces.at(i);
}
} // namespace ndn
diff --git a/helper/ndn-face-container.hpp b/helper/ndn-face-container.hpp
index 84d8e7f..e55cc2a 100644
--- a/helper/ndn-face-container.hpp
+++ b/helper/ndn-face-container.hpp
@@ -46,100 +46,89 @@
typedef std::vector<shared_ptr<Face>> Container;
public:
- typedef Container::const_iterator Iterator; ///< \brief Iterator over FaceContainer
+ typedef Container::const_iterator Iterator; ///< @brief Iterator over FaceContainer
/**
- * \brief Create an empty FaceContainer.
+ * @brief Create an empty FaceContainer.
*/
FaceContainer();
/**
- * \brief Copy constructor for FaceContainer. Calls AddAll method
+ * @brief Copy constructor for FaceContainer. Calls AddAll method
*
- * \see FaceContainer::AddAll
+ * @see FaceContainer::AddAll
*/
FaceContainer(const FaceContainer& other);
/**
- * \brief Copy operator for FaceContainer. Empties vector and calls AddAll method
+ * @brief Copy operator for FaceContainer. Empties vector and calls AddAll method
*
* All previously obtained iterators (Begin() and End()) will be invalidated
*
- * \see FaceContainer::AddAll
+ * @see FaceContainer::AddAll
*/
FaceContainer&
operator=(const FaceContainer& other);
/**
- * \brief Add all entries from other container
+ * Add an entry to the container
*
- * \param other smart pointer to a container
+ * @param face a smart pointer to a Face-derived object
+ */
+ void
+ Add(shared_ptr<Face> face);
+
+ /**
+ * @brief Add all entries from other container
+ *
+ * @param other smart pointer to a container
*/
void
AddAll(Ptr<FaceContainer> other);
/**
- * \brief Add all entries from other container
+ * @brief Add all entries from other container
*
- * \param other container
+ * @param other container
*/
void
AddAll(const FaceContainer& other);
+public: // accessors
/**
- * \brief Get an iterator which refers to the first pair in the
+ * @brief Get an iterator which refers to the first pair in the
* container.
*
- * \returns an iterator which refers to the first pair in the container.
+ * @returns an iterator which refers to the first pair in the container.
*/
Iterator
Begin() const;
/**
- * \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.
*
- * \returns an iterator which indicates an ending condition for a loop.
+ * @returns an iterator which indicates an ending condition for a loop.
*/
Iterator
End() const;
/**
- * \brief Get the number of faces stored in this container
+ * @brief Get the number of faces stored in this container
*
- * \returns the number of faces stored in this container
+ * @returns the number of faces stored in this container
*/
uint32_t
GetN() const;
- // /**
- // * \brief Set a metric for all faces in the container
- // *
- // * \param metric value of metric to assign to all faces in the container
- // */
- // void SetMetricToAll (uint16_t metric);
-
/**
- * Add an entry to the container
+ * Get a Face stored in the container
*
- * \param face a smart pointer to a Face-derived object
- *
- * @see Face
- */
- void
- Add(const shared_ptr<Face>& face);
-
- /**
- * Get a smart pointer to Face-derived object stored in the container
- *
- * \param i the iterator corresponding to the requested object
- *
- * This method is redundant and simple dereferencing of the iterator should be used instead
- *
- * @see Face
+ * @param pos index of the Face in the container
+ * @throw std::out_of_range if !(pos < GetN()).
*/
shared_ptr<Face>
- Get(Iterator i) const;
+ Get(size_t pos) const;
private:
Container m_faces;