Crazy Eddie's GUI System 0.8.7
Loading...
Searching...
No Matches
PropertySet.h
1/***********************************************************************
2 created: 21/2/2004
3 author: Paul D Turner
4
5 purpose: Defines interface for the PropertySet class
6*************************************************************************/
7/***************************************************************************
8 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 ***************************************************************************/
29#ifndef _CEGUIPropertySet_h_
30#define _CEGUIPropertySet_h_
31
32#include "CEGUI/Base.h"
33#include "CEGUI/String.h"
34#include "CEGUI/IteratorBase.h"
35#include "CEGUI/Property.h"
36#include "CEGUI/PropertyHelper.h"
37#include "CEGUI/TypedProperty.h"
38// not needed in this header but you are likely to use it if you include this,
39// we also define the CEGUI_DEFINE_PROPERTY macro that relies on this here
40#include "CEGUI/TplWindowProperty.h"
41#include "CEGUI/Exceptions.h"
42#include <map>
43
44#if defined(_MSC_VER)
45# pragma warning(push)
46# pragma warning(disable : 4251)
47#endif
48
49// Start of CEGUI namespace section
50namespace CEGUI
51{
107class CEGUIEXPORT PropertySet : public PropertyReceiver
108{
109public:
114 PropertySet(void) {}
115
116
121 virtual ~PropertySet(void) {}
122
123
138 void addProperty(Property* property);
139
140
148 void removeProperty(const String& name);
149
150
162
163
168 void clearProperties(void);
169
170
181 bool isPropertyPresent(const String& name) const;
182
183
196 const String& getPropertyHelp(const String& name) const;
197
198
211 String getProperty(const String& name) const;
212
219 template<typename T>
221 {
222 PropertyRegistry::const_iterator pos = d_properties.find(name);
223
224 if (pos == d_properties.end())
225 {
226 CEGUI_THROW(UnknownObjectException("There is no Property named '" + name + "' available in the set."));
227 }
228
229 Property* baseProperty = pos->second;
230 TypedProperty<T>* typedProperty = dynamic_cast<TypedProperty<T>* >(baseProperty);
231
232 if (typedProperty)
233 {
234 // yay, we can get native!
235 return typedProperty->getNative(this);
236 }
237 else
238 {
239 // fall back to string get
240 return PropertyHelper<T>::fromString(baseProperty->get(this));
241 }
242 }
243
257 void setProperty(const String& name, const String& value);
258
265 template<typename T>
266 void setProperty(const String& name, typename PropertyHelper<T>::pass_type value)
267 {
268 PropertyRegistry::iterator pos = d_properties.find(name);
269
270 if (pos == d_properties.end())
271 {
272 CEGUI_THROW(UnknownObjectException("There is no Property named '" + name + "' available in the set."));
273 }
274
275 Property* baseProperty = pos->second;
276 TypedProperty<T>* typedProperty = dynamic_cast<TypedProperty<T>* >(baseProperty);
277
278 if (typedProperty)
279 {
280 // yay, we can set native!
281 typedProperty->setNative(this, value);
282 }
283 else
284 {
285 // fall back to string set
286 baseProperty->set(this, PropertyHelper<T>::toString(value));
287 }
288 }
289
301 bool isPropertyDefault(const String& name) const;
302
303
314 String getPropertyDefault(const String& name) const;
315
316private:
317 typedef std::map<String, Property*, StringFastLessCompare
318 CEGUI_MAP_ALLOC(String, Property*)> PropertyRegistry;
319 PropertyRegistry d_properties;
320
321
322public:
323 /*************************************************************************
324 Iterator stuff
325 *************************************************************************/
327
334};
335
352#define CEGUI_DEFINE_PROPERTY(class_type, property_native_type, name, help, setter, getter, default_value)\
353{\
354 static ::CEGUI::TplWindowProperty<class_type, property_native_type> sProperty(\
355 name, help, propertyOrigin, setter, getter, default_value);\
356 \
357 this->addProperty(&sProperty);\
358}
359
381#define CEGUI_DEFINE_PROPERTY_NO_XML(class_type, property_native_type, name, help, setter, getter, default_value)\
382{\
383 static ::CEGUI::TplWindowProperty<class_type, property_native_type> sProperty(\
384 name, help, propertyOrigin, setter, getter, default_value, false);\
385 \
386 this->addProperty(&sProperty);\
387}
388
389} // End of CEGUI namespace section
390
391#if defined(_MSC_VER)
392# pragma warning(pop)
393#endif
394
395#endif // end of guard _CEGUIPropertySet_h_
iterator class for maps
Definition IteratorBase.h:197
Helper class used to convert various data types to and from the format expected in Property strings.
Definition PropertyHelper.h:84
Dummy base class to ensure correct casting of receivers.
Definition Property.h:46
Interface providing introspection capabilities.
Definition PropertySet.h:108
PropertySet(void)
Constructs a new PropertySet object.
Definition PropertySet.h:114
void removeProperty(const String &name)
Removes a Property from the PropertySet.
PropertyIterator getPropertyIterator(void) const
Return a PropertySet::PropertyIterator object to iterate over the available Properties.
void setProperty(const String &name, typename PropertyHelper< T >::pass_type value)
Sets the current value of a Property.
Definition PropertySet.h:266
String getPropertyDefault(const String &name) const
Returns the default value of a Property as a String.
void addProperty(Property *property)
Adds a new Property to the PropertySet.
bool isPropertyDefault(const String &name) const
Returns whether a Property is at it's default value.
virtual ~PropertySet(void)
Destructor for PropertySet objects.
Definition PropertySet.h:121
void clearProperties(void)
Removes all Property objects from the PropertySet.
Property * getPropertyInstance(const String &name) const
Retrieves a property instance (that was previously added)
bool isPropertyPresent(const String &name) const
Checks to see if a Property with the given name is in the PropertySet.
const String & getPropertyHelp(const String &name) const
Return the help text for the specified Property.
PropertyHelper< T >::return_type getProperty(const String &name) const
Gets the current value of the specified Property.
Definition PropertySet.h:220
String getProperty(const String &name) const
Gets the current value of the specified Property.
void setProperty(const String &name, const String &value)
Sets the current value of a Property.
An abstract class that defines the interface to access object properties by name.
Definition Property.h:62
virtual String get(const PropertyReceiver *receiver) const =0
Return the current value of the Property as a String.
virtual void set(PropertyReceiver *receiver, const String &value)=0
Sets the value of the property.
String class used within the GUI system.
Definition String.h:64
base class for properties able to do native set/get
Definition TypedProperty.h:50
virtual void setNative(PropertyReceiver *receiver, typename Helper::pass_type value)
native set method, sets the property given a native type
Definition TypedProperty.h:80
virtual Helper::safe_method_return_type getNative(const PropertyReceiver *receiver) const
native get method, returns the native type by copy
Definition TypedProperty.h:92
Exception class used when a request was made for an unknown object.
Definition Exceptions.h:247
Main namespace for Crazy Eddie's GUI Library.
Definition arch_overview.dox:1
Functor that can be used as comparator in a std::map with String keys. It's faster than using the def...
Definition String.h:5580