Junxiao Shi | bb5105f | 2014-03-03 12:06:45 -0700 | [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 | #ifndef NFD_TABLE_STRATEGY_CHOICE_HPP |
| 8 | #define NFD_TABLE_STRATEGY_CHOICE_HPP |
| 9 | |
| 10 | #include "strategy-choice-entry.hpp" |
| 11 | #include "name-tree.hpp" |
| 12 | |
| 13 | namespace nfd { |
| 14 | |
| 15 | class StrategyChoice : noncopyable |
| 16 | { |
| 17 | public: |
| 18 | StrategyChoice(NameTree& nameTree, shared_ptr<fw::Strategy> defaultStrategy); |
| 19 | |
| 20 | public: // available Strategy types |
| 21 | /** \return true if strategy is installed |
| 22 | */ |
| 23 | bool |
| 24 | hasStrategy(const Name& strategyName) const; |
| 25 | |
| 26 | /** \brief install a strategy |
| 27 | * \return true if installed; false if not installed due to duplicate strategyName |
| 28 | */ |
| 29 | bool |
| 30 | install(shared_ptr<fw::Strategy> strategy); |
| 31 | |
| 32 | public: // Strategy Choice table |
| 33 | /** \brief set strategy of prefix to be strategyName |
| 34 | * \param strategyName the strategy to be used, must be installed |
| 35 | * \return true on success |
| 36 | */ |
| 37 | bool |
| 38 | insert(const Name& prefix, const Name& strategyName); |
| 39 | |
| 40 | /** \brief make prefix to inherit strategy from its parent |
| 41 | * |
| 42 | * not allowed for root prefix (ndn:/) |
| 43 | */ |
| 44 | void |
| 45 | erase(const Name& prefix); |
| 46 | |
| 47 | /** \brief get strategy Name of prefix |
| 48 | * \return strategyName at exact match, or nullptr |
| 49 | */ |
| 50 | shared_ptr<const Name> |
| 51 | get(const Name& prefix) const; |
| 52 | |
| 53 | public: // effect strategy |
| 54 | /// get effective strategy for prefix |
| 55 | fw::Strategy& |
| 56 | findEffectiveStrategy(const Name& prefix) const; |
| 57 | |
| 58 | /// get effective strategy for pitEntry |
| 59 | fw::Strategy& |
| 60 | findEffectiveStrategy(const pit::Entry& pitEntry) const; |
| 61 | |
| 62 | /// number of entries stored |
| 63 | size_t |
| 64 | size() const; |
| 65 | |
| 66 | private: |
| 67 | shared_ptr<fw::Strategy> |
| 68 | getStrategy(const Name& strategyName); |
| 69 | |
| 70 | void |
| 71 | setDefaultStrategy(shared_ptr<fw::Strategy> strategy); |
| 72 | |
| 73 | void |
| 74 | changeStrategy(shared_ptr<strategy_choice::Entry> entry, |
| 75 | shared_ptr<fw::Strategy> oldStrategy, |
| 76 | shared_ptr<fw::Strategy> newStrategy); |
| 77 | |
| 78 | private: |
| 79 | NameTree& m_nameTree; |
| 80 | size_t m_nItems; |
| 81 | |
| 82 | typedef std::map<Name, shared_ptr<fw::Strategy> > StrategyInstanceTable; |
| 83 | StrategyInstanceTable m_strategyInstances; |
| 84 | }; |
| 85 | |
| 86 | inline size_t |
| 87 | StrategyChoice::size() const |
| 88 | { |
| 89 | return m_nItems; |
| 90 | } |
| 91 | |
| 92 | } // namespace nfd |
| 93 | |
| 94 | #endif // NFD_TABLE_STRATEGY_CHOICE_HPP |