00001 #ifndef HAZY_MODEL_H
00002 #define HAZY_MODEL_H
00003
00004 #include "model.h"
00005
00006 #include <sstream>
00007
00012 struct hazy_model {
00013 struct model &_model;
00014 enum strategy { LAZY_NAIVE, EAGER_NAIVE,LAZY_HAZY, EAGER_HAZY } _strategy;
00015 double low_water, high_water;
00025 bool model_is_in_db;
00027 bool test_and_set_model_in_db() { bool ret = model_is_in_db; model_is_in_db = true; return ret; }
00029 void invalidate_db_model() { model_is_in_db = false; }
00030
00032
00035 bool isEager() { return (_strategy == EAGER_NAIVE || _strategy == EAGER_HAZY); }
00039 bool isLazy () { return (_strategy == LAZY_NAIVE || _strategy == LAZY_HAZY); }
00043 bool isHazy() {return (_strategy == EAGER_HAZY || _strategy == LAZY_HAZY);}
00047 bool isNaive() { return (_strategy == EAGER_NAIVE || _strategy == LAZY_NAIVE); }
00048
00050
00055 static bool isEager(strategy s) { return (s == EAGER_NAIVE || s == EAGER_HAZY); }
00061 static bool isLazy(strategy s) {return (s == LAZY_NAIVE || s == LAZY_HAZY);}
00067 static bool isHazy(strategy s) { return (s == EAGER_HAZY || s == LAZY_HAZY); }
00073 static bool isNaive(strategy s) {return (s == EAGER_NAIVE || s == LAZY_NAIVE);}
00074
00076
00081 hazy_model(struct model &model, strategy s) : _model(model), _strategy(s),
00082 low_water(0.0), high_water(0.0), model_is_in_db(false) { }
00083 };
00084
00088 class UnknownStrategyException : public std::exception {
00089 std::string _filename, _msg;
00090 int _line;
00091 public:
00092 UnknownStrategyException(const char* file, int line, const char *msg) {
00093 _filename = std::string(file);
00094 _line = line;
00095 _msg = std::string(msg);
00096 }
00097 virtual ~UnknownStrategyException() throw() { }
00098
00099 virtual const char* what() const throw() {
00100 std::ostringstream s;
00101 s << "[Unknown Strategy Exception @ " << _filename << ":" << _line << "] msg: " << _msg;
00102 return s.str().c_str();
00103 }
00104
00105 };
00106
00107 #endif