IMP  2.1.0
The Integrative Modeling Platform
kernel/SingletonContainer.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/SingletonContainer.h
3  * \brief A container for Singletons.
4  *
5  * WARNING This file was generated from SingletonContainer.h
6  * in /tmp/nightly-build-90783/imp-2.1.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 "ParticleTuple.h"
23 #include <IMP/base/check_macros.h>
24 #include <IMP/base/Pointer.h>
25 #include <IMP/base/InputAdaptor.h>
28 #include <algorithm>
29 
30 IMPKERNEL_BEGIN_NAMESPACE
31 class SingletonModifier;
32 class SingletonScore;
33 
34 //! A shared container for Singletons
35 /** Stores a shared collection of Singletons.
36  */
37 class IMPKERNELEXPORT SingletonContainer : public Container {
38  protected:
40  std::string name = "SingletonContainer %1%");
41 
42  public:
43  typedef Particle* ContainedType;
47 
48  //! Just use apply() in the base class
49  void apply_generic(const SingletonModifier *m) const;
50 
51  //! Apply a SingletonModifier to the contents
52  void apply(const SingletonModifier *sm) const;
53 
54  /** Get all the indexes contained in the container.*/
55  virtual ParticleIndexes get_indexes() const = 0;
56  /** Get all the indexes that might possibly be contained in the
57  container, useful with dynamic containers. For example,
58  with a container::ClosePairContainer, this is the list
59  of all pairs taken from input list (those that are far apart
60  in addition to those that are close).
61  */
62  virtual ParticleIndexes get_range_indexes() const = 0;
63 
64 #ifndef IMP_DOXYGEN
65  ParticlesTemp get() const {
66  return IMP::kernel::internal::get_particle(get_model(), get_indexes());
67  }
68 
69  Particle* get(unsigned int i) const {
70  return IMP::kernel::internal::get_particle(get_model(), get_indexes()[i]);
71  }
72  unsigned int get_number() const { return get_indexes().size(); }
73 #ifndef SWIG
74  bool get_provides_access() const;
75  virtual const ParticleIndexes &get_access() const {
76  IMP_THROW("Object not implemented properly.", base::IndexException);
77  }
78 
79  template <class Functor> Functor for_each(Functor f) {
81  // use boost range instead
82  return std::for_each(vs.begin(), vs.end(), f);
83  }
84 
85 #endif
86 #endif
87 
88  /** \deprecated_at{2.1} Use get_indexes() instead.
89  */
91 
92  /** \brief This function is very slow and you should think hard about using
93  it.
94 
95  \deprecated_at{2.1} This is slow and dependent on the order of elements
96  in the tuple.
97 
98  Return whether the container has the given element.*/
99  IMPKERNEL_DEPRECATED_METHOD_DECL(2.1)
100  bool get_contains_particle(Particle* v) const;
101 
102  /** \deprecated_at{2.1} This can be very slow and is probably not useful
103  */
104  IMPKERNEL_DEPRECATED_METHOD_DECL(2.1)
105  unsigned int get_number_of_particles() const;
106 
107  /** \deprecated_at{2.1}Use get_indexes() instead and thing about using the
108  IMP_CONTAINER_FOREACH() macro.*/
109  IMPKERNEL_DEPRECATED_METHOD_DECL(2.1)
110  Particle* get_particle(unsigned int i) const;
111 
112  protected:
113  virtual void do_apply(const SingletonModifier *sm) const = 0;
114  virtual bool do_get_provides_access() const { return false; }
115 
117 };
118 
119 /** This class allows either a list or a container to be
120  accepted as input.
121 */
122 class IMPKERNELEXPORT SingletonContainerAdaptor :
123 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
124  public base::Pointer<SingletonContainer>
125 #else
126  public base::InputAdaptor
127 #endif
128  {
130 
131  public:
133 
134  /**
135  Constructs the adaptor pointing to c (so if the contents of c are changed
136  dynamically, so do the contents of the adaptor, and vice versa)
137  */
139 
140  /**
141  Constructs the adaptor pointing to c (so if the contents of c are changed
142  dynamically, so do the contents of the adaptor, and vice versa)
143  */
144  template <class C>
145  SingletonContainerAdaptor(base::internal::PointerBase<C> c)
146  : P(c) {}
147 
148  /**
149  Adapts the non-empty list t to SingletonContainer
150 
151  @param t a non-empty list of ParticlesTemp
152  @param name name for the constructed SingletonContainer
153  */
155  std::string name = "SingletonContainerAdaptor%1%");
156 };
157 
158 IMPKERNEL_END_NAMESPACE
159 
160 #endif /* IMPKERNEL_DECLARE_SINGLETON_CONTAINER_H */
An exception for a request for an invalid member of a container.
Class for adding derivatives from restraints to the model.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Abstract base class for containers of particles.
Classes to handle individual model particles.
A nullptr-initialized pointer to an IMP Object.
IMP::kernel::SingletonContainer SingletonContainer
SingletonContainerAdaptor(base::internal::PointerBase< C > c)
ParticlesTemp get_particles(kernel::Model *m, const ParticleIndexes &ps)
A smart pointer to a reference counted object.
Definition: base/Pointer.h:87
Control display of deprecation information.
A base class for modifiers of ParticlesTemp.
IMP::kernel::SingletonModifier SingletonModifier
Abstract class for containers of particles.
Basic types used by IMP.
Various general useful macros for IMP.
#define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name)
Various general useful macros for IMP.
Class to handle individual model particles.
Classes to handle individual model particles.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Exception definitions and assertions.
IMP::kernel::SingletonScore SingletonScore
A shared container for Singletons.
Class for storing model, its restraints, constraints, and particles.