OpenWalnut  1.4.0
WPropertyWrapper.cpp
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 #include <string>
00026 #include <boost/shared_ptr.hpp>
00027 
00028 #include "core/common/WProperties.h"
00029 
00030 #include "WPropertyWrapper.h"
00031 
00032 WPropertyWrapper::WPropertyWrapper( boost::shared_ptr< WPropertyBase > prop )
00033     : m_prop( prop )
00034 {
00035 }
00036 
00037 std::string WPropertyWrapper::getName() const
00038 {
00039     return m_prop->getName();
00040 }
00041 
00042 std::string WPropertyWrapper::getDescription() const
00043 {
00044     return m_prop->getDescription();
00045 }
00046 
00047 bool WPropertyWrapper::getBool( bool notify ) const
00048 {
00049     return m_prop->toPropBool()->get( notify );
00050 }
00051 
00052 int WPropertyWrapper::getInt( bool notify ) const
00053 {
00054     return m_prop->toPropInt()->get( notify );
00055 }
00056 
00057 std::string WPropertyWrapper::getString( bool notify ) const
00058 {
00059     return m_prop->toPropString()->get( notify );
00060 }
00061 
00062 double WPropertyWrapper::getDouble( bool notify ) const
00063 {
00064     return m_prop->toPropDouble()->get( notify );
00065 }
00066 
00067 std::string WPropertyWrapper::getFilename( bool notify ) const
00068 {
00069     return m_prop->toPropFilename()->get( notify ).string();
00070 }
00071 
00072 int WPropertyWrapper::getSelection( bool notify ) const
00073 {
00074     return static_cast< int >( m_prop->toPropSelection()->get( notify ).getItemIndexOfSelected( 0 ) );
00075 }
00076 
00077 void WPropertyWrapper::setBool( bool b )
00078 {
00079     m_prop->toPropBool()->set( b, false );
00080 }
00081 
00082 void WPropertyWrapper::setInt( int i )
00083 {
00084     m_prop->toPropInt()->set( i, false );
00085 }
00086 
00087 void WPropertyWrapper::setString( std::string const& s )
00088 {
00089     m_prop->toPropString()->set( s, false );
00090 }
00091 
00092 void WPropertyWrapper::setDouble( double d )
00093 {
00094     m_prop->toPropDouble()->set( d, false );
00095 }
00096 
00097 void WPropertyWrapper::setFilename( std::string const& fn )
00098 {
00099     m_prop->toPropFilename()->set( boost::filesystem::path( fn ), false );
00100 }
00101 
00102 void WPropertyWrapper::setSelection( int s )
00103 {
00104     WItemSelector::IndexList it;
00105     it.push_back( static_cast< std::size_t >( s ) );
00106     WItemSelector sel = m_prop->toPropSelection()->get().newSelector( it );
00107     m_prop->toPropSelection()->set( sel, false );
00108 }
00109 
00110 void WPropertyWrapper::click()
00111 {
00112     m_prop->toPropTrigger()->set( WPVBaseTypes::PV_TRIGGER_TRIGGERED, false );
00113 }
00114 
00115 void WPropertyWrapper::waitForUpdate()
00116 {
00117     m_prop->getUpdateCondition()->wait();
00118 }