IMP  2.0.0
The Integrative Modeling Platform
domino_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/domino_macros.h \brief Various important macros
3  * for implementing decorators.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPDOMINO_MACROS_H
10 #define IMPDOMINO_MACROS_H
11 
12 /** This macro declares
13  - IMP::domino::ParticleStates::get_number_of_states()
14  - IMP::domino::ParticleStates::load_state()
15  and defines
16  - IMP::domino::after_set_current_particle() to be empty
17 */
18 #define IMP_PARTICLE_STATES(Name) \
19  public: \
20  IMP_IMPLEMENT(virtual unsigned int get_number_of_particle_states() const); \
21  IMP_IMPLEMENT(virtual void load_particle_state(unsigned int, \
22  Particle*) const); \
23  IMP_OBJECT(Name)
24 
25 
26 /** This macro declares
27  - IMP::domino::AssignmentTable::get_assignments()
28 */
29 #define IMP_ASSIGNMENTS_TABLE(Name) \
30  public: \
31  IMP_IMPLEMENT(virtual void \
32  load_assignments(const IMP::domino::Subset&s, \
33  AssignmentContainer *ac) const); \
34  IMP_OBJECT(Name)
35 
36 
37 
38 
39 /** This macro declares
40  - IMP::domino::SubsetFilterTable::get_subset_filter()
41  - IMP::domino::SubsetFilterTable::get_strength()
42  in addition to the IMP_OBJECT() methods.
43 */
44 #define IMP_SUBSET_FILTER_TABLE(Name) \
45  public: \
46  IMP_IMPLEMENT(virtual IMP::domino::SubsetFilter* \
47  get_subset_filter(const IMP::domino::Subset&s, \
48  const IMP::domino::Subsets &excluded) const); \
49  IMP_IMPLEMENT(virtual double get_strength(const IMP::domino::Subset&s, \
50  const IMP::domino::Subsets &excluded) const); \
51  IMP_OBJECT(Name)
52 
53 /** This macro defines a class NameSubsetFilterTable from a method
54  which is applied to disjoint sets. The code should assume there is
55  a Assignment state and an Ints members which ordered indices into
56  the Assignment for the current set.
57 */
58 #define IMP_DISJOINT_SUBSET_FILTER_TABLE_DECL(Name) \
59  class IMPDOMINOEXPORT Name##SubsetFilterTable: \
60  public DisjointSetsSubsetFilterTable { \
61  typedef DisjointSetsSubsetFilterTable P; \
62  public: \
63  Name##SubsetFilterTable(IMP::domino::ParticleStatesTable *pst): \
64  P(pst, std::string(#Name)+std::string(" %1%")){} \
65  Name##SubsetFilterTable(): P(std::string(#Name) \
66  +std::string(" %1%")){} \
67  IMP_SUBSET_FILTER_TABLE(Name##SubsetFilterTable); \
68  }; \
69  IMP_OBJECTS(Name##SubsetFilterTable, Name##SubsetFilterTables)
70 
71 
72 #define IMP_DISJOINT_SUBSET_FILTER_TABLE_DEF(Name, filter, strength, \
73  next) \
74  struct Name##Filter { \
75  bool operator()(const Assignment &state, \
76  const Ints &members) const { \
77  filter; \
78  } \
79  }; \
80  struct Name##Strength { \
81  double operator()(const Subset &s, \
82  const Subsets &excluded, \
83  const Ints &members) const { \
84  strength; \
85  } \
86  }; \
87  struct Name##Next { \
88  int operator()(int pos, const Assignment& state, \
89  const Ints &set) const { \
90  next; \
91  } \
92  }; \
93  void Name##SubsetFilterTable::do_show(std::ostream &) const { \
94  } \
95  IMP::domino::SubsetFilter* Name##SubsetFilterTable:: \
96  get_subset_filter(const IMP::domino::Subset &s, \
97  const IMP::domino::Subsets &excluded) const{ \
98  IMP_OBJECT_LOG; \
99  set_was_used(true); \
100  base::Vector<Ints> all; \
101  Ints used; \
102  get_indexes(s, excluded, all, 1, used); \
103  return get_disjoint_set_filter<Name##Filter, Name##Next>(#Name, s, \
104  get_log_level(), \
105  all, used); \
106  } \
107  double \
108  Name##SubsetFilterTable::get_strength(const IMP::domino::Subset &s, \
109  const IMP::domino::Subsets &excluded) const{ \
110  IMP_OBJECT_LOG; \
111  set_was_used(true); \
112  base::Vector<Ints> all; \
113  Ints used; \
114  get_indexes(s, excluded, all, 0, used); \
115  return get_disjoint_set_strength<Name##Strength>(s, \
116  excluded, \
117  all,used); \
118  }
119 
120 
121 
122 /** This macro declares
123  - IMP::domino::SubsetFilter::get_is_ok()
124 */
125 #define IMP_SUBSET_FILTER(Name) \
126  public: \
127  IMP_IMPLEMENT(virtual bool get_is_ok(const IMP::domino::Assignment& \
128  assignment) const); \
129  IMP_OBJECT(Name)
130 
131 
132 /** This macro declares
133  - IMP::domino::DiscreteSampler::do_get_sample_assignments()
134 */
135 #define IMP_DISCRETE_SAMPLER(Name) \
136  public: \
137  IMP_IMPLEMENT(Assignments do_get_sample_assignments(const\
138  IMP::domino::Subset\
139  &known) \
140  const); \
141  IMP_OBJECT(Name)
142 
143 
144 /** This macro declares:
145  - IMP::domino::SubsetGraphTable::get_subset_graph()
146  - IMP::Object methods
147  */
148 #define IMP_SUBSET_GRAPH_TABLE(Name) \
149  public: \
150  IMP_IMPLEMENT(SubsetGraph get_subset_graph(IMP::domino::ParticleStatesTable\
151  *pst) const); \
152 IMP_OBJECT(Name)
153 
154 
155 #define IMP_ASSIGNMENT_CONTAINER_BASE(Name) \
156  public: \
157  IMP_IMPLEMENT(virtual unsigned int get_number_of_assignments() const); \
158  IMP_IMPLEMENT(virtual Assignment get_assignment(unsigned int i) const); \
159  IMP_IMPLEMENT_INLINE(virtual Assignments get_assignments(IntRange r) const,\
160  { \
161  Assignments ret(r.second-r.first); \
162  for (unsigned int i=0; i != ret.size(); ++i) { \
163  ret[i]= Name::get_assignment(r.first+i); \
164  } \
165  return ret; \
166  }); \
167  IMP_IMPLEMENT_INLINE(virtual Assignments get_assignments() const, { \
168  return get_assignments(IntRange(0, get_number_of_assignments())); \
169  }); \
170  IMP_IMPLEMENT(virtual void add_assignment(const Assignment& a)); \
171  IMP_IMPLEMENT_INLINE(virtual void add_assignments(const Assignments &as), { \
172  for (unsigned int i=0; i< as.size(); ++i) { \
173  Name::add_assignment(as[i]); \
174  } \
175  }); \
176  IMP_IMPLEMENT_INLINE(virtual Ints get_particle_assignments(unsigned\
177  int index) const,\
178  { \
179  Ints ret(Name::get_number_of_assignments()); \
180  for (unsigned int i=0; i< Name::get_number_of_assignments(); \
181  ++i) { \
182  ret[i]= get_assignment(i)[index]; \
183  } \
184  return ret; \
185  })
186 
187 
188 /** This macro declares:
189  - AssignmentsContainer::get_number_of_assignments()
190  - AssignmentsContainer::get_assignment()
191  - AssignmentsContainer::add_assignment()
192  and defines:
193  - AssignmentsContainer::get_assignments(IntRange)
194  - AssignmentsContainer::add_assignments()
195  - AssignmentsContainer::get_assignments(unsigned int)
196  in addition to the IMP_OBJECT() declarations and definitions.
197 */
198 #define IMP_ASSIGNMENT_CONTAINER(Name) \
199  IMP_ASSIGNMENT_CONTAINER_BASE(Name); \
200  IMP_OBJECT(Name)
201 
202 
203 #define IMP_ASSIGNMENT_CONTAINER_INLINE(Name, show, dest) \
204  IMP_ASSIGNMENT_CONTAINER_BASE(Name); \
205  IMP_OBJECT_INLINE(Name, show, dest)
206 
207 #endif /* IMPDOMINO_MACROS_H */