Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
PropertyDefinition.h
1 /***********************************************************************
2  filename: CEGUIPropertyDefinition.h
3  created: Sun Jun 26 2005
4  author: Paul D Turner <paul@cegui.org.uk>
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef _CEGUIFalPropertyDefinition_h_
29 #define _CEGUIFalPropertyDefinition_h_
30 
31 #include "CEGUI/falagard/FalagardPropertyBase.h"
32 #include "CEGUI/Logger.h"
33 
34 namespace CEGUI
35 {
36 template <typename T>
38 {
39 public:
40  typedef typename TypedProperty<T>::Helper Helper;
41 
42  //------------------------------------------------------------------------//
43  PropertyDefinition(const String& name, const String& initialValue,
44  const String& help, const String& origin,
45  bool redrawOnWrite, bool layoutOnWrite,
46  const String& fireEvent, const String& eventNamespace) :
47  FalagardPropertyBase<T>(name, help, initialValue, origin,
48  redrawOnWrite, layoutOnWrite,
49  fireEvent, eventNamespace),
50  d_userStringName(name + "_fal_auto_prop__")
51  {
52  }
53 
54  //------------------------------------------------------------------------//
55  ~PropertyDefinition() {}
56 
57  //------------------------------------------------------------------------//
59  {
60  setWindowUserString(static_cast<Window*>(receiver), this->d_default);
61  }
62 
63  //------------------------------------------------------------------------//
64  Property* clone() const
65  {
66  return CEGUI_NEW_AO PropertyDefinition<T>(*this);
67  }
68 
69 protected:
70  //------------------------------------------------------------------------//
71  typename Helper::safe_method_return_type
72  getNative_impl(const PropertyReceiver* receiver) const
73  {
74  const Window* const wnd = static_cast<const Window*>(receiver);
75 
76  // the try/catch is used instead of querying the existence of the user
77  // string in order that for the 'usual' case - where the user string
78  // exists - there is basically no additional overhead, and that any
79  // overhead is incurred only for the initial creation of the user
80  // string.
81  // Maybe the only negative here is that an error gets logged, though
82  // this can be treated as a 'soft' error.
83  CEGUI_TRY
84  {
85  return Helper::fromString(wnd->getUserString(d_userStringName));
86  }
87  CEGUI_CATCH (UnknownObjectException&)
88  {
89  Logger::getSingleton().logEvent(
90  "PropertyDefiniton::get: Defining new user string: " +
91  d_userStringName);
92 
93  // HACK: FIXME: TODO: This const_cast is basically to allow the
94  // above mentioned performance measure; the alternative would be
95  // to just return d_default, and while technically correct, it
96  // would be very slow.
97  const_cast<Window*>(wnd)->
98  setUserString(d_userStringName, TypedProperty<T>::d_default);
99 
100  return Helper::fromString(TypedProperty<T>::d_default);
101  }
102  }
103 
104  //------------------------------------------------------------------------//
105  void setNative_impl(PropertyReceiver* receiver,typename Helper::pass_type value)
106  {
107  setWindowUserString(static_cast<Window*>(receiver), Helper::toString(value));
108  FalagardPropertyBase<T>::setNative_impl(receiver, value);
109  }
110 
111  //------------------------------------------------------------------------//
112  void setWindowUserString(Window* window, const String& value) const
113  {
114  window->setUserString(d_userStringName, value);
115  }
116 
117  //------------------------------------------------------------------------//
119  {
120  xml_stream.openTag("PropertyDefinition");
121  }
122 
123  //------------------------------------------------------------------------//
124 
125  String d_userStringName;
126 };
127 
128 }
129 
130 #endif
131