8#ifndef model_WeakPtrFactories_H_
9#define model_WeakPtrFactories_H_
21 template<
typename Derived,
typename ValueType,
typename CompareType=std::less<
typename ValueType::KeyType>>
22 struct WeakPtrFactory :
public std::map<typename ValueType::KeyType,const std::weak_ptr<ValueType>>
24 typedef typename ValueType::KeyType
KeyType;
54 template<
typename...Args>
59 const auto iter(this->find(
temp->key));
62 if(iter->second.expired())
69 assert(
false &&
"key already existing");
83 const auto iter(this->find(
key));
86 if(iter->second.expired())
92 return iter->second.lock();
110 throw std::runtime_error(
"WeakPtrFactory::getRef key not found");
116 template<
typename...Args>
119 const auto iter(this->find(
key));
120 if(iter!=this->
end())
122 if(iter->second.expired())
128 const auto temp(iter->second.lock()->clone(args...));
140 template<
typename Derived,
typename ValueType,
typename CompareType=std::less<
typename ValueType::KeyType>>
142 const std::weak_ptr<ValueType>,
152 const auto iter(this->find(
key));
153 if(iter!=this->
end())
155 if(iter->second.expired())
158 return this->emplace(
key,
SharedPtrType(
new ValueType(
static_cast<Derived*
>(
this),
key))).first->second.lock();
162 return iter->second.lock();
168 return this->emplace(
key,
SharedPtrType(
new ValueType(
static_cast<Derived*
>(
this),
key))).first->second.lock();
SharedPtrType getFromKey(const KeyType &key)
std::shared_ptr< GlidePlaneType > SharedPtrType
std::weak_ptr< GlidePlaneType > WeakPtrType
GlidePlaneType::KeyType KeyType
std::shared_ptr< LoopType > SharedPtrType
const ValueType & getRef(const KeyType &key) const
std::weak_ptr< LoopType > WeakPtrType
SharedPtrType create(const Args &...args)
SharedPtrType get(const KeyType &key) const
LoopType::KeyType KeyType
SharedPtrType clone(const KeyType &key, const Args &... args)