IMP  2.0.0
The Integrative Modeling Platform
kernel/declare_SingletonContainer.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/declare_SingletonContainer.h
3  * \brief A container for Singletons.
4  *
5  * WARNING This file was generated from declare_SingletonContainer.h
6  * in /tmp/nightly-build-5687/imp-2.0.0/tools/build/container_templates/kernel
7  * by tools/maintenance/setup_containers.py.
8  *
9  * Copyright 2007-2013 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPKERNEL_DECLARE_SINGLETON_CONTAINER_H
13 #define IMPKERNEL_DECLARE_SINGLETON_CONTAINER_H
14 
15 #include <IMP/kernel/kernel_config.h>
16 #include "internal/IndexingIterator.h"
17 #include "declare_Particle.h"
18 #include "container_base.h"
19 #include "internal/container_helpers.h"
20 #include "DerivativeAccumulator.h"
21 #include "internal/OwnerPointer.h"
22 #include "ParticleTuple.h"
24 #include <IMP/base/check_macros.h>
25 #include <IMP/base/Pointer.h>
26 #include <IMP/base/InputAdaptor.h>
29 #include <algorithm>
30 
31 
32 IMPKERNEL_BEGIN_NAMESPACE
33 class SingletonModifier;
34 class SingletonScore;
35 
36 //! A shared container for Singletons
37 /** Stores a searchable shared collection of Singletons.
38  \headerfile SingletonContainer.h "IMP/kernel/SingletonContainer.h"
39  \implementationwithoutexample{SingletonContainer, IMP_SINGLETON_CONTAINER}
40  */
41 class IMPKERNELEXPORT SingletonContainer : public Container
42 {
43 protected:
45  std::string name="SingletonContainer %1%");
46 public:
47  typedef Particle* ContainedType;
51 
52  //! Just use apply() in the base class
53  void apply_generic(const SingletonModifier *m) const;
54 
55  //! Apply a SingletonModifier to the contents
56  void apply(const SingletonModifier *sm) const;
57 
58  /** Get all the indexes contained in the container.*/
59  virtual ParticleIndexes get_indexes() const=0;
60  /** Get all the indexes that might possibly be contained in the
61  container, useful with dynamic containers. For example,
62  with a container::ClosePairContainer, this is the list
63  of all pairs taken from input list (those that are far apart
64  in addition to those that are close).
65  */
66  virtual ParticleIndexes get_range_indexes() const=0;
67 
68 #ifndef IMP_DOXYGEN
69  ParticlesTemp get() const {
70  return IMP::kernel::internal::get_particle(get_model(),
71  get_indexes());
72  }
73 
74  Particle* get(unsigned int i) const {
75  return IMP::kernel::internal::get_particle(get_model(),
76  get_indexes()[i]);
77  }
78  unsigned int get_number() const {return get_indexes().size();}
79 #ifndef SWIG
80  bool get_provides_access() const;
81  virtual const ParticleIndexes& get_access() const {
82  IMP_THROW("Object not implemented properly.", base::IndexException);
83  }
84 
85 
86  template <class Functor>
87  Functor for_each(Functor f) {
89  // use boost range instead
90  return std::for_each(vs.begin(), vs.end(), f);
91  }
92 
93 #endif
94 #endif
95 
96  /** Use this for debugging only.
97  */
99 
100 #if IMP_HAS_DEPRECATED
101  /** \brief This function is very slow and you should think hard about using
102  it.
103 
104  \deprecated This is slow and dependent on the order of elements in the
105  tuple.
106 
107  Return whether the container has the given element.*/
109  bool get_contains_particle(Particle* v) const;
110 
111  /** \deprecated This can be very slow and is probably not useful
112  */
113  IMP_DEPRECATED_WARN unsigned int get_number_of_particles() const;
114 
115  /** \deprecated Use indexes instead and thing about using the
116  IMP_CONTAINER_FOREACH() macro.*/
118  get_particle(unsigned int i) const;
119 
120 #endif
121 protected:
122  virtual void do_apply(const SingletonModifier *sm) const=0;
123  virtual bool do_get_provides_access() const {return false;}
124 
126 };
127 
128 
129 /** This class allows either a list or a container to be
130  accepted as input.
131 */
132 class IMPKERNELEXPORT SingletonContainerAdaptor:
133 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
134 public base::Pointer<SingletonContainer>
135 #else
136 public base::InputAdaptor
137 #endif
138 {
140  public:
143  template <class C>
144  SingletonContainerAdaptor(base::internal::PointerBase<C> c): P(c){}
146  std::string name="SingletonContainerAdaptor%1%");
147 };
148 
149 
150 IMPKERNEL_END_NAMESPACE
151 
152 #endif /* IMPKERNEL_DECLARE_SINGLETON_CONTAINER_H */