9 #ifndef IMPKERNEL_SCOPED_H
10 #define IMPKERNEL_SCOPED_H
12 #include <IMP/kernel/kernel_config.h>
24 IMPKERNEL_BEGIN_NAMESPACE
37 m->add_score_state(ss);
39 if (ss_ && ss_->get_is_part_of_model()) {
42 ss_->get_model()->remove_score_state(ss_);
46 if (ss_) out <<
"(Scoped " <<ss_->get_name() <<
")";
47 else out <<
"(Unset scoped score state)";
49 bool get_is_set()
const {
return ss_;}
51 const SS* operator->()
const {
return ss_;}
52 const SS& operator*()
const {
return *ss_;}
53 SS* operator->() {
return ss_;}
54 SS& operator*() {
return *ss_;}
72 rs_->add_restraint(ss);
75 if (ss_ && ss_->get_is_part_of_model()) {
78 rs_->remove_restraint(ss_);
83 if (ss_) out <<
"(Scoped " <<ss_->get_name() <<
")";
84 else out <<
"(Unset scoped restraint)";
86 bool get_is_set()
const {
return ss_;}
88 const SS* operator->()
const {
return ss_;}
89 const SS& operator*()
const {
return *ss_;}
90 SS* operator->() {
return ss_;}
91 SS& operator*() {
return *ss_;}
106 if (rs_ && rs_->get_is_part_of_model()) {
108 << ss_->get_name() <<
" to "
109 << rs_->get_name() << std::endl);
112 rs_->add_restraint(ss_);
117 << ss_->get_name() << std::endl);
123 rs_->remove_restraint(ss);
125 << ss_->get_name() <<
" from "
126 << rs_->get_name() << std::endl);
135 if (ss_) out <<
"(Scoped removal of " <<ss_->get_name() <<
")";
136 else out <<
"(Unset scoped restraint)";
138 bool get_is_set()
const {
return ss_;}
140 const SS* operator->()
const {
return ss_;}
141 const SS& operator*()
const {
return *ss_;}
142 SS* operator->() {
return ss_;}
143 SS& operator*() {
return *ss_;}
159 << ss_->get_name() <<
" to "
160 << rs_->get_name() << std::endl);
163 rs_->add_score_state(ss_);
171 rs_->remove_score_state(ss);
173 << ss_->get_name() <<
" from "
174 << rs_->get_name() << std::endl);
182 if (ss_) out <<
"(Scoped removal of " <<ss_->get_name() <<
")";
183 else out <<
"(Unset scoped restraint)";
185 bool get_is_set()
const {
return ss_;}
187 const SS* operator->()
const {
return ss_;}
188 const SS& operator*()
const {
return *ss_;}
189 SS* operator->() {
return ss_;}
190 SS& operator*() {
return *ss_;}
206 template <
class Key,
class Value>
213 Key key,
const Value &value),
214 {pi_=base::get_invalid_index<ParticleIndexTag>();},
219 m_->add_cache_attribute(key_, pi_, value);
222 if (pi_ !=base::get_invalid_index<ParticleIndexTag>()) {
223 m_->remove_attribute(key_, pi_);
232 template <
class Key,
class Value>
240 Key key,
const Value &value),
241 {pi_=base::get_invalid_index<ParticleIndexTag>();},
246 old_= m_->get_attribute(key_, pi_);
247 m_->set_attribute(key_, pi_, value);
250 if (pi_ != base::get_invalid_index<ParticleIndexTag>()) {
251 m_->set_attribute(key_, pi_, old_);
259 IMPKERNEL_END_NAMESPACE