property.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
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
00075 virtual bool ReadConfig (ConfigFile *cf, int section) = 0;
00076
00077 protected:
00078 char *key;
00079 bool readonly;
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
00099 virtual bool ReadConfig (ConfigFile *cf, int section);
00100
00101
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
00127 virtual bool ReadConfig (ConfigFile *cf, int section);
00128
00129
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
00155 virtual bool ReadConfig (ConfigFile *cf, int section);
00156
00157
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
00184 virtual bool ReadConfig (ConfigFile *cf, int section);
00185
00186
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