12#ifndef IMPKERNEL_PAIR_CONTAINER_H
13#define IMPKERNEL_PAIR_CONTAINER_H
15#include <IMP/kernel_config.h>
16#include "internal/IndexingIterator.h"
19#include "internal/container_helpers.h"
29#include <cereal/access.hpp>
30#include <cereal/types/base_class.hpp>
32IMPKERNEL_BEGIN_NAMESPACE
39class IMPKERNELEXPORT PairContainer :
public Container {
73 if (get_provides_access())
77 if (contents_hash_ != nhash || !cache_initialized_) {
78 contents_hash_ = nhash;
79 cache_initialized_ =
true;
80 get_indexes_in_place(contents_cache_);
82 return contents_cache_;
98 return IMP::internal::get_particle(get_model(),
get_indexes());
102 return IMP::internal::get_particle(get_model(),
get_indexes()[i]);
108 unsigned int get_number()
const {
return get_indexes().size(); }
110 bool get_provides_access()
const;
112 IMP_THROW(
"Object not implemented properly.", IndexException);
115 template <
class Functor>
116 Functor for_each(Functor f) {
119 return std::for_each(vs.begin(), vs.end(), f);
126 PairContainer(Model *m,
127 std::string name =
"PairContainer %1%");
130 virtual void do_apply(
const PairModifier *sm)
const = 0;
131 virtual void do_apply_moved(
const PairModifier *sm,
132 const ParticleIndexes &moved_pis,
133 const ParticleIndexes &reset_pis)
const {
138 virtual bool do_get_provides_access()
const {
return false; }
140#if !defined(SWIG) && !defined(IMP_DOXYGEN)
144 virtual void get_indexes_in_place(ParticleIndexPairs& output)
const{
152 mutable std::size_t contents_hash_;
154 mutable bool cache_initialized_;
156 friend class cereal::access;
158 template<
class Archive>
void serialize(Archive &ar) {
159 ar(cereal::base_class<Container>(
this));
161 if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
163 cache_initialized_ =
false;
172class IMPKERNELEXPORT PairContainerAdaptor :
173#if !defined(SWIG) && !defined(IMP_DOXYGEN)
182 PairContainerAdaptor() {}
210IMPKERNEL_END_NAMESPACE
Class for adding derivatives from restraints to the model.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
A nullptr-initialized pointer to an IMP Object.
Helper macros for throwing and handling exceptions.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
std::size_t get_contents_hash() const
void set_name_if_default(std::string name)
PairContainerAdaptor(IMP::internal::PointerBase< C > c)
PairContainerAdaptor(const ParticlePairsTemp &t)
PairContainerAdaptor(PairContainer *c)
A shared container for Pairs.
virtual ParticleIndexPairs get_indexes() const =0
void apply_generic_moved(const PairModifier *m, const ParticleIndexes &moved_pis, const ParticleIndexes &reset_pis) const
Just use apply_moved() in the base class.
virtual ParticleIndexPairs get_range_indexes() const =0
void apply_moved(const PairModifier *sm, const ParticleIndexes &moved_pis, const ParticleIndexes &reset_pis) const
Apply a PairModifier to the contents.
void apply(const PairModifier *sm) const
Apply a PairModifier to the contents.
void apply_generic(const PairModifier *m) const
Just use apply() in the base class.
A base class for modifiers of ParticlePairsTemp.
Abstract base class for containers of particles.
Control display of deprecation information.
IMP::Vector< ParticleIndexPair, std::allocator< ParticleIndexPair > > ParticleIndexPairs
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Array< 2, ParticleIndex > ParticleIndexPair
An ordered pair of particles, each identified by its ParticleIndex.
Array< 2, WeakPointer< Particle >, Particle * > ParticlePair
IMP::Vector< ParticlePair > ParticlePairsTemp
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Get the indexes from a list of particles.
Macros to help with reference counting.
#define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name)
A smart pointer to a reference counted object.
Various general useful macros for IMP.
#define IMP_UNUSED(variable)