property.h
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2000
00004  *     Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
00005  *
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 /********************************************************************
00023  *
00024  *  This library is free software; you can redistribute it and/or
00025  *  modify it under the terms of the GNU Lesser General Public
00026  *  License as published by the Free Software Foundation; either
00027  *  version 2.1 of the License, or (at your option) any later version.
00028  *
00029  *  This library is distributed in the hope that it will be useful,
00030  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00031  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00032  *  Lesser General Public License for more details.
00033  *
00034  *  You should have received a copy of the GNU Lesser General Public
00035  *  License along with this library; if not, write to the Free Software
00036  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00037  *
00038  ********************************************************************/
00039 
00040 #ifndef __PROPERTY_H
00041 #define __PROPERTY_H
00042 
00043 #if defined (WIN32)
00044   #if defined (PLAYER_STATIC)
00045     #define PLAYERCORE_EXPORT
00046   #elif defined (playercore_EXPORTS)
00047     #define PLAYERCORE_EXPORT    __declspec (dllexport)
00048   #else
00049     #define PLAYERCORE_EXPORT    __declspec (dllimport)
00050   #endif
00051 #else
00052   #define PLAYERCORE_EXPORT
00053 #endif
00054 
00055 class ConfigFile;
00056 class Driver;
00057 
00059 class PLAYERCORE_EXPORT Property
00060 {
00061         public:
00062                 Property (void);
00063                 Property (const char *newKey, bool readOnly);
00064                 virtual ~Property (void);
00065 
00066                 // Accessor functions
00067                 virtual const char* GetKey (void) const         { return key; }
00068                 virtual void SetKey (const char *newKey);
00069                 virtual void GetValueToMessage (void *data) const = 0;
00070                 virtual void SetValueFromMessage (const void *data) = 0;
00071 
00072                 virtual const bool KeyIsEqual (const char *rhs);
00073 
00074                 // Config file read method
00075                 virtual bool ReadConfig (ConfigFile *cf, int section) = 0;
00076 
00077         protected:
00078                 char *key;                      // Key for this property
00079                 bool readonly;          // true if this property is read-only
00080 };
00081 
00084 
00086 class PLAYERCORE_EXPORT BoolProperty : public Property
00087 {
00088         public:
00089                 BoolProperty (const char *newKey, bool newValue, bool readOnly);
00091                 BoolProperty (const char *newKey, bool newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
00092 
00093                 bool GetValue (void) const              { return value; }
00094                 void SetValue (bool newValue);
00095                 void GetValueToMessage (void *data) const;
00096                 void SetValueFromMessage (const void *data);
00097 
00098                 // Config file read method
00099                 virtual bool ReadConfig (ConfigFile *cf, int section);
00100 
00101                 // Operators
00102                 operator bool (void)                    { return value; }
00103                 const BoolProperty& operator= (const BoolProperty &rhs);
00104                 bool operator= (bool rhs);
00105 
00106         private:
00107                 bool value;
00108 };
00109 
00112 
00114 class PLAYERCORE_EXPORT IntProperty : public Property
00115 {
00116         public:
00117                 IntProperty (const char *newKey, int newValue, bool readOnly);
00119                 IntProperty (const char *newKey, int newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
00120 
00121                 int GetValue (void) const                       { return value; }
00122                 void SetValue (int newValue);
00123                 void GetValueToMessage (void *data) const;
00124                 void SetValueFromMessage (const void *data);
00125 
00126                 // Config file read method
00127                 virtual bool ReadConfig (ConfigFile *cf, int section);
00128 
00129                 // Operators
00130                 operator int (void)                             { return value; }
00131                 const IntProperty& operator= (const IntProperty &rhs);
00132                 int operator= (int rhs);
00133 
00134         private:
00135                 int value;
00136 };
00137 
00140 
00142 class PLAYERCORE_EXPORT DoubleProperty : public Property
00143 {
00144         public:
00145                 DoubleProperty (const char *newKey, double newValue, bool readOnly);
00147                 DoubleProperty (const char *newKey, double newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
00148 
00149                 double GetValue (void) const            { return value; }
00150                 void SetValue (double newValue);
00151                 void GetValueToMessage (void *data) const;
00152                 void SetValueFromMessage (const void *data);
00153 
00154                 // Config file read method
00155                 virtual bool ReadConfig (ConfigFile *cf, int section);
00156 
00157                 // Operators
00158                 operator double (void)                          { return value; }
00159                 const DoubleProperty& operator= (const DoubleProperty &rhs);
00160                 double operator= (double rhs);
00161 
00162         private:
00163                 double value;
00164 };
00165 
00168 
00170 class PLAYERCORE_EXPORT StringProperty : public Property
00171 {
00172         public:
00173                 StringProperty (const char *newKey, const char *newValue, bool readOnly);
00175                 StringProperty (const char *newKey, const char *newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
00176                 ~StringProperty (void);
00177 
00178                 const char* GetValue (void) const       { return value; }
00179                 void SetValue (const char *newValue);
00180                 void GetValueToMessage (void *data) const;
00181                 void SetValueFromMessage (const void *data);
00182 
00183                 // Config file read method
00184                 virtual bool ReadConfig (ConfigFile *cf, int section);
00185 
00186                 // Operators
00187                 operator const char* (void)                             { return value; }
00188                 const StringProperty& operator= (const StringProperty &rhs);
00189                 const char* operator= (const char* rhs);
00190 
00191         private:
00192                 char *value;
00193 };
00194 
00197 
00199 typedef struct PropertyNode
00200 {
00201         char *key;
00202         Property *property;
00203         struct PropertyNode *next;
00204 } PropertyNode;
00205 
00207 class PLAYERCORE_EXPORT PropertyBag
00208 {
00209         public:
00210                 PropertyBag (void);
00211                 ~PropertyBag (void);
00212 
00213                 bool AddProperty (const char *key, Property *property);
00214                 Property* GetProperty (const char *key);
00215 
00216         private:
00217                 PropertyNode *firstProperty;
00218 };
00219 
00220 #endif // __PROPERTY_H

Last updated 25 May 2011 21:17:00