IMP logo
IMP Reference Guide  2.17.0
The Integrative Modeling Platform
TripletContainer.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-402/imp-2.17.0/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-402/imp-2.17.0/tools/build/container_templates/kernel/ClassnameContainer.h
3 // Do not edit - any changes will be lost!
4 
5 /**
6  * \file IMP/TripletContainer.h
7  * \brief A container for Triplets.
8  *
9  * Copyright 2007-2022 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPKERNEL_TRIPLET_CONTAINER_H
13 #define IMPKERNEL_TRIPLET_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 TripletModifier;
32 class TripletScore;
33 
34 //! A shared container for Triplets
35 /** Stores a shared collection of Triplets.
36  */
37 class IMPKERNELEXPORT TripletContainer : public Container {
38  public:
43  typedef TripletModifier Modifier;
45 
46  //! Just use apply() in the base class
47  void apply_generic(const TripletModifier *m) const;
48 
49  //! Just use apply_moved() in the base class
50  void apply_generic_moved(const TripletModifier *m,
51  const ParticleIndexes &moved_pis,
52  const ParticleIndexes &reset_pis) const;
53 
54  //! Apply a TripletModifier to the contents
55  void apply(const TripletModifier *sm) const;
56 
57  //! Apply a TripletModifier to the contents
58  void apply_moved(const TripletModifier *sm,
59  const ParticleIndexes &moved_pis,
60  const ParticleIndexes &reset_pis) const;
61 
62  /** Get all the indexes that might possibly be contained in the
63  container, useful with dynamic containers. For example,
64  with a container::ClosePairContainer, this is the list
65  of all pairs taken from the input list (those that are far apart
66  in addition to those that are close).
67  */
68  virtual ParticleIndexTriplets get_range_indexes() const = 0;
69 
70  const ParticleIndexTriplets &get_contents() const {
71  if (get_provides_access())
72  return get_access();
73  else {
74  std::size_t nhash = get_contents_hash();
75  if (contents_hash_ != nhash || !cache_initialized_) {
76  contents_hash_ = nhash;
77  cache_initialized_ = true;
78  get_indexes_in_place(contents_cache_); // inheriting class could implement this faster than get_indexes()
79  }
80  return contents_cache_;
81  }
82  }
83 
84  /** Get all the indexes contained in the container.
85 
86  This should be protected but isn't for compatibility reasons.
87 
88  External callers should use get_contents().
89  */
90  virtual ParticleIndexTriplets get_indexes() const = 0;
91 
92 
93 #ifndef IMP_DOXYGEN
94 
95  ParticleTripletsTemp get() const {
96  return IMP::internal::get_particle(get_model(), get_indexes());
97  }
98 
99  ParticleTriplet get(unsigned int i) const {
100  return IMP::internal::get_particle(get_model(), get_indexes()[i]);
101  }
102 
103  //! Return size of current container content
104  //! Note that this may be expensive since it may involve
105  //! refreshing of the container
106  unsigned int get_number() const { return get_indexes().size(); }
107 #ifndef SWIG
108  bool get_provides_access() const;
109  virtual const ParticleIndexTriplets &get_access() const {
110  IMP_THROW("Object not implemented properly.", IndexException);
111  }
112 
113  template <class Functor>
114  Functor for_each(Functor f) {
116  // use boost range instead
117  return std::for_each(vs.begin(), vs.end(), f);
118  }
119 
120 #endif
121 #endif
122 
123  protected:
125  std::string name = "TripletContainer %1%");
126 
127  virtual void do_apply(const TripletModifier *sm) const = 0;
128  virtual void do_apply_moved(const TripletModifier *sm,
129  const ParticleIndexes &moved_pis,
130  const ParticleIndexes &reset_pis) const {
131  IMP_UNUSED(moved_pis);
132  IMP_UNUSED(reset_pis);
133  do_apply(sm);
134  }
135  virtual bool do_get_provides_access() const { return false; }
136 
137 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
138  //! Insert the contents of the container into output
139  //! Could be reimplemented to save time in terms of e.g. memory
140  //! allocation compared with calling get_indexes()
141  virtual void get_indexes_in_place(ParticleIndexTriplets& output) const{
142  output= get_indexes();
143  }
144 #endif
145 
147 
148  private:
149  mutable std::size_t contents_hash_;
150  mutable ParticleIndexTriplets contents_cache_;
151  mutable bool cache_initialized_;
152 };
153 
154 /** This class allows either a list or a container to be
155  accepted as input.
156 */
157 class IMPKERNELEXPORT TripletContainerAdaptor :
158 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
159  public Pointer<TripletContainer>
160 #else
161  public InputAdaptor
162 #endif
163  {
165 
166  public:
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  */
174 
175  /**
176  Constructs the adaptor pointing to c (so if the contents of c are changed
177  dynamically, so do the contents of the adaptor, and vice versa)
178  */
179  template <class C>
180  TripletContainerAdaptor(IMP::internal::PointerBase<C> c)
181  : P(c) {}
182 
183  /**
184  Adapts the non-empty list t to TripletContainer
185 
186  @param t a non-empty list of ParticleTripletsTemp
187  */
189 
190  /** Set the name of the resulting container if it is currently the
191  default value. */
192  void set_name_if_default(std::string name);
193 };
194 
195 IMPKERNEL_END_NAMESPACE
196 
197 #endif /* IMPKERNEL_TRIPLET_CONTAINER_H */
Control display of deprecation information.
Macros to help with reference counting.
Basic types used by IMP.
A class to store an fixed array of same-typed values.
Definition: Array.h:33
Class for adding derivatives from restraints to the model.
std::size_t get_contents_hash() const
A more IMP-like version of the std::vector.
Definition: Vector.h:40
A smart pointer to a reference counted object.
Definition: Pointer.h:87
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:73
Convenience class to accept multiple input types.
#define IMP_UNUSED(variable)
Various general useful macros for IMP.
An exception for a request for an invalid member of a container.
Definition: exception.h:156
TripletContainerAdaptor(IMP::internal::PointerBase< C > c)
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.
Helper macros for throwing and handling exceptions.
A base class for modifiers of ParticleTripletsTemp.
#define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name)
Convenience class to accept multiple input types.
Definition: InputAdaptor.h:25
A shared container for Triplets.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Get the indexes from a list of particles.
Abstract class for containers of particles.