Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 1 | /* -*- 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 | |
| 9 | namespace ndn { |
| 10 | namespace nrd { |
| 11 | |
| 12 | Rib::Rib() |
| 13 | { |
| 14 | } |
| 15 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 16 | |
Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 17 | Rib::~Rib() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | static inline bool |
| 22 | ribEntryNameCompare(const PrefixRegOptions& opt1, const PrefixRegOptions& opt2) |
| 23 | { |
| 24 | return opt1.getName() == opt2.getName(); |
| 25 | } |
| 26 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 27 | |
Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 28 | Rib::const_iterator |
| 29 | Rib::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 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 41 | |
Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 42 | void |
| 43 | Rib::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 | |
Obaid | 3f48fe5 | 2014-02-27 21:45:23 -0600 | [diff] [blame] | 53 | |
Obaid | 793401d | 2014-02-27 19:13:49 -0600 | [diff] [blame] | 54 | void |
| 55 | Rib::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 |