00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef IMP_SINGLETON_CONTAINER_H
00011 #define IMP_SINGLETON_CONTAINER_H
00012
00013 #include "kernel_config.h"
00014 #include "internal/IndexingIterator.h"
00015 #include "Particle.h"
00016 #include "container_base.h"
00017 #include "utility.h"
00018 #include "VersionInfo.h"
00019 #include "base_types.h"
00020 #include "Pointer.h"
00021 #include "VectorOfRefCounted.h"
00022 #include "VersionInfo.h"
00023 #include "DerivativeAccumulator.h"
00024 #include "internal/OwnerPointer.h"
00025 #include "macros.h"
00026
00027 IMP_BEGIN_NAMESPACE
00028 class SingletonModifier;
00029 class SingletonScore;
00030
00031
00032
00033
00034
00035
00036
00037
00038 class IMPEXPORT SingletonContainer : public Container
00039 {
00040 internal::OwnerPointer<Container> added_, removed_;
00041 struct Accessor {
00042 typedef Accessor This;
00043 typedef Particle* result_type;
00044 typedef unsigned int argument_type;
00045 result_type operator()(argument_type i) const {
00046 return o_->get_particle(i);
00047 }
00048 Accessor(SingletonContainer *pc): o_(pc){}
00049 Accessor(): o_(NULL){}
00050 IMP_COMPARISONS_1(o_);
00051 private:
00052
00053 SingletonContainer* o_;
00054 };
00055 protected:
00056
00057
00058
00059
00060
00061
00062
00063 void set_added_and_removed_containers(SingletonContainer* added,
00064 SingletonContainer* removed) {
00065 added_=added;
00066 removed_=removed;
00067 }
00068
00069 public:
00070 #ifndef IMP_DOXYGEN
00071 bool get_is_added_or_removed_container() {
00072 return !added_;
00073 }
00074 #endif
00075
00076 SingletonContainer(std::string name="SingletonContainer %1%");
00077
00078
00079
00080
00081 virtual bool get_contains_particle(Particle* v) const =0;
00082
00083
00084
00085 virtual unsigned int get_number_of_particles() const =0;
00086
00087 ParticlesTemp get_particles() const {
00088 return ParticlesTemp(particles_begin(),
00089 particles_end());
00090 }
00091 virtual Particle* get_particle(unsigned int i) const=0;
00092
00093 #ifdef IMP_DOXYGEN
00094
00095 class ParticleIterator;
00096 #else
00097 typedef internal::IndexingIterator<Accessor> ParticleIterator;
00098 #endif
00099
00100 ParticleIterator particles_begin() const {
00101
00102 return
00103 ParticleIterator(Accessor(const_cast<SingletonContainer*>(this)),
00104 0);
00105 }
00106
00107 ParticleIterator particles_end() const {
00108 return
00109 ParticleIterator(Accessor(const_cast<SingletonContainer*>(this)),
00110 get_number_of_particles());
00111 }
00112
00113
00114 virtual void apply(const SingletonModifier *sm)=0;
00115
00116
00117 virtual void apply(const SingletonModifier *sm, DerivativeAccumulator &da)=0;
00118
00119
00120 virtual double evaluate(const SingletonScore *s,
00121 DerivativeAccumulator *da) const=0;
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 SingletonContainer* get_removed_singletons_container() const {
00132 IMP_USAGE_CHECK(added_, "The containers returned by "
00133 << " get_added_singletons_container() do not "
00134 << " track their own added and removed contents.");
00135 SingletonContainer *ret= dynamic_cast<SingletonContainer*>(removed_.get());
00136 IMP_INTERNAL_CHECK(ret, "Cannot cast object " << removed_->get_name()
00137 << " to a SingletonContainer.");
00138 return ret;
00139 }
00140 SingletonContainer* get_added_singletons_container() const {
00141 IMP_USAGE_CHECK(added_, "The containers returned by "
00142 << " get_added_singletons_container() do not "
00143 << " track their own added and removed contents.");
00144 SingletonContainer *ret= dynamic_cast<SingletonContainer*>(added_.get());
00145 IMP_INTERNAL_CHECK(ret, "Cannot cast object " << added_->get_name()
00146 << " to a SingletonContainer.");
00147 return ret;
00148 }
00149
00150
00151
00152 virtual double evaluate_change(const SingletonScore *o,
00153 DerivativeAccumulator *da) const = 0;
00154
00155
00156
00157
00158
00159 virtual double evaluate_prechange(const SingletonScore *o,
00160 DerivativeAccumulator *da) const = 0;
00161
00162
00163 #ifndef IMP_DOXYGEN
00164 Particle* get(unsigned int i) const {return get_particle(i);}
00165 bool get_contains(Particle* v) const {
00166 return get_contains_particle(v);
00167 }
00168 unsigned int get_number() const {return get_number_of_particles();}
00169 #endif
00170
00171 IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(SingletonContainer);
00172 };
00173
00174 IMP_OUTPUT_OPERATOR(SingletonContainer);
00175
00176
00177 IMP_OBJECTS(SingletonContainer);
00178
00179
00180
00181
00182
00183 IMP_END_NAMESPACE
00184
00185 #endif