blob: 272177fc222150119ed3e47421e4692dd0e8e85c [file] [log] [blame]
Junxiao Shie5e2fce2014-02-10 20:01:53 -07001/* -*- 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_INFO_HOST_HPP
8#define NFD_TABLE_STRATEGY_INFO_HOST_HPP
9
10#include "fw/strategy-info.hpp"
11
12namespace nfd {
13
14/** \class StrategyInfoHost
15 * \brief base class for an entity onto which StrategyInfo may be placed
16 */
17class StrategyInfoHost
18{
19public:
20 template<typename T>
21 void
22 setStrategyInfo(shared_ptr<T> strategyInfo);
23
24 template<typename T>
25 shared_ptr<T>
26 getStrategyInfo();
27
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070028 template<typename T>
29 shared_ptr<T>
30 getOrCreateStrategyInfo();
31
32 template<typename T, typename T1>
33 shared_ptr<T>
34 getOrCreateStrategyInfo(T1& a1);
35
Junxiao Shie5e2fce2014-02-10 20:01:53 -070036 void
37 clearStrategyInfo();
38
39private:
40 shared_ptr<fw::StrategyInfo> m_strategyInfo;
41};
42
43
44template<typename T>
45void
46StrategyInfoHost::setStrategyInfo(shared_ptr<T> strategyInfo)
47{
48 m_strategyInfo = strategyInfo;
49}
50
51template<typename T>
52shared_ptr<T>
53StrategyInfoHost::getStrategyInfo()
54{
55 return static_pointer_cast<T, fw::StrategyInfo>(m_strategyInfo);
56}
57
Junxiao Shi0b5fbbb2014-02-20 15:54:03 -070058template<typename T>
59shared_ptr<T>
60StrategyInfoHost::getOrCreateStrategyInfo()
61{
62 shared_ptr<T> info = this->getStrategyInfo<T>();
63 if (!static_cast<bool>(info)) {
64 info = make_shared<T>();
65 this->setStrategyInfo(info);
66 }
67 return info;
68}
69
70template<typename T, typename T1>
71shared_ptr<T>
72StrategyInfoHost::getOrCreateStrategyInfo(T1& a1)
73{
74 shared_ptr<T> info = this->getStrategyInfo<T>();
75 if (!static_cast<bool>(info)) {
76 info = make_shared<T>(boost::ref(a1));
77 this->setStrategyInfo(info);
78 }
79 return info;
80}
81
Junxiao Shie5e2fce2014-02-10 20:01:53 -070082} // namespace nfd
83
84#endif // NFD_TABLE_STRATEGY_INFO_HOST_HPP