85 lines
1.7 KiB
C++
85 lines
1.7 KiB
C++
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
/**
|
|
* Copyright (C) 2014 Named Data Networking Project
|
|
* See COPYING for copyright and distribution information.
|
|
*/
|
|
|
|
#ifndef NFD_TABLE_STRATEGY_INFO_HOST_HPP
|
|
#define NFD_TABLE_STRATEGY_INFO_HOST_HPP
|
|
|
|
#include "fw/strategy-info.hpp"
|
|
|
|
namespace nfd {
|
|
|
|
/** \class StrategyInfoHost
|
|
* \brief base class for an entity onto which StrategyInfo may be placed
|
|
*/
|
|
class StrategyInfoHost
|
|
{
|
|
public:
|
|
template<typename T>
|
|
void
|
|
setStrategyInfo(shared_ptr<T> strategyInfo);
|
|
|
|
template<typename T>
|
|
shared_ptr<T>
|
|
getStrategyInfo();
|
|
|
|
template<typename T>
|
|
shared_ptr<T>
|
|
getOrCreateStrategyInfo();
|
|
|
|
template<typename T, typename T1>
|
|
shared_ptr<T>
|
|
getOrCreateStrategyInfo(T1& a1);
|
|
|
|
void
|
|
clearStrategyInfo();
|
|
|
|
private:
|
|
shared_ptr<fw::StrategyInfo> m_strategyInfo;
|
|
};
|
|
|
|
|
|
template<typename T>
|
|
void
|
|
StrategyInfoHost::setStrategyInfo(shared_ptr<T> strategyInfo)
|
|
{
|
|
m_strategyInfo = strategyInfo;
|
|
}
|
|
|
|
template<typename T>
|
|
shared_ptr<T>
|
|
StrategyInfoHost::getStrategyInfo()
|
|
{
|
|
return static_pointer_cast<T, fw::StrategyInfo>(m_strategyInfo);
|
|
}
|
|
|
|
template<typename T>
|
|
shared_ptr<T>
|
|
StrategyInfoHost::getOrCreateStrategyInfo()
|
|
{
|
|
shared_ptr<T> info = this->getStrategyInfo<T>();
|
|
if (!static_cast<bool>(info)) {
|
|
info = make_shared<T>();
|
|
this->setStrategyInfo(info);
|
|
}
|
|
return info;
|
|
}
|
|
|
|
template<typename T, typename T1>
|
|
shared_ptr<T>
|
|
StrategyInfoHost::getOrCreateStrategyInfo(T1& a1)
|
|
{
|
|
shared_ptr<T> info = this->getStrategyInfo<T>();
|
|
if (!static_cast<bool>(info)) {
|
|
info = make_shared<T>(boost::ref(a1));
|
|
this->setStrategyInfo(info);
|
|
}
|
|
return info;
|
|
}
|
|
|
|
} // namespace nfd
|
|
|
|
#endif // NFD_TABLE_STRATEGY_INFO_HOST_HPP
|