IMP  2.2.0
The Integrative Modeling Platform
kernel/PairContainer.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/PairContainer.h
3  * \brief A container for Pairs.
4  *
5  * WARNING This file was generated from PairContainer.h
6  * in /tmp/nightly-build-28832/imp-2.2.0/tools/build/container_templates/kernel
7  * by tools/maintenance/setup_containers.py.
8  *
9  * Copyright 2007-2014 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPKERNEL_PAIR_CONTAINER_H
13 #define IMPKERNEL_PAIR_CONTAINER_H
14 
15 #include <IMP/kernel/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 "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 PairModifier;
32 class PairScore;
33 
34 //! A shared container for Pairs
35 /** Stores a shared collection of Pairs.
36  */
37 class IMPKERNELEXPORT PairContainer : public Container {
38  public:
43  typedef PairModifier Modifier;
45 
46  //! Just use apply() in the base class
47  void apply_generic(const PairModifier *m) const;
48 
49  //! Apply a SingletonModifier to the contents
50  void apply(const PairModifier *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 kernel::ParticleIndexPairs get_range_indexes() const = 0;
59 
60  const kernel::ParticleIndexPairs &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  contents_cache_ = 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 kernel::ParticleIndexPairs get_indexes() const = 0;
81 
82 #ifndef IMP_DOXYGEN
83 
84  kernel::ParticlePairsTemp get() const {
85  return IMP::kernel::internal::get_particle(get_model(), get_indexes());
86  }
87 
88  kernel::ParticlePair get(unsigned int i) const {
89  return IMP::kernel::internal::get_particle(get_model(), get_indexes()[i]);
90  }
91  unsigned int get_number() const { return get_indexes().size(); }
92 #ifndef SWIG
93  bool get_provides_access() const;
94  virtual const kernel::ParticleIndexPairs &get_access() const {
95  IMP_THROW("Object not implemented properly.", base::IndexException);
96  }
97 
98  template <class Functor>
99  Functor for_each(Functor f) {
101  // use boost range instead
102  return std::for_each(vs.begin(), vs.end(), f);
103  }
104 
105 #endif
106 #endif
107 
108  /** \deprecated_at{2.1} Use get_indexes() instead.
109  */
110  kernel::ParticlePairsTemp get_particle_pairs() const;
111 
112  /** \deprecated_at{2.1} This can be very slow and is probably not useful
113  */
114  IMPKERNEL_DEPRECATED_METHOD_DECL(2.1)
115  unsigned int get_number_of_particle_pairs() const;
116 
117  /** \deprecated_at{2.1}Use get_indexes() instead and thing about using the
118  IMP_CONTAINER_FOREACH() macro.*/
119  IMPKERNEL_DEPRECATED_METHOD_DECL(2.1)
120  kernel::ParticlePair get_particle_pair(unsigned int i) const;
121 
122  protected:
124  std::string name = "PairContainer %1%");
125 
126  virtual void do_apply(const PairModifier *sm) const = 0;
127  virtual bool do_get_provides_access() const { return false; }
128 
130 
131  private:
132  mutable std::size_t contents_hash_;
133  mutable kernel::ParticleIndexPairs contents_cache_;
134  mutable bool cache_initialized_;
135 };
136 
137 /** This class allows either a list or a container to be
138  accepted as input.
139 */
140 class IMPKERNELEXPORT PairContainerAdaptor :
141 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
142  public base::Pointer<PairContainer>
143 #else
144  public base::InputAdaptor
145 #endif
146  {
148 
149  public:
151 
152  /**
153  Constructs the adaptor pointing to c (so if the contents of c are changed
154  dynamically, so do the contents of the adaptor, and vice versa)
155  */
157 
158  /**
159  Constructs the adaptor pointing to c (so if the contents of c are changed
160  dynamically, so do the contents of the adaptor, and vice versa)
161  */
162  template <class C>
163  PairContainerAdaptor(base::internal::PointerBase<C> c)
164  : P(c) {}
165 
166  /**
167  Adapts the non-empty list t to PairContainer
168 
169  @param t a non-empty list of kernel::ParticlePairsTemp
170  */
172 
173  /** Set the name of the resulting container if it is currently the
174  default value. */
175  void set_name_if_default(std::string name);
176 };
177 
178 IMPKERNEL_END_NAMESPACE
179 
180 #endif /* IMPKERNEL_PAIR_CONTAINER_H */
std::size_t get_contents_hash() const
An exception for a request for an invalid member of a container.
IMP::kernel::PairModifier PairModifier
Class for adding derivatives from restraints to the model.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Abstract base class for containers of particles.
PairContainerAdaptor(base::internal::PointerBase< C > c)
IMP::kernel::PairScore PairScore
A nullptr-initialized pointer to an IMP Object.
A shared container for Pairs.
A smart pointer to a reference counted object.
Definition: base/Pointer.h:87
Control display of deprecation information.
A class to store an fixed array of same-typed values.
Definition: base/Array.h:33
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.
Classes to handle individual model particles.
Classes to handle individual model particles.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
IMP::kernel::PairContainer PairContainer
Exception definitions and assertions.
A base class for modifiers of kernel::ParticlePairsTemp.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72