guarded_value.h

Go to the documentation of this file.
00001 #ifndef GUARDED_VALUE_CLASS
00002 #define GUARDED_VALUE_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : guarded_value                                                     *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
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 

Generated on Fri Nov 28 04:29:12 2008 for HOOPLE Libraries by  doxygen 1.5.1