00001 #ifndef GUARDED_VALUE_CLASS
00002 #define GUARDED_VALUE_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00025 template <class contents>
00026 class guarded_value
00027 {
00028 public:
00029 guarded_value() : _initialized(false) {}
00031 guarded_value(const contents &def) : _value(def), _initialized(true) {}
00033 guarded_value(const guarded_value &to_copy)
00034 : _value(to_copy._value), _initialized(to_copy._initialized) {}
00036
00039 bool initialized() const { return _initialized; }
00041
00044 void reset() { _initialized = false; }
00046
00049 guarded_value &operator =(const guarded_value &t_c)
00050 { if (this == &t_c) return *this; else return *this = t_c._value; }
00052 guarded_value &operator =(const contents &t_c)
00053 { _value = t_c; _initialized = true; return *this; }
00055
00056 operator contents() const { return _value; }
00058
00061 contents &access() { return _value; }
00063
00064 private:
00065 bool _initialized;
00066 contents _value;
00067 };
00068
00069 #endif
00070