00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef CACHED_VALUE_H
00012 #define CACHED_VALUE_H
00013
00014 #include "op_exception.h"
00015
00016
00017
00018
00019 template <class T>
00020 class cached_value
00021 {
00022 public:
00023 cached_value() : set(false) {}
00024
00025 typedef T value_type;
00026
00027
00028 value_type const get() const {
00029 if (!set)
00030 throw op_fatal_error("cached value not set");
00031 return value;
00032 }
00033
00034
00035 bool cached() const { return set; }
00036
00037
00038 value_type const reset(value_type const & val) {
00039 value = val;
00040 set = true;
00041 return value;
00042 }
00043
00044 private:
00045
00046 value_type value;
00047
00048 bool set;
00049 };
00050
00051
00052 #endif