IMP logo
IMP Reference Guide  2.20.2
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-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPDOMINO_MACROS_H
10 #define IMPDOMINO_MACROS_H
11 
12 #include <IMP/domino/domino_config.h>
13 
14 /** This macro defines a class NameSubsetFilterTable from a method
15  which is applied to disjoint sets. The code should assume there is
16  a Assignment state and an Ints members which ordered indices into
17  the Assignment for the current set.
18 */
19 #define IMP_DISJOINT_SUBSET_FILTER_TABLE_DECL(Name) \
20  class IMPDOMINOEXPORT Name##SubsetFilterTable \
21  : public DisjointSetsSubsetFilterTable { \
22  typedef DisjointSetsSubsetFilterTable P; \
23  \
24  public: \
25  Name##SubsetFilterTable(IMP::domino::ParticleStatesTable *pst) \
26  : P(pst, std::string(#Name) + std::string(" %1%")) {} \
27  Name##SubsetFilterTable() : P(std::string(#Name) + std::string(" %1%")) {} \
28  virtual IMP::domino::SubsetFilter *get_subset_filter( \
29  const IMP::domino::Subset &s, \
30  const IMP::domino::Subsets &excluded) const override; \
31  virtual double get_strength(const IMP::domino::Subset &s, \
32  const IMP::domino::Subsets &excluded) const \
33  override; \
34  IMP_OBJECT_METHODS(Name##SubsetFilterTable); \
35  }; \
36  IMP_OBJECTS(Name##SubsetFilterTable, Name##SubsetFilterTables)
37 
38 #define IMP_DISJOINT_SUBSET_FILTER_TABLE_DEF(Name, filter, strength, next) \
39  struct Name##Filter { \
40  bool operator()(const Assignment &state, const Ints &members) const { \
41  filter; \
42  } \
43  }; \
44  struct Name##Strength { \
45  double operator()(const Subset &s, const Subsets &excluded, \
46  const Ints &members) const { \
47  strength; \
48  } \
49  }; \
50  struct Name##Next { \
51  int operator()(int pos, const Assignment &state, const Ints &set) const { \
52  next; \
53  } \
54  }; \
55  IMP::domino::SubsetFilter *Name##SubsetFilterTable::get_subset_filter( \
56  const IMP::domino::Subset &s, \
57  const IMP::domino::Subsets &excluded) const { \
58  IMP_OBJECT_LOG; \
59  set_was_used(true); \
60  Vector<Ints> all; \
61  Ints used; \
62  get_indexes(s, excluded, all, 1, used); \
63  return get_disjoint_set_filter<Name##Filter, Name##Next>( \
64  #Name, s, get_log_level(), all, used); \
65  } \
66  double Name##SubsetFilterTable::get_strength( \
67  const IMP::domino::Subset &s, \
68  const IMP::domino::Subsets &excluded) const { \
69  IMP_OBJECT_LOG; \
70  set_was_used(true); \
71  Vector<Ints> all; \
72  Ints used; \
73  get_indexes(s, excluded, all, 0, used); \
74  return get_disjoint_set_strength<Name##Strength>(s, excluded, all, used); \
75  }
76 
77 /** This macro defines:
78  - AssignmentsContainer::get_assignments(IntRange)
79  - AssignmentsContainer::add_assignments()
80  - AssignmentsContainer::get_assignments(unsigned int)
81 */
82 #define IMP_ASSIGNMENT_CONTAINER_METHODS(Name) \
83  public: \
84  virtual Assignments get_assignments(IntRange r) const override { \
85  Assignments ret(r.second - r.first); \
86  for (unsigned int i = 0; i != ret.size(); ++i) { \
87  ret[i] = Name::get_assignment(r.first + i); \
88  } \
89  return ret; \
90  } \
91  virtual Assignments get_assignments() const override { \
92  return get_assignments(IntRange(0, get_number_of_assignments())); \
93  }; \
94  virtual void add_assignments(const Assignments &asgn) override { \
95  for (unsigned int i = 0; i < asgn.size(); ++i) { \
96  Name::add_assignment(asgn[i]); \
97  } \
98  } \
99  virtual Ints get_particle_assignments(unsigned int index) const \
100  override { \
101  Ints ret(Name::get_number_of_assignments()); \
102  for (unsigned int i = 0; i < Name::get_number_of_assignments(); ++i) { \
103  ret[i] = get_assignment(i)[index]; \
104  } \
105  return ret; \
106  }
107 
108 #endif /* IMPDOMINO_MACROS_H */