Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
NetworkBase.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_NetworkBase_H_
9#define model_NetworkBase_H_
10
11#include <TerminalColors.h>
12#include <map>
13#include <memory>
14
15
16namespace model
17{
18
19 template<typename Derived,typename _KeyType>
21 {
22
23 typedef typename TypeTraits<Derived>::LoopNetworkType LoopNetworkType;
24 typedef std::map<_KeyType,const std::weak_ptr<Derived>> WeakPtrContainerType;
25 LoopNetworkType* const _network;
26 WeakPtrContainerType* const weakPtrContainer;
27
28 public:
29
30 typedef _KeyType KeyType;
31
32 const KeyType key;
35
36
37 /**********************************************************************/
38 NetworkBase(LoopNetworkType* const metwork_in,
39 WeakPtrContainerType* const wpc,
40 const KeyType& key_in) :
41 /* init */ _network(metwork_in)
42 /* init */,weakPtrContainer(wpc)
43 /* init */,key(key_in)
44 {
45 }
46
47 /**********************************************************************/
49 {
50 weakPtrContainer->erase(key);
51// size_t erased(weakPtrContainer->erase(key));
52// assert(erased==1 && "Could not erase key");
53 }
54
55
56 /**********************************************************************/
57 const LoopNetworkType& network() const
58 {
59 return *_network;
60 }
61
62 LoopNetworkType& network()
63 {
64 return *_network;
65 }
66
67 /**********************************************************************/
68 LoopNetworkType* p_network() const
69 {
70 return _network;
71 }
72
73 size_t networkID() const
74 {
75 return std::distance(weakPtrContainer->begin(),weakPtrContainer->find(key));
76 }
77
78
79// LoopNetworkType* const p_network() const
80// {
81// return _network;
82// }
83
84
85 };
86
87
88
89
90}
91#endif
NetworkBase(LoopNetworkType *const metwork_in, WeakPtrContainerType *const wpc, const KeyType &key_in)
Definition NetworkBase.h:38
size_t networkID() const
Definition NetworkBase.h:73
const LoopNetworkType & network() const
Definition NetworkBase.h:57
NetworkBase(const NetworkBase< LoopNetworkType, KeyType > &)=delete
NetworkBase & operator=(const NetworkBase< LoopNetworkType, KeyType > &other)=delete
LoopNetworkType & network()
Definition NetworkBase.h:62
LoopNetworkType * p_network() const
Definition NetworkBase.h:68