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

node/fields.h

Go to the documentation of this file.
00001 #ifndef NODE_FIELDS_H
00002 #define NODE_FIELDS_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 
00034 #ifdef GLT_WIN32
00035 #pragma warning(disable: 4786)      
00036 #endif
00037 
00038 #include <node/field.h>
00039 
00040 #include <vector>
00041 #include <string>
00042 
00043 class Vector;
00044 class Matrix;
00045 class BoundingBox;
00046 class GltColor;
00047 class GltLight;
00048 class GltMaterial;
00049 class GltViewport;
00050 
00051 class GltRegistry;
00052 class GltRegistryMenu;
00053 
00059 class GltFields : public GltField
00060 {
00061     friend class GltRegistry;
00062     friend class GltRegistryMenu;
00063 
00064 public:
00065     GltFields(const std::string &name);
00066     GltFields(const GltFields &);
00067     virtual ~GltFields();
00068 
00069     GltFields &operator=(const GltFields &);
00070 
00071     void add(bool         &,                  const std::string &name);
00072     void add(int          &,                  const std::string &name);
00073     void add(float        &,                  const std::string &name);
00074     void add(float        &,const float step, const std::string &name);
00075     void add(double       &,                  const std::string &name);
00076     void add(double       &,const double step,const std::string &name);
00077     void add(std::string  &,                  const std::string &name);
00078     void add(Vector       &,                  const std::string &name);
00079     void add(Matrix       &,                  const std::string &name);
00080     void add(BoundingBox  &,                  const std::string &name);
00081     void add(GltColor     &,                  const std::string &name);
00082     void add(GltLight     &,                  const std::string &name);
00083     void add(GltMaterial  &,                  const std::string &name);
00084     void add(GltViewport  &,                  const std::string &name);
00085 
00087 
00088     void add(int          &,const int max,const std::string *labels,const std::string &name);
00089 
00091 
00092 //  template<class T>
00093 //  void add(T &v,const std::string &name)
00094 //  {
00095 //      GltFieldPtr root = v.settings();
00096 //      root->name() = name;
00097 //      add(root);
00098 //  }
00099 
00100     void add(const GltFieldPtr &field);
00101     void add(const GltFieldPtr &field,const std::string &rename);
00102     void add(      GltField    *field);
00103 
00105 
00106     template<class T>
00107     void add(T *ptr,const int n,const std::string &name)
00108     {
00109         GltFields *root = new GltFields(name);
00110         _fields.push_back(GltFieldPtr(root));
00111 
00112         for (int i=0; i<n; i++,ptr++)
00113         {
00114             char buffer[10];
00115             sprintf(buffer,"%d",i);
00116             root->add(*ptr,buffer);
00117         }
00118     }
00119 
00121 
00122     template<class T>
00123     void add(T &obj,void (T::*func)(void),const std::string &name,const bool output = false)
00124     {
00125         add(GltFieldPtr(new GltFieldFunc<T>(obj,func,name,output)));
00126     }
00127 
00128     bool reset();
00129 
00131 
00132     void merge(const GltFieldPtr &root);
00133 
00134     bool write(std::ostream &os,const std::string &prefix = std::string()) const;
00135 
00136 protected:
00137 
00138     #ifdef GLT_WIN32
00139     virtual bool writeRegistry(void *key) const;
00140     virtual bool readRegistry (void *key);
00141     #endif
00142 
00143 private:
00144 
00145     std::vector<GltFieldPtr> _fields;
00146 
00148 
00154     class GltFieldBool : public GltField
00155     {
00156     public:
00157         GltFieldBool(bool &val,const std::string &name);
00158         GltFieldBool(const GltFieldBool &);
00159         virtual ~GltFieldBool();
00160 
00161               bool &val();
00162         const bool &val() const;
00163 
00164         std::string get() const;
00165         bool        set(const std::string &value);
00166         bool        reset();
00167         bool        isDefault() const;
00168 
00169     private:
00170 
00171         bool &_val;
00172         const bool _default;
00173     };
00174 
00180     class GltFieldInt : public GltField
00181     {
00182     public:
00183         GltFieldInt(int &val,const std::string &name);
00184         GltFieldInt(const GltFieldInt &);
00185         virtual ~GltFieldInt();
00186 
00187               int &val();
00188         const int &val() const;
00189 
00190         std::string get() const;
00191         bool        set(const std::string &value);
00192         bool        reset();
00193         bool        isDefault() const;
00194 
00195     private:
00196 
00197         int &_val;
00198         const int _default;
00199     };
00200 
00206     class GltFieldDouble : public GltField
00207     {
00208     public:
00209         GltFieldDouble(double &val,const double step,const std::string &name);
00210         GltFieldDouble(const GltFieldDouble &);
00211         virtual ~GltFieldDouble();
00212 
00213               double &val();
00214         const double &val() const;
00215 
00216         std::string get() const;
00217         bool        set(const std::string &value);
00218         bool        reset();
00219         bool        isDefault() const;
00220 
00221         GltFieldDouble &operator++();
00222         GltFieldDouble &operator--();
00223 
00224     private:
00225 
00226         double &_val;
00227         double  _step;
00228         const double _default;
00229     };
00230 
00236     class GltFieldFloat : public GltField
00237     {
00238     public:
00239         GltFieldFloat(float &val,const float step,const std::string &name);
00240         GltFieldFloat(const GltFieldFloat &);
00241         virtual ~GltFieldFloat();
00242 
00243               float &val();
00244         const float &val() const;
00245 
00246         std::string get() const;
00247         bool        set(const std::string &value);
00248         bool        reset();
00249         bool        isDefault() const;
00250 
00251         GltFieldFloat &operator++();
00252         GltFieldFloat &operator--();
00253 
00254     private:
00255 
00256         float &_val;
00257         float  _step;
00258         const float _default;
00259     };
00260 
00266     class GltFieldString : public GltField
00267     {
00268     public:
00269         GltFieldString(std::string &val,const std::string &name);
00270         GltFieldString(const GltFieldString &);
00271         virtual ~GltFieldString();
00272 
00273               std::string &val();
00274         const std::string &val() const;
00275 
00276         std::string get() const;
00277         bool        set(const std::string &value);
00278         bool        reset();
00279         bool        isDefault() const;
00280 
00281     private:
00282 
00283         std::string &_val;
00284         const std::string _default;
00285     };
00286 
00292     class GltFieldEnum : public GltField
00293     {
00294     public:
00295         GltFieldEnum(int &val,const int max,const std::string *labels,const std::string &name);
00296         GltFieldEnum(const GltFieldEnum &);
00297         virtual ~GltFieldEnum();
00298 
00299               int &val();
00300         const int &val() const;
00301 
00302         std::string get() const;
00303         bool        set(const std::string &value);
00304         bool        reset();
00305         bool        isDefault() const;
00306 
00307         GltFieldEnum &operator++();
00308         GltFieldEnum &operator--();
00309 
00310     private:
00311 
00312         int &_val;
00313         const int _default;
00314         const int _max;
00315         const std::string *_labels;
00316     };
00317 };
00318 
00319 #endif

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