strategy-choice.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
27 #define NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
28 
30 #include "name-tree.hpp"
31 
32 #include <boost/range/adaptor/transformed.hpp>
33 
34 namespace nfd {
35 
36 class Forwarder;
37 
38 namespace strategy_choice {
39 
51 class StrategyChoice : noncopyable
52 {
53 public:
54  explicit
55  StrategyChoice(Forwarder& forwarder);
56 
57  size_t
58  size() const
59  {
60  return m_nItems;
61  }
62 
67  void
68  setDefaultStrategy(const Name& strategyName);
69 
70 public: // Strategy Choice table
72  {
73  public:
74  explicit
75  operator bool() const
76  {
77  return m_status == OK;
78  }
79 
80  bool
81  isRegistered() const
82  {
83  return m_status != NOT_REGISTERED;
84  }
85 
86  private:
87  enum Status {
88  OK,
89  NOT_REGISTERED,
90  EXCEPTION
91  };
92 
93  // implicitly constructible from Status
94  InsertResult(Status status, const std::string& exceptionMessage = "");
95 
96  private:
97  Status m_status;
98  std::string m_exceptionMessage;
99 
100  friend class StrategyChoice;
101  friend std::ostream& operator<<(std::ostream&, const InsertResult&);
102  };
103 
111  insert(const Name& prefix, const Name& strategyName);
112 
117  void
118  erase(const Name& prefix);
119 
123  std::pair<bool, Name>
124  get(const Name& prefix) const;
125 
126 public: // effective strategy
129  fw::Strategy&
130  findEffectiveStrategy(const Name& prefix) const;
131 
136  fw::Strategy&
137  findEffectiveStrategy(const pit::Entry& pitEntry) const;
138 
143  fw::Strategy&
144  findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
145 
146 public: // enumeration
147  typedef boost::transformed_range<name_tree::GetTableEntry<Entry>, const name_tree::Range> Range;
148  typedef boost::range_iterator<Range>::type const_iterator;
149 
155  const_iterator
156  begin() const
157  {
158  return this->getRange().begin();
159  }
160 
164  const_iterator
165  end() const
166  {
167  return this->getRange().end();
168  }
169 
170 private:
171  void
172  changeStrategy(Entry& entry,
173  fw::Strategy& oldStrategy,
174  fw::Strategy& newStrategy);
175 
178  template<typename K>
179  fw::Strategy&
180  findEffectiveStrategyImpl(const K& key) const;
181 
182  Range
183  getRange() const;
184 
185 private:
186  Forwarder& m_forwarder;
187  NameTree& m_nameTree;
188  size_t m_nItems;
189 };
190 
191 std::ostream&
192 operator<<(std::ostream& os, const StrategyChoice::InsertResult& res);
193 
194 } // namespace strategy_choice
195 
196 using strategy_choice::StrategyChoice;
197 
198 } // namespace nfd
199 
200 #endif // NFD_DAEMON_TABLE_STRATEGY_CHOICE_HPP
main class of NFD
Definition: forwarder.hpp:52
represents a Measurements entry
represents the Strategy Choice table
InsertResult insert(const Name &prefix, const Name &strategyName)
set strategy of prefix to be strategyName
friend std::ostream & operator<<(std::ostream &, const InsertResult &)
boost::transformed_range< name_tree::GetTableEntry< Entry >, const name_tree::Range > Range
std::ostream & operator<<(std::ostream &os, const StrategyChoice::InsertResult &res)
boost::range_iterator< Range >::type const_iterator
an Interest table entry
Definition: pit-entry.hpp:57
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
void setDefaultStrategy(const Name &strategyName)
set the default strategy
represents a Strategy Choice entry
represents a forwarding strategy
Definition: strategy.hpp:37
boost::iterator_range< Iterator > Range
a Forward Range of name tree entries
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
get effective strategy for prefix
void erase(const Name &prefix)
make prefix to inherit strategy from its parent