Crazy Eddie's GUI System  0.8.3
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
PropertySet.h
1 /***********************************************************************
2  filename: CEGUIPropertySet.h
3  created: 21/2/2004
4  author: Paul D Turner
5 
6  purpose: Defines interface for the PropertySet class
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIPropertySet_h_
31 #define _CEGUIPropertySet_h_
32 
33 #include "CEGUI/Base.h"
34 #include "CEGUI/String.h"
35 #include "CEGUI/IteratorBase.h"
36 #include "CEGUI/Property.h"
37 #include "CEGUI/PropertyHelper.h"
38 #include "CEGUI/TypedProperty.h"
39 // not needed in this header but you are likely to use it if you include this,
40 // we also define the CEGUI_DEFINE_PROPERTY macro that relies on this here
41 #include "CEGUI/TplWindowProperty.h"
42 #include "CEGUI/Exceptions.h"
43 #include <map>
44 
45 #if defined(_MSC_VER)
46 # pragma warning(push)
47 # pragma warning(disable : 4251)
48 #endif
49 
50 // Start of CEGUI namespace section
51 namespace CEGUI
52 {
57 class CEGUIEXPORT PropertySet : public PropertyReceiver
58 {
59 public:
64  PropertySet(void) {}
65 
66 
71  virtual ~PropertySet(void) {}
72 
73 
87  void addProperty(Property* property);
88 
89 
100  void removeProperty(const String& name);
101 
102 
113  Property* getPropertyInstance(const String& name) const;
114 
115 
123  void clearProperties(void);
124 
125 
136  bool isPropertyPresent(const String& name) const;
137 
138 
151  const String& getPropertyHelp(const String& name) const;
152 
153 
166  String getProperty(const String& name) const;
167 
174  template<typename T>
175  typename PropertyHelper<T>::return_type getProperty(const String& name) const
176  {
177  PropertyRegistry::const_iterator pos = d_properties.find(name);
178 
179  if (pos == d_properties.end())
180  {
181  CEGUI_THROW(UnknownObjectException("There is no Property named '" + name + "' available in the set."));
182  }
183 
184  Property* baseProperty = pos->second;
185  TypedProperty<T>* typedProperty = dynamic_cast<TypedProperty<T>* >(baseProperty);
186 
187  if (typedProperty)
188  {
189  // yay, we can get native!
190  return typedProperty->getNative(this);
191  }
192  else
193  {
194  // fall back to string get
195  return PropertyHelper<T>::fromString(baseProperty->get(this));
196  }
197  }
198 
215  void setProperty(const String& name, const String& value);
216 
223  template<typename T>
224  void setProperty(const String& name, typename PropertyHelper<T>::pass_type value)
225  {
226  PropertyRegistry::iterator pos = d_properties.find(name);
227 
228  if (pos == d_properties.end())
229  {
230  CEGUI_THROW(UnknownObjectException("There is no Property named '" + name + "' available in the set."));
231  }
232 
233  Property* baseProperty = pos->second;
234  TypedProperty<T>* typedProperty = dynamic_cast<TypedProperty<T>* >(baseProperty);
235 
236  if (typedProperty)
237  {
238  // yay, we can set native!
239  typedProperty->setNative(this, value);
240  }
241  else
242  {
243  // fall back to string set
244  baseProperty->set(this, PropertyHelper<T>::toString(value));
245  }
246  }
247 
259  bool isPropertyDefault(const String& name) const;
260 
261 
272  String getPropertyDefault(const String& name) const;
273 
274 private:
275  typedef std::map<String, Property*, StringFastLessCompare
276  CEGUI_MAP_ALLOC(String, Property*)> PropertyRegistry;
277  PropertyRegistry d_properties;
278 
279 
280 public:
281  /*************************************************************************
282  Iterator stuff
283  *************************************************************************/
284  typedef ConstMapIterator<PropertyRegistry> PropertyIterator;
285 
291  PropertyIterator getPropertyIterator(void) const;
292 };
293 
306 #define CEGUI_DEFINE_PROPERTY(class_type, property_native_type, name, help, setter, getter, default_value)\
307 {\
308  static ::CEGUI::TplWindowProperty<class_type, property_native_type> sProperty(\
309  name, help, propertyOrigin, setter, getter, default_value);\
310  \
311  this->addProperty(&sProperty);\
312 }
313 
328 #define CEGUI_DEFINE_PROPERTY_NO_XML(class_type, property_native_type, name, help, setter, getter, default_value)\
329 {\
330  static ::CEGUI::TplWindowProperty<class_type, property_native_type> sProperty(\
331  name, help, propertyOrigin, setter, getter, default_value, false);\
332  \
333  this->addProperty(&sProperty);\
334 }
335 
336 } // End of CEGUI namespace section
337 
338 #if defined(_MSC_VER)
339 # pragma warning(pop)
340 #endif
341 
342 #endif // end of guard _CEGUIPropertySet_h_