IMP
2.3.1
The Integrative Modeling Platform
IMP Mainpage
Modules
Applications
Related Pages
Groups
Classes
Files
Examples
Indexes
File List
File Members
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-2014 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 IMP_OVERRIDE; \
31
virtual double get_strength(const IMP::domino::Subset &s, \
32
const IMP::domino::Subsets &excluded) const \
33
IMP_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
base::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
base::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 IMP_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 IMP_OVERRIDE { \
92
return get_assignments(IntRange(0, get_number_of_assignments())); \
93
}; \
94
virtual void add_assignments(const Assignments &as) IMP_OVERRIDE { \
95
for (unsigned int i = 0; i < as.size(); ++i) { \
96
Name::add_assignment(as[i]); \
97
} \
98
} \
99
virtual Ints get_particle_assignments(unsigned int index) const \
100
IMP_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 */