blob: 3fc93997a8b059111a295abd73d1fa917a9842ea [file] [log] [blame]
Obaid793401d2014-02-27 19:13:49 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "rib.hpp"
8
9namespace ndn {
10namespace nrd {
11
12Rib::Rib()
13{
14}
15
Obaid3f48fe52014-02-27 21:45:23 -060016
Obaid793401d2014-02-27 19:13:49 -060017Rib::~Rib()
18{
19}
20
21static inline bool
22ribEntryNameCompare(const PrefixRegOptions& opt1, const PrefixRegOptions& opt2)
23{
24 return opt1.getName() == opt2.getName();
25}
26
Obaid3f48fe52014-02-27 21:45:23 -060027
Obaid793401d2014-02-27 19:13:49 -060028Rib::const_iterator
29Rib::find(const PrefixRegOptions& options) const
30{
31 RibTable::const_iterator it = std::find_if(m_rib.begin(), m_rib.end(),
32 bind(&ribEntryNameCompare, _1, options));
33 if (it == m_rib.end())
34 {
35 return end();
36 }
37 else
38 return it;
39}
40
Obaid3f48fe52014-02-27 21:45:23 -060041
Obaid793401d2014-02-27 19:13:49 -060042void
43Rib::insert(const PrefixRegOptions& options)
44{
45 RibTable::const_iterator it = std::find_if(m_rib.begin(), m_rib.end(),
46 bind(&ribEntryNameCompare, _1, options));
47 if (it == m_rib.end())
48 {
49 m_rib.push_front(options);
50 }
51}
52
Obaid3f48fe52014-02-27 21:45:23 -060053
Obaid793401d2014-02-27 19:13:49 -060054void
55Rib::erase(const PrefixRegOptions& options)
56{
57 RibTable::iterator it = std::find_if(m_rib.begin(), m_rib.end(),
58 bind(&ribEntryNameCompare, _1, options));
59 if (it != m_rib.end())
60 {
61 m_rib.erase(it);
62 }
63}
64
65} // namespace nrd
66} // namespace ndn