Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
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
50 namespace CEGUI
51 {
56 class CEGUIEXPORT PropertySet : public PropertyReceiver
57 {
58 public:
63  PropertySet(void) {}
64 
65 
70  virtual ~PropertySet(void) {}
71 
72 
86  void addProperty(Property* property);
87 
88 
99  void removeProperty(const String& name);
100 
101 
112  Property* getPropertyInstance(const String& name) const;
113 
114 
122  void clearProperties(void);
123 
124 
135  bool isPropertyPresent(const String& name) const;
136 
137 
150  const String& getPropertyHelp(const String& name) const;
151 
152 
165  String getProperty(const String& name) const;
166 
173  template<typename T>
174  typename PropertyHelper<T>::return_type getProperty(const String& name) const
175  {
176  PropertyRegistry::const_iterator pos = d_properties.find(name);
177 
178  if (pos == d_properties.end())
179  {
180  CEGUI_THROW(UnknownObjectException("There is no Property named '" + name + "' available in the set."));
181  }
182 
183  Property* baseProperty = pos->second;
184  TypedProperty<T>* typedProperty = dynamic_cast<TypedProperty<T>* >(baseProperty);
185 
186  if (typedProperty)
187  {
188  // yay, we can get native!
189  return typedProperty->getNative(this);
190  }
191  else
192  {
193  // fall back to string get
194  return PropertyHelper<T>::fromString(baseProperty->get(this));
195  }
196  }
197 
214  void setProperty(const String& name, const String& value);
215 
222  template<typename T>
223  void setProperty(const String& name, typename PropertyHelper<T>::pass_type value)
224  {
225  PropertyRegistry::iterator pos = d_properties.find(name);
226 
227  if (pos == d_properties.end())
228  {
229  CEGUI_THROW(UnknownObjectException("There is no Property named '" + name + "' available in the set."));
230  }
231 
232  Property* baseProperty = pos->second;
233  TypedProperty<T>* typedProperty = dynamic_cast<TypedProperty<T>* >(baseProperty);
234 
235  if (typedProperty)
236  {
237  // yay, we can set native!
238  typedProperty->setNative(this, value);
239  }
240  else
241  {
242  // fall back to string set
243  baseProperty->set(this, PropertyHelper<T>::toString(value));
244  }
245  }
246 
258  bool isPropertyDefault(const String& name) const;
259 
260 
271  String getPropertyDefault(const String& name) const;
272 
273 private:
274  typedef std::map<String, Property*, StringFastLessCompare
275  CEGUI_MAP_ALLOC(String, Property*)> PropertyRegistry;
276  PropertyRegistry d_properties;
277 
278 
279 public:
280  /*************************************************************************
281  Iterator stuff
282  *************************************************************************/
283  typedef ConstMapIterator<PropertyRegistry> PropertyIterator;
284 
290  PropertyIterator getPropertyIterator(void) const;
291 };
292 
305 #define CEGUI_DEFINE_PROPERTY(class_type, property_native_type, name, help, setter, getter, default_value)\
306 {\
307  static ::CEGUI::TplWindowProperty<class_type, property_native_type> sProperty(\
308  name, help, propertyOrigin, setter, getter, default_value);\
309  \
310  this->addProperty(&sProperty);\
311 }
312 
327 #define CEGUI_DEFINE_PROPERTY_NO_XML(class_type, property_native_type, name, help, setter, getter, default_value)\
328 {\
329  static ::CEGUI::TplWindowProperty<class_type, property_native_type> sProperty(\
330  name, help, propertyOrigin, setter, getter, default_value, false);\
331  \
332  this->addProperty(&sProperty);\
333 }
334 
335 } // End of CEGUI namespace section
336 
337 #if defined(_MSC_VER)
338 # pragma warning(pop)
339 #endif
340 
341 #endif // end of guard _CEGUIPropertySet_h_