OpenWalnut  1.4.0
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 <string>
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #include "core/common/WPropertyBase.h"
33 
34 /**
35  * \class WPropertyWrapper
36  *
37  * Encapsulates a WProperty. Used to expose the properties to scripts.
38  */
40 {
41 public:
42  /**
43  * Constructor.
44  *
45  * \param prop The property.
46  */
47  explicit WPropertyWrapper( boost::shared_ptr< WPropertyBase > prop );
48 
49  /**
50  * Return the name of the property.
51  *
52  * \return The name of the property.
53  */
54  std::string getName() const;
55 
56  /**
57  * Return the description of the property.
58  *
59  * \return The description of the property.
60  */
61  std::string getDescription() const;
62 
63  /**
64  * Get the value of a boolean property.
65  *
66  * \param notify If true, informs the property that it was read.
67  * \return The current value of the property.
68  */
69  bool getBool( bool notify = false ) const;
70 
71  /**
72  * Get the value of an integer property.
73  *
74  * \param notify If true, informs the property that it was read.
75  * \return The current value of the property.
76  */
77  int getInt( bool notify = false ) const;
78 
79  /**
80  * Get the value of a string property.
81  *
82  * \param notify If true, informs the property that it was read.
83  * \return The current value of the property.
84  */
85  std::string getString( bool notify = false ) const;
86 
87  /**
88  * Get the value of a double property.
89  *
90  * \param notify If true, informs the property that it was read.
91  * \return The current value of the property.
92  */
93  double getDouble( bool notify = false ) const;
94 
95  /**
96  * Get the filename of a filename property.
97  *
98  * \param notify If true, informs the property that it was read.
99  * \return The current value of the property.
100  */
101  std::string getFilename( bool notify = false ) const;
102 
103  /**
104  * Get the (first) selected item of a selection property.
105  *
106  * \param notify If true, informs the property that it was read.
107  * \return The first of the currently selected items.
108  */
109  int getSelection( bool notify = false ) const;
110 
111  /**
112  * Set the value of a boolean property.
113  *
114  * \param b The new value.
115  */
116  void setBool( bool b );
117 
118  /**
119  * Set the value of an integer property.
120  *
121  * \param i The new value.
122  */
123  void setInt( int i );
124 
125  /**
126  * Set the value of a string property.
127  *
128  * \param s The new value.
129  */
130  void setString( std::string const& s );
131 
132  /**
133  * Set the value of a double property.
134  *
135  * \param d The new value.
136  */
137  void setDouble( double d );
138 
139  /**
140  * Set the filename of the filename property.
141  *
142  * \param fn The new value.
143  */
144  void setFilename( std::string const& fn );
145 
146  /**
147  * Sets the selected item of a selection. All other items will be deselected.
148  *
149  * \param s The index of the selected item.
150  */
151  void setSelection( int s );
152 
153  /**
154  * Trigger a trigger property.
155  */
156  void click();
157 
158  /**
159  * Wait for the property to update its value.
160  */
161  void waitForUpdate();
162 
163 private:
164  //! The property.
165  boost::shared_ptr< WPropertyBase > m_prop;
166 };
167 
168 #endif // WPROPERTYWRAPPER_H