IMP logo
IMP Reference Guide  develop.63b38c487d,2024/12/21
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-2023 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 #include <cereal/access.hpp>
21 #include <cereal/types/base_class.hpp>
22 
23 IMPKERNEL_BEGIN_NAMESPACE
24 class Particle;
25 class Model;
26 
27 //! Abstract class for containers of particles
28 /** Containers store sets of tuples of particles. The degree of the tuple
29  (i.e. whether each tuple contains one, two, three or four
30  particles) is constant for each container. That is, a
31  SingletonContainer is a set of single particles, a PairContainer
32  is a set of pairs of particles etc.
33 
34  These sets can come from a variety of sources, such as
35  - user-provided lists, e.g. IMP::container::ListSingletonContainer
36  - operations on other containers e.g. IMP::container::PairContainerSet
37  - computations based on particle attributes
38  e.g. IMP::container::ClosePairContainer
39 
40  Most basically, containers allow you to get their contents
41  (eg SingletonContainer::get_indexes()) or do an operation on their contents
42  IMP_CONTAINER_FOREACH().
43 
44  \note Containers store \em sets and so are fundamentally unordered.
45  */
46 class IMPKERNELEXPORT Container : public ModelObject {
47 #if IMP_HAS_CHECKS >= IMP_INTERNAL
48  bool readable_;
49  bool writeable_;
50 #endif
51 
52  friend class cereal::access;
53 
54  template<class Archive> void serialize(Archive &ar) {
55 #if IMP_HAS_CHECKS < IMP_INTERNAL
56  // serialize the same data regardless of the check level, so we are portable
57  bool readable_ = true, writeable_ = true;
58 #endif
59  ar(cereal::base_class<ModelObject>(this), readable_, writeable_);
60  }
61 
62  protected:
63  Container(Model *m, std::string name = "Container %1%");
64  Container() {}
65 
66  virtual std::size_t do_get_contents_hash() const = 0;
67 
68  public:
69  //! Get contained particles
70  /** Get a list of all particles contained in this one,
71  given that the input containers are up to date.
72  */
73  virtual ParticleIndexes get_all_possible_indexes() const = 0;
74 
75  /** Return a hash that can be used to detect when the contents
76  of the container changed. Store the value and then compare
77  against the version next time to detect if it is different. */
78  std::size_t get_contents_hash() const { return do_get_contents_hash(); }
79 
80  //! containers don't have outputs
81  ModelObjectsTemp do_get_outputs() const override {
82  return ModelObjectsTemp();
83  }
84 
85  /** True if the container's contents are not independent from one
86  another, and so it cannot be decomposed into a sum of terms.
87  Examples include connectivity.*/
88  virtual bool get_is_decomposable() const { return true; }
89 
90 #if !defined(IMP_DOXYGEN)
91  // methods to implement checking for inputs and outputs (only when checks beyond or equal internal)
92  void validate_readable() const;
93  void validate_writable() const;
94  void set_is_readable(bool tf);
95  void set_is_writable(bool tf);
96 #endif
97 
99 };
100 
101 IMPKERNEL_END_NAMESPACE
102 
103 #endif /* IMPKERNEL_CONTAINER_BASE_H */
Macros to help with reference counting.
Basic types used by IMP.
Functions and adaptors for dealing with particle indexes.
std::size_t get_contents_hash() const
ModelObjectsTemp do_get_outputs() const override
containers don't have outputs
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Set up destructor for a ref counted object.
virtual bool get_is_decomposable() const
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:106
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Base class for objects in a Model that depend on other objects.
Definition: ModelObject.h:28
Various general useful macros for IMP.
A weak pointer to an Object or RefCountedObject.
Base class for objects in a Model that depend on other objects.
A shared base class to help in debugging and things.
Abstract class for containers of particles.