IMP  2.3.0
The Integrative Modeling Platform
kernel/triplet_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/triplet_macros.h
3  * \brief Macros for various classes.
4  *
5  * This file is generated by a script (core/tools/make-containers).
6  * Do not edit directly.
7  *
8  * Copyright 2007-2014 IMP Inventors. All rights reserved.
9  */
10 
11 #ifndef IMPKERNEL_TRIPLET_MACROS_H
12 #define IMPKERNEL_TRIPLET_MACROS_H
13 
14 #include "internal/TupleRestraint.h"
15 #include "internal/functors.h"
16 #include "container_macros.h"
17 #include <IMP/base/object_macros.h>
18 #include <algorithm>
19 
20 /** Define
21  - IMP::kernel::TripletScore::evaluate_indexes()
22  - IMP::kernel::TripletScore::evaluate_if_good_indexes()
23  */
24 #define IMP_TRIPLET_SCORE_METHODS(Name) \
25  double evaluate_indexes(kernel::Model *m, const kernel::ParticleIndexTriplets &p, \
26  DerivativeAccumulator *da, unsigned int lower_bound, \
27  unsigned int upper_bound) const IMP_FINAL { \
28  double ret = 0; \
29  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
30  ret += evaluate_index(m, p[i], da); \
31  } \
32  return ret; \
33  } \
34  double evaluate_if_good_indexes( \
35  kernel::Model *m, const kernel::ParticleIndexTriplets &p, DerivativeAccumulator *da, \
36  double max, unsigned int lower_bound, unsigned int upper_bound) const { \
37  double ret = 0; \
38  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
39  ret += evaluate_if_good_index(m, p[i], da, max - ret); \
40  if (ret > max) return std::numeric_limits<double>::max(); \
41  } \
42  return ret; \
43  }
44 
45 //! Define extra the functions needed for a TripletPredicate
46 #define IMP_TRIPLET_PREDICATE_METHODS(Name) \
47  int get_value(const kernel::ParticleTriplet& a) const { \
48  return get_value_index(IMP::kernel::internal::get_model(a), \
49  IMP::kernel::internal::get_index(a)); \
50  } \
51  Ints get_value(const kernel::ParticleTripletsTemp &o) const { \
52  Ints ret(o.size()); \
53  for (unsigned int i = 0; i < o.size(); ++i) { \
54  ret[i] += Name::get_value(o[i]); \
55  } \
56  return ret; \
57  } \
58  Ints get_value_index(kernel::Model *m, const kernel::ParticleIndexTriplets &o) const { \
59  Ints ret(o.size()); \
60  for (unsigned int i = 0; i < o.size(); ++i) { \
61  ret[i] += Name::get_value_index(m, o[i]); \
62  } \
63  return ret; \
64  } \
65  IMP_IMPLEMENT_INLINE_NO_SWIG( \
66  void remove_if_equal(kernel::Model *m, kernel::ParticleIndexTriplets &ps, \
67  int value) const, \
68  { \
69  ps.erase( \
70  std::remove_if(ps.begin(), ps.end(), \
71  IMP::kernel::internal::PredicateEquals<Name, true>( \
72  this, m, value)), \
73  ps.end()); \
74  }); \
75  IMP_IMPLEMENT_INLINE_NO_SWIG(void remove_if_not_equal(kernel::Model *m, \
76  kernel::ParticleIndexTriplets &ps, \
77  int value) const, \
78  { \
79  ps.erase( \
80  std::remove_if(ps.begin(), ps.end(), \
81  IMP::kernel::internal::PredicateEquals<Name, false>( \
82  this, m, value)), \
83  ps.end()); \
84  });
85 
86 //! Use IMP_TRIPLET_MODIFIER() instead
87 #define IMP_TRIPLET_DERIVATIVE_MODIFIER(Name) IMP_TRIPLET_MODIFIER(Name)
88 
89 /** Define
90  - IMP::kernel::TripletModifier::apply_indexes()
91 */
92 #define IMP_TRIPLET_MODIFIER_METHODS(Name) \
93  virtual void apply_indexes(kernel::Model *m, const kernel::ParticleIndexTriplets &o, \
94  unsigned int lower_bound, \
95  unsigned int upper_bound) const IMP_FINAL { \
96  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
97  apply_index(m, o[i]); \
98  } \
99  }
100 
101 //! Use IMP_INDEX_TRIPLET_MODIFIER instead
102 #define IMP_INDEX_TRIPLET_DERIVATIVE_MODIFIER(Name) \
103  IMP_INDEX_TRIPLET_MODIFIER(Name)
104 
105 #ifndef IMP_DOXYGEN
106 #define IMP_IMPLEMENT_TRIPLET_CONTAINER(Name) \
107  IMP_IMPLEMENT_INLINE(void do_apply(const TripletModifier *sm) const, \
108  { apply_generic(sm); }); \
109  virtual ParticleIndexes get_all_possible_indexes() const IMP_OVERRIDE; \
110  IMP_OBJECT_NO_WARNING(Name)
111 #endif
112 
113 /** Use this to fill in container methods
114  IMP::kernel::TripletContainer::do_apply()
115 */
116 #define IMP_TRIPLET_CONTAINER_METHODS(Name) \
117  void do_apply(const TripletModifier *sm) const { apply_generic(sm); }
118 
119 #endif /* IMPKERNEL_TRIPLET_MACROS_H */
Various general useful macros for IMP.
Macros to define containers of objects.