8 #ifndef IMPKERNEL_DECORATOR_H
9 #define IMPKERNEL_DECORATOR_H
11 #include <IMP/kernel/kernel_config.h>
18 #include "internal/utility.h"
23 IMPKERNEL_BEGIN_NAMESPACE
118 WeakPointer<Model> model_;
121 if (o < get_particle())
return -1;
122 else if (o > get_particle())
return 1;
137 return operator==(o);
140 return operator!=(o);
149 return operator>=(o);
152 return operator<=(o);
156 return (compare(o) == 0);
159 return (compare(o) != 0);
162 return (compare(o) <0);
165 return (compare(o) > 0);
168 return !(compare(o) < 0);
171 return !(compare(o) > 0);
174 bool operator==(
Particle* o)
const {
175 return (compare(o) == 0);
177 bool operator!=(
Particle* o)
const {
178 return (compare(o) != 0);
181 return (compare(o) <0);
184 return (compare(o) > 0);
186 bool operator>=(
Particle* o)
const {
187 return !(compare(o) < 0);
189 bool operator<=(
Particle* o)
const {
190 return !(compare(o) > 0);
203 if (!model_)
return nullptr;
206 "Particle " << pi_ <<
" is no longer part of the model.");
207 return model_->get_particle(pi_);
211 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
213 return get_particle();
216 return get_particle();
260 static bool particle_is_instance(
Particle *p);
274 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
275 typedef boost::false_type DecoratorHasTraits;
284 inline Decorator::Decorator(
Particle *p): model_(p->get_model()),
286 inline Decorator::Decorator() : pi_(-1) {}
288 #define IMP_CONSTRAINT_DECORATOR_DECL(Name) \
290 static ObjectKey get_constraint_key(); \
291 static void set_constraint(SingletonModifier* before, \
292 SingletonDerivativeModifier *after, \
295 Constraint *get_constraint() const { \
296 return dynamic_cast<Constraint*>(get_particle() \
297 ->get_value(get_constraint_key())); \
299 IMP_REQUIRE_SEMICOLON_CLASS(constraint)
302 #define IMP_CONSTRAINT_DECORATOR_DEF(Name) \
303 ObjectKey Name::get_constraint_key() { \
304 static ObjectKey ret(#Name " score state"); \
307 void Name::set_constraint(SingletonModifier* before, \
308 SingletonDerivativeModifier *after, \
310 if (!after && !before ) { \
311 if (p->has_attribute(get_constraint_key())) { \
312 p->get_model()->remove_score_state(dynamic_cast<ScoreState*> \
313 (p->get_value(get_constraint_key()))); \
314 p->remove_attribute(get_constraint_key()); \
317 Constraint *ss= new SingletonConstraint(before, \
319 std::string(#Name "updater for ")+p->get_name()); \
320 p->add_attribute(get_constraint_key(), ss); \
321 p->get_model()->add_score_state(ss); \
324 IMP_REQUIRE_SEMICOLON_NAMESPACE
336 #define IMP_CHECK_DECORATOR(Name, function) \
337 IMP::kernel::internal::ParticleCheck \
338 Name##pc(Name::particle_is_instance, function);
344 IMPKERNELEXPORT
void check_particle(
Particle*p);
347 IMPKERNEL_END_NAMESPACE
349 #if !defined(SWIG) && !defined IMP_DOXYGEN
350 IMPKERNEL_BEGIN_INTERNAL_NAMESPACE
352 return base::internal::unref(static_cast<Particle*>(d));
355 return base::internal::release(static_cast<Particle*>(d));
358 return base::internal::ref(static_cast<Particle*>(d));
361 IMPKERNEL_END_INTERNAL_NAMESPACE