Itasca C++ Interface
Loading...
Searching...
No Matches
sharedpropertyblock.h
Go to the documentation of this file.
1#pragma once
2//
3
14#include "propertyblock.h"
15#include "shared/src/blockmemset.h"
16
17namespace models {
23 template <class T> class SharedPropertyBlock {
24 public:
29
31 const T *claim(const T &t);
33 void release(const T *t);
34
35 private:
36 BlockMemSet<T> properties_;
37 };
38
39 template <class T> const T *SharedPropertyBlock<T>::claim(const T &in) {
40 auto i = properties_.insert(in);
41 const T &t = *i.first;
42 t.incrementReference();
43 return &t;
44 }
45
46 template <class T> void SharedPropertyBlock<T>::release(const T *t) {
47 assert(t);
48 auto i = properties_.find(*t);
49 assert(i!=properties_.end());
50 const T &found = *i;
51 assert(&found==t);
52 if (!found.decrementReference())
53 properties_.erase(i);
54 }
55} // namespace models
56
58// EoF
This class allows zones to share model properties minimizing memery usage. Models currently using thi...
Definition sharedpropertyblock.h:23
const T * claim(const T &t)
Add property t to the property set and increase the property reference count (See SharedProperty).
Definition sharedpropertyblock.h:39
SharedPropertyBlock()
Constructor.
Definition sharedpropertyblock.h:26
void release(const T *t)
Decreases property t reference count. If the properrty reference reaches zero, removes property from ...
Definition sharedpropertyblock.h:46
virtual ~SharedPropertyBlock()
Destructor.
Definition sharedpropertyblock.h:28
The Constitutive Model interface library.
Definition conmodel.cpp:7
This class provides reference count for model properties.