OpenWalnut 1.2.5

WPropertyBase.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 <list>
00026 #include <string>
00027 
00028 // Use filesystem version 2 for compatibility with newer boost versions.
00029 #ifndef BOOST_FILESYSTEM_VERSION
00030     #define BOOST_FILESYSTEM_VERSION 2
00031 #endif
00032 #include <boost/filesystem.hpp>
00033 
00034 #include "exceptions/WPropertyNameMalformed.h"
00035 #include "WProperties.h"
00036 #include "WPropertyBase.h"
00037 #include "WPropertyVariable.h"
00038 
00039 WPropertyBase::WPropertyBase( std::string name, std::string description ):
00040     boost::enable_shared_from_this< WPropertyBase >(),
00041     m_name( name ),
00042     m_description( description ),
00043     m_hidden( false ),
00044     m_purpose( PV_PURPOSE_PARAMETER ),
00045     signal_PropertyChange(),
00046     m_updateCondition( new WConditionSet() )
00047 {
00048     // check name validity
00049     if( ( m_name.find( std::string( "/" ) ) != std::string::npos ) || m_name.empty() )
00050     {
00051         throw WPropertyNameMalformed( std::string( "Property name \"" + name +
00052                                       "\" is malformed. Do not use slashes (\"/\") or empty strings in property names." ) );
00053     }
00054 }
00055 
00056 WPropertyBase::WPropertyBase( const WPropertyBase& from ):
00057     boost::enable_shared_from_this< WPropertyBase >(),
00058     m_name( from.m_name ),
00059     m_description( from.m_description ),
00060     m_hidden( from.m_hidden ),
00061     m_type( from.m_type ),
00062     m_purpose( from.m_purpose ),
00063     signal_PropertyChange(),                    // create a new and empty signal
00064     m_updateCondition( new WConditionSet() )    // create a new condition set. Do not copy it.
00065 {
00066 }
00067 
00068 WPropertyBase::~WPropertyBase()
00069 {
00070     // cleanup
00071 }
00072 
00073 std::string WPropertyBase::getName() const
00074 {
00075     return m_name;
00076 }
00077 
00078 std::string WPropertyBase::getDescription() const
00079 {
00080     return m_description;
00081 }
00082 
00083 PROPERTY_TYPE WPropertyBase::getType() const
00084 {
00085     return m_type;
00086 }
00087 
00088 PROPERTY_PURPOSE WPropertyBase::getPurpose() const
00089 {
00090     return m_purpose;
00091 }
00092 
00093 void WPropertyBase::setPurpose( PROPERTY_PURPOSE purpose )
00094 {
00095     m_purpose = purpose;
00096 }
00097 
00098 void WPropertyBase::updateType()
00099 {
00100     m_type = PV_UNKNOWN;
00101 }
00102 
00103 bool WPropertyBase::isHidden() const
00104 {
00105     return m_hidden;
00106 }
00107 
00108 void WPropertyBase::setHidden( bool hidden )
00109 {
00110     if( m_hidden != hidden )
00111     {
00112         m_hidden = hidden;
00113         m_updateCondition->notify();
00114     }
00115 }
00116 
00117 WPropInt WPropertyBase::toPropInt()
00118 {
00119     return boost::shared_static_cast< WPVInt >( shared_from_this() );
00120 }
00121 
00122 WPropDouble WPropertyBase::toPropDouble()
00123 {
00124     return boost::shared_static_cast< WPVDouble >( shared_from_this() );
00125 }
00126 
00127 WPropBool WPropertyBase::toPropBool()
00128 {
00129     return boost::shared_static_cast< WPVBool >( shared_from_this() );
00130 }
00131 
00132 WPropString WPropertyBase::toPropString()
00133 {
00134     return boost::shared_static_cast< WPVString >( shared_from_this() );
00135 }
00136 
00137 WPropFilename WPropertyBase::toPropFilename()
00138 {
00139     return boost::shared_static_cast< WPVFilename >( shared_from_this() );
00140 }
00141 
00142 WPropSelection WPropertyBase::toPropSelection()
00143 {
00144     return boost::shared_static_cast< WPVSelection >( shared_from_this() );
00145 }
00146 
00147 WPropColor WPropertyBase::toPropColor()
00148 {
00149     return boost::shared_static_cast< WPVColor >( shared_from_this() );
00150 }
00151 
00152 WPropPosition WPropertyBase::toPropPosition()
00153 {
00154     return boost::shared_static_cast< WPVPosition >( shared_from_this() );
00155 }
00156 
00157 WPropGroup WPropertyBase::toPropGroup()
00158 {
00159     return boost::shared_static_cast< WPVGroup >( shared_from_this() );
00160 }
00161 
00162 WPropMatrix4X4 WPropertyBase::toPropMatrix4X4()
00163 {
00164     return boost::shared_static_cast< WPVMatrix4X4 >( shared_from_this() );
00165 }
00166 
00167 WPropTrigger WPropertyBase::toPropTrigger()
00168 {
00169     return boost::shared_static_cast< WPVTrigger >( shared_from_this() );
00170 }
00171 
00172 boost::shared_ptr< WCondition > WPropertyBase::getUpdateCondition() const
00173 {
00174     return m_updateCondition;
00175 }
00176 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends