Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

node/field.h

Go to the documentation of this file.
00001 #ifndef NODE_FIELD_H
00002 #define NODE_FIELD_H
00003 
00004 /*
00005 
00006   GLT OpenGL C++ Toolkit (LGPL)
00007   Copyright (C) 2000-2002 Nigel Stewart  
00008 
00009   Email: nigels.com@gmail.com   
00010   WWW:   http://www.nigels.com/glt/
00011 
00012   This library is free software; you can redistribute it and/or
00013   modify it under the terms of the GNU Lesser General Public
00014   License as published by the Free Software Foundation; either
00015   version 2.1 of the License, or (at your option) any later version.
00016 
00017   This library is distributed in the hope that it will be useful,
00018   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020   Lesser General Public License for more details.
00021 
00022   You should have received a copy of the GNU Lesser General Public
00023   License along with this library; if not, write to the Free Software
00024   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 */
00027 
00033 #include <string>
00034 #include <iosfwd>
00035 #include <misc/refcount.h>
00036 
00037 class GltRegistry;
00038 class GltFields;
00039 
00040 class GltField;
00041 
00043 typedef ReferenceCountPtr<GltField> GltFieldPtr;
00044 
00050 class GltField
00051 {
00052     friend class GltFields;
00053     friend class GltRegistry;
00054 
00055 protected:
00056     GltField();
00057     GltField(const std::string &name);
00058     GltField(const GltField &);
00059 
00060     GltField &operator=(const GltField &);
00061 
00062 public:
00063 
00064     virtual ~GltField();
00065 
00066             std::string &name();
00067             bool        &locked();
00068 
00069       const std::string &name() const;
00070 
00071     virtual std::string get() const;
00072     virtual bool        set(const std::string &value);
00073     virtual bool        reset();
00074     virtual bool        isDefault() const;
00075 
00076     virtual bool write(std::ostream &os,const std::string &prefix = std::string()) const;
00077 
00078 protected:
00079 
00080     std::string _name;
00081 
00082     #ifdef GLT_WIN32
00083     virtual bool writeRegistry(void *key) const;
00084     virtual bool readRegistry (void *key);
00085     #endif
00086 };
00087 
00089 
00099 template<class T>
00100 class GltFieldFunc : public GltField
00101 {
00102 public:
00103     GltFieldFunc(T &obj,void (T::*func)(void),const std::string &name,const bool output = false)
00104     : GltField(name), _obj(&obj), _func(func), _output(output)
00105     {
00106     }
00107 
00108     GltFieldFunc(const GltFieldFunc &f)
00109     : GltField(f), _obj(f._obj), _func(f._func), _output(f._output)
00110     {
00111     }
00112 
00113     virtual ~GltFieldFunc()
00114     {
00115     }
00116 
00117     GltFieldFunc &operator=(const GltFieldFunc &f)
00118     {
00119         if (this!=&f)
00120         {
00121             _obj    = f._obj;   
00122             _func   = f._func;
00123             _output = f._output;
00124         }
00125 
00126         return *this;
00127     }
00128 
00129     bool write(std::ostream &os,const std::string &prefix = std::string()) const 
00130     { 
00131         if (_output)
00132             GltField::write(os,prefix);
00133         
00134         return true;
00135     }
00136 
00137     bool set(const std::string &value)
00138     {
00139         (_obj->*(_func))();
00140         return true;
00141     }
00142 
00143 private:
00144 
00146     T *_obj;
00148     void (T::*_func)(void);
00150     const bool _output;      
00151 };
00152 
00153 #endif

Generated on Tue Nov 5 11:11:05 2002 for GLT by doxygen1.2.18