IMP  2.0.0
The Integrative Modeling Platform
Typed.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/Typed.h \brief A particle with a user-defined type.
3  *
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPCORE_TYPED_H
9 #define IMPCORE_TYPED_H
10 
11 #include <IMP/core/core_config.h>
12 #include <IMP/decorator_macros.h>
13 #include <IMP/key_macros.h>
14 
15 #include <IMP/Decorator.h>
16 #include <IMP/algebra/Vector3D.h>
18 #include <vector>
19 #include <limits>
20 
21 IMPCORE_BEGIN_NAMESPACE
22 
23 // TODO: why this number? how can we tell it's unique
24 #define IMP_PARTICLE_TYPE_INDEX 34897493
25 
26 /** A ParticleType is a Key object for identifying types of particles
27  by strings. The PartickeType key is use to type particles within
28  the Typed decorator */
29 IMP_DECLARE_KEY_TYPE(ParticleType, IMP_PARTICLE_TYPE_INDEX);
30 
31 
32 //! A decorator for classifying particles in your system.
33 /** This decorator
34  */
35 class IMPCOREEXPORT Typed: public Decorator
36 {
37  public:
38 
39  static IntKey get_type_key();
40 
42 
43  /** Create a decorator with the passed coordinates. */
45  p->add_attribute(get_type_key(),t.get_index());
46  return Typed(p);
47  }
48 
49  static bool particle_is_instance(Particle *p) {
50  return p->has_attribute(get_type_key());
51  }
52 
53  static bool particle_is_instance(Model *m, ParticleIndex pi) {
54  return m->get_has_attribute(get_type_key(), pi);
55  }
56 
57  ParticleType get_type() const {
58  return ParticleType(get_particle()->get_value(get_type_key()));
59  }
60 };
61 
62 IMP_DECORATORS(Typed,Typeds, ParticlesTemp);
63 
64 
65 IMPCORE_END_NAMESPACE
66 
67 
68 
69 #endif /* IMPCORE_TYPED_H */