Crazy Eddie's GUI System 0.8.7
Loading...
Searching...
No Matches
PropertyDefinition.h
1/***********************************************************************
2 created: Sun Jun 26 2005
3 author: Paul D Turner <paul@cegui.org.uk>
4*************************************************************************/
5/***************************************************************************
6 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 ***************************************************************************/
27#ifndef _CEGUIFalPropertyDefinition_h_
28#define _CEGUIFalPropertyDefinition_h_
29
30#include "CEGUI/falagard/FalagardPropertyBase.h"
31#include "CEGUI/falagard/XMLHandler.h"
32#include "CEGUI/Logger.h"
33
34namespace CEGUI
35{
36template <typename T>
38{
39public:
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),
51 {
52 }
53
54 //------------------------------------------------------------------------//
56
57 //------------------------------------------------------------------------//
59 {
60 setWindowUserString(static_cast<Window*>(receiver), FalagardPropertyBase<T>::d_initialValue);
61 }
62
63 //------------------------------------------------------------------------//
64 Property* clone() const
65 {
66 return CEGUI_NEW_AO PropertyDefinition<T>(*this);
67 }
68
69protected:
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, FalagardPropertyBase<T>::d_initialValue);
99
100 return Helper::fromString(FalagardPropertyBase<T>::d_initialValue);
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 {
121 writeDefinitionXMLAdditionalAttributes(xml_stream);
122 }
123 //------------------------------------------------------------------------//
124 void writeDefinitionXMLAdditionalAttributes(XMLSerializer& xml_stream) const
125 {
128
131 }
132
133
134 //------------------------------------------------------------------------//
135
136 String d_userStringName;
137};
138
139}
140
141#endif
142
Definition FalagardPropertyBase.h:37
static const String GenericDataType
Default or unspecified value for the "dataType" attribute.
Definition falagard/XMLHandler.h:89
static const String HelpStringAttribute
Attribute name that stores a help string.
Definition falagard/XMLHandler.h:179
static const String PropertyDefinitionElement
Tag name for property definition elements.
Definition falagard/XMLHandler.h:129
static const String PropertyDefinitionHelpDefaultValue
Default value for the "type" attribute of PropertyDefinition elements.
Definition falagard/XMLHandler.h:83
static const String TypeAttribute
Attribute name that stores a type string.
Definition falagard/XMLHandler.h:152
static const String UserStringNameSuffix
The PropertyDefinition's user string name suffix, which is appended to each #d_userStringName.
Definition PropertyDefinitionBase.h:84
Definition PropertyDefinition.h:38
void initialisePropertyReceiver(PropertyReceiver *receiver) const
function to allow initialisation of a PropertyReceiver.
Definition PropertyDefinition.h:58
void writeDefinitionXMLElementType(XMLSerializer &xml_stream) const
Write out the text of the XML element type. Note that you should not write the opening '<' character,...
Definition PropertyDefinition.h:118
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
An abstract class that defines the interface to access object properties by name.
Definition Property.h:62
String class used within the GUI system.
Definition String.h:64
An abstract base class providing common functionality and specifying the required interface for deriv...
Definition Window.h:151
Class used to create XML Document.
Definition XMLSerializer.h:87
XMLSerializer & attribute(const String &name, const String &value)
After an opening tag you can populate attribute list with this function.
XMLSerializer & openTag(const String &name)
Start a new tag in the xml document.
Main namespace for Crazy Eddie's GUI Library.
Definition arch_overview.dox:1