OpenWalnut  1.5.0dev
WPropertyWrapper.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WPROPERTYWRAPPER_H
26 #define WPROPERTYWRAPPER_H
27 
28 #include <memory>
29 #include <string>
30 
31 
32 #include "WColorWrapper.h"
33 #include "core/common/WPropertyBase.h"
34 
35 /**
36  * \class WPropertyWrapper
37  *
38  * Encapsulates a WProperty. Used to expose the properties to scripts.
39  */
41 {
42 public:
43  /**
44  * Constructor.
45  *
46  * \param prop The property.
47  */
48  explicit WPropertyWrapper( std::shared_ptr< WPropertyBase > prop );
49 
50  /**
51  * Return the name of the property.
52  *
53  * \return The name of the property.
54  */
55  std::string getName() const;
56 
57  /**
58  * Return the description of the property.
59  *
60  * \return The description of the property.
61  */
62  std::string getDescription() const;
63 
64  /**
65  * Get the value of a boolean property.
66  *
67  * \param notify If true, informs the property that it was read.
68  * \return The current value of the property.
69  */
70  bool getBool( bool notify = false ) const;
71 
72  /**
73  * Get the value of an integer property.
74  *
75  * \param notify If true, informs the property that it was read.
76  * \return The current value of the property.
77  */
78  int getInt( bool notify = false ) const;
79 
80  /**
81  * Get the value of a string property.
82  *
83  * \param notify If true, informs the property that it was read.
84  * \return The current value of the property.
85  */
86  std::string getString( bool notify = false ) const;
87 
88  /**
89  * Get the value of a double property.
90  *
91  * \param notify If true, informs the property that it was read.
92  * \return The current value of the property.
93  */
94  double getDouble( bool notify = false ) const;
95 
96  /**
97  * Get the filename of a filename property.
98  *
99  * \param notify If true, informs the property that it was read.
100  * \return The current value of the property.
101  */
102  std::string getFilename( bool notify = false ) const;
103 
104  /**
105  * Get the (first) selected item of a selection property.
106  *
107  * \param notify If true, informs the property that it was read.
108  * \return The first of the currently selected items.
109  */
110  int getSelection( bool notify = false ) const;
111 
112  /**
113  * Get the color of a color property.
114  *
115  * \param notify If true, informs the property that it was read.
116  *
117  * \return The color of the property.
118  */
119  WColorWrapper getColor( bool notify = false ) const;
120 
121  /**
122  * Set the value of a boolean property.
123  *
124  * \param b The new value.
125  */
126  void setBool( bool b );
127 
128  /**
129  * Set the value of an integer property.
130  *
131  * \param i The new value.
132  */
133  void setInt( int i );
134 
135  /**
136  * Set the value of a string property.
137  *
138  * \param s The new value.
139  */
140  void setString( std::string const& s );
141 
142  /**
143  * Set the value of a double property.
144  *
145  * \param d The new value.
146  */
147  void setDouble( double d );
148 
149  /**
150  * Set the filename of the filename property.
151  *
152  * \param fn The new value.
153  */
154  void setFilename( std::string const& fn );
155 
156  /**
157  * Sets the selected item of a selection. All other items will be deselected.
158  *
159  * \param s The index of the selected item.
160  */
161  void setSelection( int s );
162 
163  /**
164  * Set the color of a color property.
165  *
166  * \param col The new color.
167  */
168  void setColor( WColorWrapper col );
169 
170  /**
171  * Trigger a trigger property.
172  */
173  void click();
174 
175  /**
176  * Wait for the property to update its value.
177  */
178  void waitForUpdate();
179 
180 private:
181  //! The property.
182  std::shared_ptr< WPropertyBase > m_prop;
183 };
184 
185 #endif // WPROPERTYWRAPPER_H
Wraps the WColor class for scripts.
Definition: WColorWrapper.h:34
Encapsulates a WProperty.
std::shared_ptr< WPropertyBase > m_prop
The property.
std::string getName() const
Return the name of the property.
void setColor(WColorWrapper col)
Set the color of a color property.
void click()
Trigger a trigger property.
void setInt(int i)
Set the value of an integer property.
std::string getString(bool notify=false) const
Get the value of a string property.
std::string getDescription() const
Return the description of the property.
void setString(std::string const &s)
Set the value of a string property.
void setBool(bool b)
Set the value of a boolean property.
WPropertyWrapper(std::shared_ptr< WPropertyBase > prop)
Constructor.
void waitForUpdate()
Wait for the property to update its value.
bool getBool(bool notify=false) const
Get the value of a boolean property.
std::string getFilename(bool notify=false) const
Get the filename of a filename property.
void setFilename(std::string const &fn)
Set the filename of the filename property.
double getDouble(bool notify=false) const
Get the value of a double property.
WColorWrapper getColor(bool notify=false) const
Get the color of a color property.
int getSelection(bool notify=false) const
Get the (first) selected item of a selection property.
void setSelection(int s)
Sets the selected item of a selection.
int getInt(bool notify=false) const
Get the value of an integer property.
void setDouble(double d)
Set the value of a double property.