IMP  2.1.1
The Integrative Modeling Platform
kernel/container_base.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/container_base.h
3  * \brief Abstract base class for containers of particles.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_CONTAINER_BASE_H
10 #define IMPKERNEL_CONTAINER_BASE_H
11 
12 #include <IMP/kernel/kernel_config.h>
13 #include "base_types.h"
14 #include "ScoreState.h"
15 #include "particle_index.h"
18 #include <IMP/base/Object.h>
19 #include <IMP/base/WeakPointer.h>
20 
21 IMPKERNEL_BEGIN_NAMESPACE
22 class Particle;
23 class Model;
24 
25 //! Abstract class for containers of particles
26 /** Containers store sets of tuples of particles. The degree of the tuple
27  (i.e. whether each tuple contains one, two, three or four
28  particles) is constant for each container. That is, a
29  SingletonContainer is a set of single particles, a PairContainer
30  is a set of pairs of particles etc.
31 
32  These sets can come from a variety of sources, such as
33  - user-provided lists, e.g. IMP::container::ListSingletonContainer
34  - operations on other containers e.g. IMP::container::PairContainerSet
35  - computations based on particle attributes
36  e.g. IMP::container::ClosePairContainer
37 
38  Most basically, containers allow you to get their contents
39  (eg SingletonContainer::get_indexes()) or do an operation on their contents
40  IMP_CONTAINER_FOREACH().
41 
42  \note Containers store \em sets and so are fundamentally unordered.
43  */
44 class IMPKERNELEXPORT Container : public ScoreState {
45  int version_;
46 #if IMP_HAS_CHECKS >= IMP_INTERNAL
47  bool readable_;
48  bool writeable_;
49 #endif
50  protected:
51  //! Call this with true when the contents of the container change
52  /** See get_contents_version() to monitor the container for changes.
53 
54  Static containers should call this in their constructor. */
55  void set_is_changed(bool tf);
56  Container(kernel::Model *m, std::string name = "Container %1%");
57 
58  public:
59 
60 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
61  // lazy, should go in an internal header
62  static bool update_version(Container *c, int &version) {
63  int old = version;
64  version = c->get_contents_version();
65  return old != version;
66  }
67 #endif
68  //! Get contained particles
69  /** Get a list of all particles contained in this one,
70  given that the input containers are up to date.
71  */
72  virtual ParticleIndexes get_all_possible_indexes() const = 0;
73 
74  /** Return true if the container changed since the last evaluate.
75 
76  \deprecated_at{2.1} Use get_contents_version() instead as that
77  is safer.*/
78  IMPKERNEL_DEPRECATED_FUNCTION_DECL(2.1)
79  bool get_is_changed() const;
80 
81  /** Return a counter that can be used to detect when the contents
82  of the container changed. Store the value and then compare
83  against the version next time to detect if it is different. It
84  is initially 0.*/
85  int get_contents_version() const { return version_; }
86 
87  //! containers don't have outputs
88  ModelObjectsTemp do_get_outputs() const IMP_OVERRIDE {
89  return ModelObjectsTemp();
90  }
91 
92  //! Reset changed status
93  virtual void do_after_evaluate(DerivativeAccumulator *accpt) IMP_OVERRIDE;
94 
95  /** True if the container's contents are not independent from one
96  another, and so it cannot be decomposed into a sum of terms.
97  Examples include connectivity.*/
98  virtual bool get_is_decomposable() const { return true; }
99 
100 #if !defined(IMP_DOXYGEN)
101  // methods to implement checking for inputs and outputs
102  void validate_readable() const;
103  void validate_writable() const;
104  void set_is_readable(bool tf);
105  void set_is_writable(bool tf);
106 #endif
107 
108  /** \deprecated_at{2.1} use get_all_possible_indexes() instead
109  */
110  IMPKERNEL_DEPRECATED_METHOD_DECL(2.1)
111  ParticlesTemp get_all_possible_particles() const {
112  IMPKERNEL_DEPRECATED_METHOD_DEF(
113  2.1,
114  "Use IMP::Container::get_all_possible_indexes()"
115  "instead");
116  return IMP::kernel::get_particles(get_model(), get_all_possible_indexes());
117  }
118 
120 };
121 
122 IMPKERNEL_END_NAMESPACE
123 
124 #endif /* IMPKERNEL_CONTAINER_BASE_H */
Various general useful functions for IMP.
Class for adding derivatives from restraints to the model.
IMP::base::Vector< IMP::base::WeakPointer< kernel::ModelObject > > ModelObjectsTemp
ParticlesTemp get_particles(kernel::Model *m, const ParticleIndexes &ps)
Basic types used by IMP.
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Ref counted objects should have private destructors.
ScoreStates maintian invariants in the Model.
IMP::kernel::Container Container
virtual bool get_is_decomposable() const
Abstract class for containers of particles.
IMP::kernel::Model Model
Various general useful macros for IMP.
Shared score state.
Various general useful macros for IMP.
A nullptr-initialized pointer to an Object.
IMP::kernel::Particle Particle
A shared base class to help in debugging and things.
Class for storing model, its restraints, constraints, and particles.
ModelObjectsTemp do_get_outputs() const
containers don&#39;t have outputs