28 context_dependencies::context_dependencies(
const context_dependencies& cd) :
30 touched(static_cast<bool>(cd.touched)),
31 dependencies(cd.dependencies),
32 dependent(cd.dependent),
36 context_dependencies& context_dependencies::operator=(
const context_dependencies& cd)
39 touched =
static_cast<bool>(cd.touched);
40 dependencies = cd.dependencies;
41 dependent = cd.dependent;
45 void context_dependencies::sup_dependent_
46 (
const context_dependencies &cd)
const {
47 getfem::local_guard lock = locks_.get_lock();
49 iterator_list it1 = dependent.begin(), it2 = it1, ite = dependent.end();
50 for (; it1 != ite; ++it1)
51 { *it2 = *it1;
if (*it2 != &cd) ++it2;
else --s; }
55 void context_dependencies::sup_dependency_
56 (
const context_dependencies &cd)
const {
57 getfem::local_guard lock = locks_.get_lock();
59 iterator_list it1=dependencies.begin(), it2=it1, ite=dependencies.end();
60 for (; it1 != ite; ++it1)
61 { *it2 = *it1;
if (*it2 != &cd) ++it2;
else --s; }
62 dependencies.resize(s);
65 void context_dependencies::invalid_context()
const {
66 if (state != CONTEXT_INVALID)
68 iterator_list it = dependent.begin(), ite = dependent.end();
69 for (; it != ite; ++it) (*it)->invalid_context();
70 getfem::local_guard lock = locks_.get_lock();
71 state = CONTEXT_INVALID;
75 void context_dependencies::add_dependency(
const context_dependencies &cd) {
76 cd.context_check(); cd.touched =
false;
78 getfem::local_guard lock = locks_.get_lock();
79 iterator_list it = dependencies.begin(), ite = dependencies.end();
80 for (; it != ite; ++it)
if ((*it) == &cd)
return;
81 dependencies.push_back(&cd);
83 getfem::local_guard lock = cd.locks_.get_lock();
84 cd.dependent.push_back(
this);
87 bool context_dependencies::go_check()
const 89 if (state == CONTEXT_CHANGED)
91 iterator_list it = dependencies.begin(), ite = dependencies.end();
92 for (; it != ite; ++it)
94 (*it)->context_check();
95 (*it)->touched =
false;
97 getfem::local_guard lock = locks_.get_lock();
98 state = CONTEXT_NORMAL;
102 GMM_ASSERT1(state != CONTEXT_INVALID,
"Invalid context");
106 void context_dependencies::touch()
const 110 iterator_list it = dependent.begin(), ite = dependent.end();
111 for (; it != ite; ++it) (*it)->change_context();
116 void context_dependencies::clear_dependencies() {
117 iterator_list it = dependencies.begin(), ite = dependencies.end();
118 for (; it != ite; ++it) (*it)->sup_dependent_(*
this);
119 dependencies.clear();
122 context_dependencies::~context_dependencies() {
124 iterator_list it = dependencies.begin(), ite = dependencies.end();
125 for (; it != ite; ++it) (*it)->sup_dependent_(*
this);
126 it = dependent.begin(), ite = dependent.end();
127 for (; it != ite; ++it) (*it)->sup_dependency_(*
this);
virtual void update_from_context() const =0
this function has to be defined and should update the object when the context is modified.
size_t size_type
used as the common size type in the library
GEneric Tool for Finite Element Methods.
Deal with interdependencies of objects (getfem::context_dependencies).