OpenWalnut  1.4.0
WPropertyWrapper.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WPROPERTYWRAPPER_H
00026 #define WPROPERTYWRAPPER_H
00027 
00028 #include <string>
00029 
00030 #include <boost/shared_ptr.hpp>
00031 
00032 #include "core/common/WPropertyBase.h"
00033 
00034 /**
00035  * \class WPropertyWrapper
00036  *
00037  * Encapsulates a WProperty. Used to expose the properties to scripts.
00038  */
00039 class WPropertyWrapper
00040 {
00041 public:
00042     /**
00043      * Constructor.
00044      *
00045      * \param prop The property.
00046      */
00047     explicit WPropertyWrapper( boost::shared_ptr< WPropertyBase > prop );
00048 
00049     /**
00050      * Return the name of the property.
00051      *
00052      * \return The name of the property.
00053      */
00054     std::string getName() const;
00055 
00056     /**
00057      * Return the description of the property.
00058      *
00059      * \return The description of the property.
00060      */
00061     std::string getDescription() const;
00062 
00063     /**
00064      * Get the value of a boolean property.
00065      *
00066      * \param notify If true, informs the property that it was read.
00067      * \return The current value of the property.
00068      */
00069     bool getBool( bool notify = false ) const;
00070 
00071     /**
00072      * Get the value of an integer property.
00073      *
00074      * \param notify If true, informs the property that it was read.
00075      * \return The current value of the property.
00076      */
00077     int getInt( bool notify = false ) const;
00078 
00079     /**
00080      * Get the value of a string property.
00081      *
00082      * \param notify If true, informs the property that it was read.
00083      * \return The current value of the property.
00084      */
00085     std::string getString( bool notify = false ) const;
00086 
00087     /**
00088      * Get the value of a double property.
00089      *
00090      * \param notify If true, informs the property that it was read.
00091      * \return The current value of the property.
00092      */
00093     double getDouble( bool notify = false ) const;
00094 
00095     /**
00096      * Get the filename of a filename property.
00097      *
00098      * \param notify If true, informs the property that it was read.
00099      * \return The current value of the property.
00100      */
00101     std::string getFilename( bool notify = false ) const;
00102 
00103     /**
00104      * Get the (first) selected item of a selection property.
00105      *
00106      * \param notify If true, informs the property that it was read.
00107      * \return The first of the currently selected items.
00108      */
00109     int getSelection( bool notify = false ) const;
00110 
00111     /**
00112      * Set the value of a boolean property.
00113      *
00114      * \param b The new value.
00115      */
00116     void setBool( bool b );
00117 
00118     /**
00119      * Set the value of an integer property.
00120      *
00121      * \param i The new value.
00122      */
00123     void setInt( int i );
00124 
00125     /**
00126      * Set the value of a string property.
00127      *
00128      * \param s The new value.
00129      */
00130     void setString( std::string const& s );
00131 
00132     /**
00133      * Set the value of a double property.
00134      *
00135      * \param d The new value.
00136      */
00137     void setDouble( double d );
00138 
00139     /**
00140      * Set the filename of the filename property.
00141      *
00142      * \param fn The new value.
00143      */
00144     void setFilename( std::string const& fn );
00145 
00146     /**
00147      * Sets the selected item of a selection. All other items will be deselected.
00148      *
00149      * \param s The index of the selected item.
00150      */
00151     void setSelection( int s );
00152 
00153     /**
00154      * Trigger a trigger property.
00155      */
00156     void click();
00157 
00158     /**
00159      * Wait for the property to update its value.
00160      */
00161     void waitForUpdate();
00162 
00163 private:
00164     //! The property.
00165     boost::shared_ptr< WPropertyBase > m_prop;
00166 };
00167 
00168 #endif  // WPROPERTYWRAPPER_H