IMP logo
IMP Reference Guide  2.9.0
The Integrative Modeling Platform
SingletonContainer.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-61563/imp-2.9.0/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-61563/imp-2.9.0/tools/build/container_templates/kernel/ClassnameContainer.h
3 // Do not edit - any changes will be lost!
4 
5 /**
6  * \file IMP/SingletonContainer.h
7  * \brief A container for Singletons.
8  *
9  * Copyright 2007-2018 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPKERNEL_SINGLETON_CONTAINER_H
13 #define IMPKERNEL_SINGLETON_CONTAINER_H
14 
15 #include <IMP/kernel_config.h>
16 #include "internal/IndexingIterator.h"
17 #include "Particle.h"
18 #include "container_base.h"
19 #include "internal/container_helpers.h"
20 #include "DerivativeAccumulator.h"
21 #include "base_types.h"
22 #include <IMP/ref_counted_macros.h>
23 #include <IMP/check_macros.h>
24 #include <IMP/Pointer.h>
25 #include <IMP/InputAdaptor.h>
26 #include <IMP/utility_macros.h>
27 #include <IMP/deprecation_macros.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  public:
39  typedef Particle* ContainedType;
45 
46  //! Just use apply() in the base class
47  void apply_generic(const SingletonModifier *m) const;
48 
49  //! Apply a SingletonModifier to the contents
50  void apply(const SingletonModifier *sm) const;
51 
52  /** Get all the indexes that might possibly be contained in the
53  container, useful with dynamic containers. For example,
54  with a container::ClosePairContainer, this is the list
55  of all pairs taken from input list (those that are far apart
56  in addition to those that are close).
57  */
58  virtual ParticleIndexes get_range_indexes() const = 0;
59 
60  const ParticleIndexes &get_contents() const {
61  if (get_provides_access())
62  return get_access();
63  else {
64  std::size_t nhash = get_contents_hash();
65  if (contents_hash_ != nhash || !cache_initialized_) {
66  contents_hash_ = nhash;
67  cache_initialized_ = true;
68  get_indexes_in_place(contents_cache_); // inheriting class could implement this faster than get_indexes()
69  }
70  return contents_cache_;
71  }
72  }
73 
74  /** Get all the indexes contained in the container.
75 
76  This should be protected but isn't for compatibility reasons.
77 
78  External callers should use get_contents().
79  */
80  virtual ParticleIndexes get_indexes() const = 0;
81 
82 
83 #ifndef IMP_DOXYGEN
84 
85  ParticlesTemp get() const {
86  return IMP::internal::get_particle(get_model(), get_indexes());
87  }
88 
89  Particle* get(unsigned int i) const {
90  return IMP::internal::get_particle(get_model(), get_indexes()[i]);
91  }
92 
93  //! Return size of current container content
94  //! Note that this may be expensive since my evaluate
95  //! refreshing of the container
96  unsigned int get_number() const { return get_indexes().size(); }
97 #ifndef SWIG
98  bool get_provides_access() const;
99  virtual const ParticleIndexes &get_access() const {
100  IMP_THROW("Object not implemented properly.", IndexException);
101  }
102 
103  template <class Functor>
104  Functor for_each(Functor f) {
106  // use boost range instead
107  return std::for_each(vs.begin(), vs.end(), f);
108  }
109 
110 #endif
111 #endif
112 
113  /** \deprecated_at{2.1}
114  Use get_contents() instead.
115  */
117 
118  /** \deprecated_at{2.1}
119  Use get_contents() instead and consider using the
120  IMP_CONTAINER_FOREACH() macro.*/
121  IMPKERNEL_DEPRECATED_METHOD_DECL(2.1)
122  Particle* get_particle(unsigned int i) const;
123 
124  protected:
126  std::string name = "SingletonContainer %1%");
127 
128  virtual void do_apply(const SingletonModifier *sm) const = 0;
129  virtual bool do_get_provides_access() const { return false; }
130 
131 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
132  //! Insert the contents of the container into output
133  //! Could be reimplemented to save time in terms of e.g. memory
134  //! allocation compared with calling get_indexes()
135  virtual void get_indexes_in_place(ParticleIndexes& output) const{
136  output= get_indexes();
137  }
138 #endif
139 
141 
142  private:
143  mutable std::size_t contents_hash_;
144  mutable ParticleIndexes contents_cache_;
145  mutable bool cache_initialized_;
146 };
147 
148 /** This class allows either a list or a container to be
149  accepted as input.
150 */
151 class IMPKERNELEXPORT SingletonContainerAdaptor :
152 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
153  public Pointer<SingletonContainer>
154 #else
155  public InputAdaptor
156 #endif
157  {
159 
160  public:
162 
163  /**
164  Constructs the adaptor pointing to c (so if the contents of c are changed
165  dynamically, so do the contents of the adaptor, and vice versa)
166  */
168 
169  /**
170  Constructs the adaptor pointing to c (so if the contents of c are changed
171  dynamically, so do the contents of the adaptor, and vice versa)
172  */
173  template <class C>
174  SingletonContainerAdaptor(IMP::internal::PointerBase<C> c)
175  : P(c) {}
176 
177  /**
178  Adapts the non-empty list t to SingletonContainer
179 
180  @param t a non-empty list of ParticlesTemp
181  */
183 
184  /** Set the name of the resulting container if it is currently the
185  default value. */
186  void set_name_if_default(std::string name);
187 };
188 
189 IMPKERNEL_END_NAMESPACE
190 
191 #endif /* IMPKERNEL_SINGLETON_CONTAINER_H */
A base class for modifiers of ParticlesTemp.
Control display of deprecation information.
Various general useful macros for IMP.
Basic types used by IMP.
Class for adding derivatives from restraints to the model.
std::size_t get_contents_hash() const
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
A smart pointer to a reference counted object.
Definition: Pointer.h:87
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Basic types used by IMP.
Various general useful macros for IMP.
An exception for a request for an invalid member of a container.
Definition: exception.h:157
A shared container for Singletons.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
Abstract base class for containers of particles.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Definition: check_macros.h:50
A nullptr-initialized pointer to an IMP Object.
Exception definitions and assertions.
Class to handle individual particles of a Model object.
Definition: Particle.h:41
#define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name)
SingletonContainerAdaptor(IMP::internal::PointerBase< C > c)
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Abstract class for containers of particles.