IMP logo
IMP Reference Guide  2.8.0
The Integrative Modeling Platform
container_base.h
Go to the documentation of this file.
1 /**
2  * \file IMP/container_base.h
3  * \brief Abstract base class for containers of particles.
4  *
5  * Copyright 2007-2017 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_config.h>
13 #include "base_types.h"
14 #include "ModelObject.h"
15 #include "particle_index.h"
16 #include <IMP/utility_macros.h>
17 #include <IMP/ref_counted_macros.h>
18 #include <IMP/Object.h>
19 #include <IMP/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 ModelObject {
45 #if IMP_HAS_CHECKS >= IMP_INTERNAL
46  bool readable_;
47  bool writeable_;
48 #endif
49  protected:
50  Container(Model *m, std::string name = "Container %1%");
51 
52  virtual std::size_t do_get_contents_hash() const = 0;
53 
54  public:
55  //! Get contained particles
56  /** Get a list of all particles contained in this one,
57  given that the input containers are up to date.
58  */
59  virtual ParticleIndexes get_all_possible_indexes() const = 0;
60 
61  /** Return a hash that can be used to detect when the contents
62  of the container changed. Store the value and then compare
63  against the version next time to detect if it is different. */
64  std::size_t get_contents_hash() const { return do_get_contents_hash(); }
65 
66  //! containers don't have outputs
68  return ModelObjectsTemp();
69  }
70 
71  /** True if the container's contents are not independent from one
72  another, and so it cannot be decomposed into a sum of terms.
73  Examples include connectivity.*/
74  virtual bool get_is_decomposable() const { return true; }
75 
76 #if !defined(IMP_DOXYGEN)
77  // methods to implement checking for inputs and outputs
78  void validate_readable() const;
79  void validate_writable() const;
80  void set_is_readable(bool tf);
81  void set_is_writable(bool tf);
82 #endif
83 
85 };
86 
87 IMPKERNEL_END_NAMESPACE
88 
89 #endif /* IMPKERNEL_CONTAINER_BASE_H */
Various general useful macros for IMP.
Basic types used by IMP.
Various general useful functions for IMP.
std::size_t get_contents_hash() const
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Ref counted objects should have private destructors.
virtual bool get_is_decomposable() const
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:82
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
ModelObjectsTemp do_get_outputs() const
containers don't have outputs
Various general useful macros for IMP.
A nullptr-initialized pointer to an Object.
Single variable function.
A shared base class to help in debugging and things.
Abstract class for containers of particles.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.