Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
SharedPtrFactories.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_SharedPtrFactories_h_
9#define model_SharedPtrFactories_h_
10
11#include <map>
12#include <memory>
13
14#include <CRTP.h>
15
16namespace model
17{
18
19
20 template<typename Derived,typename ValueType>
21 struct KeyConstructableSharedPtrFactory : public CRTP<Derived>
22 /* */,public std::map<typename ValueType::KeyType,
23 /* */ const std::shared_ptr<ValueType>,
24 /* */ typename ValueType::CompareType>
25 {
26
27 typedef typename ValueType::KeyType KeyType;
28 typedef std::shared_ptr<ValueType> SharedPtrType;
29 typedef std::map<KeyType,const SharedPtrType> MapType;
30 typedef typename MapType::size_type SizeType;
31
32 /**************************************************************************/
34 {
35 const auto iter(this->find(key));
36 if(iter!=this->end())
37 {// key found
38 return iter->second;
39 }
40 else
41 {
42 return this->emplace(key,new ValueType(this->derived(),key)).first->second;
43 }
44
45 }
46
47
48 // /**************************************************************************/
49 // SharedPtrType get(const KeyType& key)
50 // {
51 // return MapType::emplace(std::piecewise_construct,
52 // std::forward_as_tuple(key),
53 // std::forward_as_tuple(this->derived(),key)
54 // ).first->second;
55 // }
56
57 // /**************************************************************************/
58 // SizeType erase(const SharedPtrType& shared) FINISH THIS PART
59 // {
60 // const auto iter(MapType::find(shared->key()));
61 // if(iter!=MapType::end())
62 // {
63 // if(iter->second->use_count()<=2)
64 // {// current map
65 //
66 // }
67 // }
68 // else
69 // {
70 // return 0;
71 // }
72 // }
73
74 };
75
76}
77#endif
Derived & derived()
A reference to the derived object.
Definition CRTP.h:24
CRTP()
The default constructor.
Definition CRTP.h:37
std::map< KeyType, const SharedPtrType > MapType
std::shared_ptr< ValueType > SharedPtrType
SharedPtrType get(const KeyType &key)
int end[2]
newbad key