property.h
1/*
2 * Player - One Hell of a Robot Server
3 * Copyright (C) 2000
4 * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22/********************************************************************
23 *
24 * This library is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU Lesser General Public
26 * License as published by the Free Software Foundation; either
27 * version 2.1 of the License, or (at your option) any later version.
28 *
29 * This library is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 * Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public
35 * License along with this library; if not, write to the Free Software
36 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 *
38 ********************************************************************/
39
40#ifndef __PROPERTY_H
41#define __PROPERTY_H
42
43#if defined (WIN32)
44 #if defined (PLAYER_STATIC)
45 #define PLAYERCORE_EXPORT
46 #elif defined (playercore_EXPORTS)
47 #define PLAYERCORE_EXPORT __declspec (dllexport)
48 #else
49 #define PLAYERCORE_EXPORT __declspec (dllimport)
50 #endif
51#else
52 #define PLAYERCORE_EXPORT
53#endif
54
55class ConfigFile;
56class Driver;
57
59class PLAYERCORE_EXPORT Property
60{
61 public:
62 Property (void);
63 Property (const char *newKey, bool readOnly);
64 virtual ~Property (void);
65
66 // Accessor functions
67 virtual const char* GetKey (void) const { return key; }
68 virtual void SetKey (const char *newKey);
69 virtual void GetValueToMessage (void *data) const = 0;
70 virtual void SetValueFromMessage (const void *data) = 0;
71
72 virtual bool KeyIsEqual (const char *rhs);
73
74 // Config file read method
75 virtual bool ReadConfig (ConfigFile *cf, int section) = 0;
76
77 protected:
78 char *key; // Key for this property
79 bool readonly; // true if this property is read-only
80};
81
84
86class PLAYERCORE_EXPORT BoolProperty : public Property
87{
88 public:
89 BoolProperty (const char *newKey, bool newValue, bool readOnly);
91 BoolProperty (const char *newKey, bool newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
92
93 bool GetValue (void) const { return value; }
94 void SetValue (bool newValue);
95 void GetValueToMessage (void *data) const;
96 void SetValueFromMessage (const void *data);
97
98 // Config file read method
99 virtual bool ReadConfig (ConfigFile *cf, int section);
100
101 // Operators
102 operator bool (void) { return value; }
103 const BoolProperty& operator= (const BoolProperty &rhs);
104 bool operator= (bool rhs);
105
106 private:
107 bool value;
108};
109
112
114class PLAYERCORE_EXPORT IntProperty : public Property
115{
116 public:
117 IntProperty (const char *newKey, int newValue, bool readOnly);
119 IntProperty (const char *newKey, int newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
120
121 int GetValue (void) const { return value; }
122 void SetValue (int newValue);
123 void GetValueToMessage (void *data) const;
124 void SetValueFromMessage (const void *data);
125
126 // Config file read method
127 virtual bool ReadConfig (ConfigFile *cf, int section);
128
129 // Operators
130 operator int (void) { return value; }
131 const IntProperty& operator= (const IntProperty &rhs);
132 int operator= (int rhs);
133
134 private:
135 int value;
136};
137
140
142class PLAYERCORE_EXPORT DoubleProperty : public Property
143{
144 public:
145 DoubleProperty (const char *newKey, double newValue, bool readOnly);
147 DoubleProperty (const char *newKey, double newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
148
149 double GetValue (void) const { return value; }
150 void SetValue (double newValue);
151 void GetValueToMessage (void *data) const;
152 void SetValueFromMessage (const void *data);
153
154 // Config file read method
155 virtual bool ReadConfig (ConfigFile *cf, int section);
156
157 // Operators
158 operator double (void) { return value; }
159 const DoubleProperty& operator= (const DoubleProperty &rhs);
160 double operator= (double rhs);
161
162 private:
163 double value;
164};
165
168
170class PLAYERCORE_EXPORT StringProperty : public Property
171{
172 public:
173 StringProperty (const char *newKey, const char *newValue, bool readOnly);
175 StringProperty (const char *newKey, const char *newValue, bool readOnly, Driver * driver, ConfigFile*cf, int section);
176 ~StringProperty (void);
177
178 const char* GetValue (void) const { return value; }
179 void SetValue (const char *newValue);
180 void GetValueToMessage (void *data) const;
181 void SetValueFromMessage (const void *data);
182
183 // Config file read method
184 virtual bool ReadConfig (ConfigFile *cf, int section);
185
186 // Operators
187 operator const char* (void) { return value; }
188 const StringProperty& operator= (const StringProperty &rhs);
189 const char* operator= (const char* rhs);
190
191 private:
192 char *value;
193};
194
197
199typedef struct PropertyNode
200{
201 char *key;
202 Property *property;
203 struct PropertyNode *next;
205
207class PLAYERCORE_EXPORT PropertyBag
208{
209 public:
210 PropertyBag (void);
211 ~PropertyBag (void);
212
213 bool AddProperty (const char *key, Property *property);
214 Property* GetProperty (const char *key);
215
216 private:
217 PropertyNode *firstProperty;
218};
219
220#endif // __PROPERTY_H
Boolean property class.
Definition property.h:87
BoolProperty(const char *newKey, bool newValue, bool readOnly, Driver *driver, ConfigFile *cf, int section)
Constructor that registers the property with a driver as well while it is constructed.
Class for loading configuration file information.
Definition configfile.h:197
Double property class.
Definition property.h:143
DoubleProperty(const char *newKey, double newValue, bool readOnly, Driver *driver, ConfigFile *cf, int section)
Constructor that registers the property with a driver as well while it is constructed.
Base class for all drivers.
Definition driver.h:109
Integer property class.
Definition property.h:115
IntProperty(const char *newKey, int newValue, bool readOnly, Driver *driver, ConfigFile *cf, int section)
Constructor that registers the property with a driver as well while it is constructed.
Property bag class: stores registered properties.
Definition property.h:208
Property base class.
Definition property.h:60
String Property Class.
Definition property.h:171
StringProperty(const char *newKey, const char *newValue, bool readOnly, Driver *driver, ConfigFile *cf, int section)
Constructor that registers the property with a driver as well while it is constructed.
Property node structure.
Definition property.h:200