/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014-2017,  The University of Memphis,
 *                           Regents of the University of California,
 *                           Arizona Board of Regents.
 *
 * This file is part of NLSR (Named-data Link State Routing).
 * See AUTHORS.md for complete list of NLSR authors and contributors.
 *
 * NLSR is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NLSR, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 **/

#include <iostream>
#include <algorithm>

#include <ndn-cxx/common.hpp>

#include "common.hpp"
#include "name-prefix-list.hpp"
#include "logger.hpp"

namespace nlsr {

INIT_LOGGER("NamePrefixList");

using namespace std;

NamePrefixList::NamePrefixList()
{
}

NamePrefixList::~NamePrefixList()
{
}

static bool
nameCompare(const ndn::Name& name1, const ndn::Name& name2)
{
  return name1 == name2;
}

bool
NamePrefixList::insert(const ndn::Name& name)
{
  std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
                                                   m_nameList.end(),
                                                   std::bind(&nameCompare, _1 ,
                                                   std::cref(name)));
  if (it != m_nameList.end()) {
    return false;
  }
  m_nameList.push_back(name);
  return true;
}

bool
NamePrefixList::remove(const ndn::Name& name)
{
  std::list<ndn::Name>::iterator it = std::find_if(m_nameList.begin(),
                                                   m_nameList.end(),
                                                   std::bind(&nameCompare, _1 ,
                                                   std::cref(name)));
  if (it != m_nameList.end()) {
    m_nameList.erase(it);
    return true;
  }

  return false;
}

bool
NamePrefixList::operator==(const NamePrefixList& other) const
{
  return m_nameList == other.getNameList();
}

void
NamePrefixList::sort()
{
  m_nameList.sort();
}

std::ostream&
operator<<(std::ostream& os, const NamePrefixList& list) {
  os << "Name prefix list: {\n";
  for (const auto& name : list.getNameList()) {
    os << name << "\n";
  }
  os << "}" << std::endl;
  return os;
}

} // namespace nlsr
