00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMP_SCORE_STATE_H
00009 #define IMP_SCORE_STATE_H
00010
00011 #include "kernel_config.h"
00012 #include "RefCounted.h"
00013 #include "Pointer.h"
00014 #include "Model.h"
00015 #include "DerivativeAccumulator.h"
00016 #include "VersionInfo.h"
00017 #include "utility.h"
00018 #include "container_base.h"
00019
00020 #include <iostream>
00021
00022 IMP_BEGIN_NAMESPACE
00023
00024 class Model;
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class IMPEXPORT ScoreState : public Object
00048 {
00049 friend class Model;
00050 protected:
00051
00052
00053 virtual void set_model(Model* model);
00054
00055 public:
00056 ScoreState(std::string name=std::string());
00057
00058
00059 void before_evaluate();
00060
00061
00062 void after_evaluate(DerivativeAccumulator *accpt);
00063
00064
00065 Model *get_model() const {
00066 IMP_INTERNAL_CHECK(model_,
00067 "Must call set_model before get_model on state");
00068 return model_.get();
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 virtual ContainersTemp get_input_containers() const=0;
00080 virtual ContainersTemp get_output_containers() const=0;
00081
00082 virtual ParticlesTemp get_input_particles() const=0;
00083
00084 virtual ParticlesTemp get_output_particles() const=0;
00085 virtual ParticlesList get_interacting_particles() const=0;
00086
00087
00088
00089 protected:
00090
00091
00092
00093
00094
00095
00096
00097
00098 virtual void do_before_evaluate() = 0;
00099
00100
00101
00102
00103
00104 virtual void do_after_evaluate(DerivativeAccumulator *accpt)=0;
00105
00106 IMP_REF_COUNTED_DESTRUCTOR(ScoreState);
00107
00108 private:
00109
00110 WeakPointer<Model> model_;
00111 };
00112
00113
00114
00115 class ScoreStatePointer: public RAII {
00116 Pointer<ScoreState> ss_;
00117
00118 Pointer<Model> model_;
00119 public:
00120 IMP_RAII(ScoreStatePointer, (ScoreState *ss, Model *m),, {
00121 ss_=ss;
00122 model_=m;
00123 m->add_score_state(ss);
00124 }, {
00125 if (ss_) {
00126 ss_->get_model()->remove_score_state(ss_);
00127 ss_=NULL;
00128 model_=NULL;
00129 }
00130 });
00131 bool get_is_set() const {return ss_;}
00132 Model * get_model() const {
00133 return model_;
00134 }
00135 ScoreState* get_score_state() const {
00136 return ss_;
00137 }
00138 };
00139
00140 IMP_END_NAMESPACE
00141
00142
00143 #include "Model.h"
00144
00145 #endif