blob: 5e9c6e3170e48c33b13b076213827f8b46e04e3e [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev7112f482011-08-17 14:05:57 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev7112f482011-08-17 14:05:57 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyev7112f482011-08-17 14:05:57 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev7112f482011-08-17 14:05:57 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070019
Alexander Afanasyev0c395372014-12-20 15:54:02 -080020#include "ndn-face-container.hpp"
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070021
Alexander Afanasyev7112f482011-08-17 14:05:57 -070022#include <algorithm>
23
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070024namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070025namespace ndn {
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070026
Alexander Afanasyev241df872015-08-13 17:26:15 -070027FaceContainer::FaceContainer() = default;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070028
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080029FaceContainer::FaceContainer(const FaceContainer& other)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070030{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080031 AddAll(other);
Alexander Afanasyev7112f482011-08-17 14:05:57 -070032}
33
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070034FaceContainer&
35FaceContainer::operator= (const FaceContainer &other)
Alexander Afanasyev7112f482011-08-17 14:05:57 -070036{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080037 m_faces.clear();
38 AddAll(other);
Alexander Afanasyev7112f482011-08-17 14:05:57 -070039
40 return *this;
41}
42
Alexander Afanasyev7112f482011-08-17 14:05:57 -070043void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044FaceContainer::AddAll(Ptr<FaceContainer> other)
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070045{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 AddAll(*other);
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070047}
48
49void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050FaceContainer::AddAll(const FaceContainer& other)
Alexander Afanasyev7112f482011-08-17 14:05:57 -070051{
Alexander Afanasyev241df872015-08-13 17:26:15 -070052 if (this == &other) { // adding self to self, need to make a copy
53 auto copyOfFaces = other.m_faces;
54 m_faces.insert(m_faces.end(), copyOfFaces.begin(), copyOfFaces.end());
55 }
56 else {
57 m_faces.insert(m_faces.end(), other.m_faces.begin(), other.m_faces.end());
58 }
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070059}
60
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070061FaceContainer::Iterator
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062FaceContainer::Begin(void) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070063{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 return m_faces.begin();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070065}
66
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070067FaceContainer::Iterator
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068FaceContainer::End(void) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070069{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 return m_faces.end();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070071}
72
73uint32_t
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074FaceContainer::GetN(void) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070075{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 return m_faces.size();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070077}
78
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079void
Alexander Afanasyev241df872015-08-13 17:26:15 -070080FaceContainer::Add(shared_ptr<Face> face)
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070081{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 m_faces.push_back(face);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070083}
84
Spyridon Mastorakise4f0d3c2014-10-29 13:20:03 -070085shared_ptr<Face>
Alexander Afanasyev241df872015-08-13 17:26:15 -070086FaceContainer::Get(size_t i) const
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070087{
Alexander Afanasyev241df872015-08-13 17:26:15 -070088 return m_faces.at(i);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070089}
90
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070091} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070092} // namespace ns3