blob: 6afdb543609a2c62b249cf42b96ea148c27ce14e [file] [log] [blame]
akmhoque3d06e792014-05-27 16:23:20 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 University of Memphis,
4 * Regents of the University of California
5 *
6 * This file is part of NLSR (Named-data Link State Routing).
7 * See AUTHORS.md for complete list of NLSR authors and contributors.
8 *
9 * NLSR is free software: you can redistribute it and/or modify it under the terms
10 * of the GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
12 *
13 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * \author A K M Mahmudul Hoque <ahoque1@memphis.edu>
21 *
22 **/
akmhoque53353462014-04-22 08:43:45 -050023#include <iostream>
24#include <algorithm>
25
akmhoquec8a10f72014-04-25 18:42:55 -050026#include <ndn-cxx/common.hpp>
27
Vince Lehman0a7da612014-10-29 14:39:29 -050028#include "common.hpp"
akmhoquec8a10f72014-04-25 18:42:55 -050029#include "name-prefix-list.hpp"
akmhoque674b0b12014-05-20 14:33:28 -050030#include "logger.hpp"
akmhoque53353462014-04-22 08:43:45 -050031
32namespace nlsr {
33
akmhoque674b0b12014-05-20 14:33:28 -050034INIT_LOGGER("NamePrefixList");
35
akmhoque53353462014-04-22 08:43:45 -050036using namespace std;
37
akmhoquec8a10f72014-04-25 18:42:55 -050038NamePrefixList::NamePrefixList()
akmhoque53353462014-04-22 08:43:45 -050039{
40}
41
akmhoquec8a10f72014-04-25 18:42:55 -050042NamePrefixList::~NamePrefixList()
akmhoque53353462014-04-22 08:43:45 -050043{
44}
45
46static bool
akmhoque31d1d4b2014-05-05 22:08:14 -050047nameCompare(const ndn::Name& name1, const ndn::Name& name2)
akmhoque53353462014-04-22 08:43:45 -050048{
akmhoque31d1d4b2014-05-05 22:08:14 -050049 return name1 == name2;
akmhoque53353462014-04-22 08:43:45 -050050}
51
akmhoquefdbddb12014-05-02 18:35:19 -050052int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050053NamePrefixList::insert(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050054{
akmhoque31d1d4b2014-05-05 22:08:14 -050055 std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
56 m_nameList.end(),
57 ndn::bind(&nameCompare, _1 ,
58 ndn::cref(name)));
akmhoque157b0a42014-05-13 00:26:37 -050059 if (it != m_nameList.end()) {
akmhoque53353462014-04-22 08:43:45 -050060 return -1;
61 }
62 m_nameList.push_back(name);
63 return 0;
64}
65
akmhoquefdbddb12014-05-02 18:35:19 -050066int32_t
akmhoque31d1d4b2014-05-05 22:08:14 -050067NamePrefixList::remove(const ndn::Name& name)
akmhoque53353462014-04-22 08:43:45 -050068{
akmhoque31d1d4b2014-05-05 22:08:14 -050069 std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
70 m_nameList.end(),
71 ndn::bind(&nameCompare, _1 ,
72 ndn::cref(name)));
akmhoque157b0a42014-05-13 00:26:37 -050073 if (it != m_nameList.end()) {
akmhoque53353462014-04-22 08:43:45 -050074 m_nameList.erase(it);
75 }
76 return -1;
77}
78
79void
akmhoquec8a10f72014-04-25 18:42:55 -050080NamePrefixList::sort()
akmhoque53353462014-04-22 08:43:45 -050081{
82 m_nameList.sort();
83}
84
85void
akmhoque674b0b12014-05-20 14:33:28 -050086NamePrefixList::writeLog()
87{
88 _LOG_DEBUG("-------Name Prefix List--------");
89 int i = 1;
90 for (std::list<ndn::Name>::iterator it = m_nameList.begin();
91 it != m_nameList.end(); it++) {
92 _LOG_DEBUG("Name " << i << " : " << (*it));
93 i++;
94 }
95}
96
akmhoque53353462014-04-22 08:43:45 -050097}//namespace nlsr