IMP  2.2.0
The Integrative Modeling Platform
kernel/Refiner.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/Refiner.h
3  * \brief Refine a particle into a list of particles.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPKERNEL_REFINER_H
9 #define IMPKERNEL_REFINER_H
10 
11 #include <IMP/kernel/kernel_config.h>
12 #include "base_types.h"
13 #include "Particle.h"
14 #include "internal/IndexingIterator.h"
16 #include "model_object_helpers.h"
17 
18 IMPKERNEL_BEGIN_NAMESPACE
19 
20 class Particle;
22 
23 //! Abstract class to implement hierarchical methods.
24 /** The job of this class is to take a single particle and, if
25  appropriate, return a list of particles. These lists can
26  reflect existing relationships, such as the
27  IMP::core::LeavesRefiner or arbitrary relationships set up
28  for a particular purpose, such as IMP::core::TableRefiner.
29 */
30 class IMPKERNELEXPORT Refiner : public ParticleInputs, public base::Object {
31  struct Accessor;
32 
33  public:
34  Refiner(std::string name = "Refiner %1%");
35  //! Return true if this refiner can refine that particle
36  /** This should not throw, so be careful what fields are touched.
37  */
38  virtual bool get_can_refine(Particle *) const { return false; }
39 
40  //! Refine the passed particle into a set of particles.
41  /** As a precondition can_refine_particle(a) should be true.
42  */
43  virtual const ParticlesTemp get_refined(Particle *a) const = 0;
44 
45  virtual ParticleIndexes get_refined_indexes(Model *m, ParticleIndex pi) const;
46 
47  //! Get the ith refined particle.
48  /** As a precondition can_refine_particle(a) should be true.
49  */
50  virtual Particle *get_refined(Particle *a, unsigned int i) const {
51  return get_refined(a)[i];
52  }
53 
54  /** As a precondition can_refine_particle(a) should be true.
55  */
56  virtual unsigned int get_number_of_refined(Particle *a) const {
57  return get_refined(a).size();
58  }
59 
60 #ifndef SWIG
61  /** @name Iterating through the set of refined particles
62 
63  Using iterators can be more efficient than using the bulk
64  get_refined(), however it is not necessarily so.
65  @{
66  */
67  typedef internal::IndexingIterator<Accessor> RefinedIterator;
68  RefinedIterator refined_begin(Particle *a) const;
69  RefinedIterator refined_end(Particle *a) const;
70 /** @} */
71 #endif
72 };
73 //! a collection of Refiner objects
75 
76 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
77 struct Refiner::Accessor {
78  // can't reference count since swig memory management is broken
79  Particle *p_;
80  const Refiner *r_;
81  Accessor(Particle *p, const Refiner *r) : p_(p), r_(r) {}
82  Accessor() {}
83  typedef Particle *result_type;
84  Particle *operator()(unsigned int i) const { return r_->get_refined(p_, i); }
85  bool operator==(const Accessor &o) const { return p_ == o.p_ && r_ == o.r_; }
86 };
87 #endif
88 
89 inline Refiner::RefinedIterator Refiner::refined_begin(Particle *a) const {
90  return RefinedIterator(Accessor(a, this), 0);
91 }
92 inline Refiner::RefinedIterator Refiner::refined_end(Particle *a) const {
93  return RefinedIterator(Accessor(a, this), get_number_of_refined(a));
94 }
95 
96 IMPKERNEL_END_NAMESPACE
97 
98 #endif /* IMPKERNEL_REFINER_H */
virtual unsigned int get_number_of_refined(Particle *a) const
IMP::kernel::DerivativeAccumulator DerivativeAccumulator
Basic types used by IMP.
virtual Particle * get_refined(Particle *a, unsigned int i) const
Get the ith refined particle.
Control display of deprecation information.
virtual bool get_can_refine(Particle *) const
Return true if this refiner can refine that particle.
Single variable function.
IMP::kernel::Refiner Refiner
Class to handle individual model particles.
Common base class for heavy weight IMP objects.
Definition: base/Object.h:106
Classes to handle individual model particles.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
IMP::kernel::Particle Particle
Abstract class to implement hierarchical methods.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72