Crazy Eddie's GUI System  0.8.7
FormattingSetting.h
1 /***********************************************************************
2  created: Fri Jun 15 2012
3  author: Paul D Turner <paul@cegui.org.uk>
4 *************************************************************************/
5 /***************************************************************************
6  * Copyright (C) 2004 - 2012 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 _CEGUIFormattingSetting_h_
28 #define _CEGUIFormattingSetting_h_
29 
30 #include "CEGUI/Window.h"
31 #include "CEGUI/falagard/XMLEnumHelper.h"
32 
33 namespace CEGUI
34 {
35 
36 template<typename T>
38 {
39 public:
40  //------------------------------------------------------------------------//
43  {}
44 
45  //------------------------------------------------------------------------//
46  FormattingSetting(const String& property_name) :
48  d_propertySource(property_name)
49  {}
50 
51  //------------------------------------------------------------------------//
52  FormattingSetting(T val) :
53  d_value(val)
54  {}
55 
56  //------------------------------------------------------------------------//
57  T get(const Window& wnd) const
58  {
59  if (d_propertySource.empty())
60  return d_value;
61 
63  wnd.getProperty(d_propertySource));
64  }
65 
66  //------------------------------------------------------------------------//
67  void set(T val)
68  {
69  d_value = val;
70  d_propertySource.clear();
71  }
72 
73  //------------------------------------------------------------------------//
74  T getValue() const
75  {
76  return d_value;
77  }
78 
79  //------------------------------------------------------------------------//
80  const String& getPropertySource() const
81  {
82  return d_propertySource;
83  }
84 
85  //------------------------------------------------------------------------//
86  void setPropertySource(const String& property_name)
87  {
88  d_propertySource = property_name;
89  }
90 
91  //------------------------------------------------------------------------//
92  bool isFetchedFromProperty() const
93  {
94  return !d_propertySource.empty();
95  }
96 
97  //------------------------------------------------------------------------//
98  void writeXMLToStream(XMLSerializer& xml_stream) const
99  {
100  writeXMLTagToStream(xml_stream);
101  writeXMLAttributesToStream(xml_stream);
102  xml_stream.closeTag();
103  }
104 
105  //------------------------------------------------------------------------//
106  virtual void writeXMLTagToStream(XMLSerializer& /*xml_stream*/) const
107  {
108  // This does nothing and needs to be specialised or overridden
109  }
110 
111  //------------------------------------------------------------------------//
112  virtual void writeXMLAttributesToStream(XMLSerializer& /*xml_stream*/) const
113  {
114  // This does nothing and needs to be specialised or overridden
115  }
116 
117  //------------------------------------------------------------------------//
118  bool operator==(const FormattingSetting<T>& rhs) const
119  {
120  return d_value == rhs.d_value &&
121  d_propertySource == rhs.d_propertySource;
122  }
123 
124  //------------------------------------------------------------------------//
125  bool operator!=(const FormattingSetting<T>& rhs) const
126  {
127  return !operator==(rhs);
128  }
129 
130 protected:
131  T d_value;
132  String d_propertySource;
133 };
134 
136  XMLSerializer& xml_stream) const;
138  XMLSerializer& xml_stream) const;
140  XMLSerializer& xml_stream) const;
142  XMLSerializer& xml_stream) const;
144  XMLSerializer& xml_stream) const;
146  XMLSerializer& xml_stream) const;
148  XMLSerializer& xml_stream) const;
150  XMLSerializer& xml_stream) const;
151 }
152 
153 #endif
154 
Definition: FormattingSetting.h:37
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
bool empty(void) const
Returns true if the String is empty.
Definition: String.h:633
Definition: XMLEnumHelper.h:37
XMLSerializer & closeTag(void)
Close the current tag.
An abstract base class providing common functionality and specifying the required interface for deriv...
Definition: Window.h:149
Class used to create XML Document.
Definition: XMLSerializer.h:85
void clear(void)
Removes all data from the String.
Definition: String.h:2348
String class used within the GUI system.
Definition: String.h:62