IMP  2.3.1
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-2014 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 
14 #include <IMP/Decorator.h>
15 #include <IMP/algebra/Vector3D.h>
17 #include <vector>
18 #include <limits>
19 
20 IMPCORE_BEGIN_NAMESPACE
21 
22 // TODO: why this number? how can we tell it's unique
23 #define IMP_PARTICLE_TYPE_INDEX 34897493
24 
25 /** A kernel::ParticleType is an IMP::kernel::Key object for identifying types
26  of
27  particles by strings. The kernel::ParticleType key is used to type particles
28  within
29  the Typed decorator */
30 typedef Key<IMP_PARTICLE_TYPE_INDEX, true> ParticleType;
32 
33 //! A decorator for classifying particles in your system.
34 /** This decorator
35  */
36 class IMPCOREEXPORT Typed : public Decorator {
37  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi,
38  ParticleType t) {
39  m->add_attribute(get_type_key(), pi, t.get_index());
40  }
41 
42  public:
43  static IntKey get_type_key();
44 
47 
48  static bool get_is_setup(kernel::Model *m, kernel::ParticleIndex pi) {
49  return m->get_has_attribute(get_type_key(), pi);
50  }
51 
52  ParticleType get_type() const {
53  return ParticleType(
54  get_model()->get_attribute(get_type_key(), get_particle_index()));
55  }
56 };
57 
58 IMP_DECORATORS(Typed, Typeds, kernel::ParticlesTemp);
59 
60 IMPCORE_END_NAMESPACE
61 
62 #endif /* IMPCORE_TYPED_H */
Import IMP/kernel/Decorator.h in the namespace.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
A base class for Keys.
Definition: kernel/Key.h:46
#define IMP_DECORATOR_METHODS(Name, Parent)
Model * get_model() const
Returns the Model containing the particle.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
Definition: value_macros.h:23
Import IMP/kernel/decorator_macros.h in the namespace.
Simple 3D transformation class.
Key< 34897493, true > ParticleType
Definition: Typed.h:30
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
Simple 3D vector class.
A decorator for classifying particles in your system.
Definition: Typed.h:36
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73