OpenWalnut
1.4.0
|
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 WPROPERTYLIST_H 00026 #define WPROPERTYLIST_H 00027 00028 #include <string> 00029 00030 #include <boost/shared_ptr.hpp> 00031 00032 #include "WPropertyGroupBase.h" 00033 #include "WPropertyTypes.h" 00034 00035 /** 00036 * This is a dynamic property list. With its help, users can dynamically add items. 00037 * 00038 * \tparam T This is a property type. The list will then contain several of these properties. 00039 */ 00040 template< typename T > 00041 class WPropertyList: public WPropertyGroupBase 00042 { 00043 public: 00044 /** 00045 * The type of property to store in this list. 00046 */ 00047 typedef T ValueType; 00048 00049 /** 00050 * Abbreviation for this template with the current value type. 00051 */ 00052 typedef WPropertyList< ValueType > WPropertyListType; 00053 00054 /** 00055 * Convenience typedef for a boost::shared_ptr< WPropertyList >. 00056 */ 00057 typedef boost::shared_ptr< WPropertyList< ValueType > > SPtr; 00058 00059 /** 00060 * Convenience typedef for a boost::shared_ptr< const WPropertyList >. 00061 */ 00062 typedef boost::shared_ptr< const WPropertyList< ValueType > > ConstSPtr; 00063 00064 /** 00065 * Create an empty named property. 00066 * 00067 * \param name the name of the property 00068 * \param description the description of the property 00069 */ 00070 WPropertyList( std::string name, std::string description ): 00071 WPropertyGroupBase( name, description ) 00072 { 00073 // nothing to do here. The list is initially empty 00074 } 00075 00076 /** 00077 * Copy constructor. Creates a deep copy of this property. As boost::signals2 and condition variables are non-copyable, new instances get 00078 * created. The subscriptions to a signal are LOST as well as all listeners to a condition. 00079 * 00080 * \param from the instance to copy. 00081 */ 00082 explicit WPropertyList( const WPropertyListType& from ): 00083 WPropertyGroupBase( from ) 00084 { 00085 // this created a NEW update condition and NEW property instances (clones) 00086 } 00087 00088 /** 00089 * Destructor. 00090 */ 00091 virtual ~WPropertyList() 00092 { 00093 // storing structure is destroyed automatically in WPropertyGroupBase. 00094 } 00095 00096 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00097 // The WPropertyList specific stuff 00098 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00099 00100 00101 00102 00103 00104 00105 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00106 // The WPropertyBase specific stuff 00107 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 00108 00109 /** 00110 * This method clones a property and returns the clone. It does a deep copy and, in contrast to a copy constructor, creates property with the 00111 * correct type without explicitly requiring the user to specify it. It creates a NEW change condition and change signal. This means, alls 00112 * subscribed signal handlers are NOT copied. 00113 * 00114 * \note this simply ensures the copy constructor of the runtime type is issued. 00115 * 00116 * \return the deep clone of this property. 00117 */ 00118 virtual WPropertyBase::SPtr clone() 00119 { 00120 // just use the copy constructor 00121 return WPropertyListType::SPtr( new WPropertyListType( *this ) ); 00122 } 00123 00124 /** 00125 * Gets the real WPropertyVariable type of this instance. 00126 * 00127 * \return the real type. 00128 */ 00129 virtual PROPERTY_TYPE getType() const 00130 { 00131 return PV_LIST; 00132 } 00133 00134 /** 00135 * This methods allows properties to be set by a string value. This is especially useful when a property is only available as string and the 00136 * real type of the property is unknown. This is a shortcut for casting the property and then setting the lexically casted value. 00137 * 00138 * \param value the new value to set. 00139 * 00140 * \return true if value could be set. 00141 */ 00142 virtual bool setAsString( std::string value ) 00143 { 00144 return false; 00145 } 00146 00147 /** 00148 * Returns the current value as a string. This is useful for debugging or project files. It is not implemented as << operator, since the << 00149 * should also print min/max constraints and so on. This simply is the value. 00150 * 00151 * \return the value as a string. 00152 */ 00153 virtual std::string getAsString() 00154 { 00155 // lock, unlocked if l looses focus 00156 PropertySharedContainerType::ReadTicket l = m_properties.getReadTicket(); 00157 return ""; 00158 } 00159 00160 /** 00161 * Sets the value from the specified property to this one. This is especially useful to copy a value without explicitly casting/knowing the 00162 * dynamic type of the property. 00163 * 00164 * \param value the new value. 00165 * 00166 * \return true if the value has been accepted. 00167 */ 00168 virtual bool set( boost::shared_ptr< WPropertyBase > value ) 00169 { 00170 // is this the same type as we are? 00171 typename WPropertyListType::SPtr v = boost::dynamic_pointer_cast< WPropertyListType >( value ); 00172 if( !v ) 00173 { 00174 // it is not a WPropertyList with the same type 00175 return false; 00176 } 00177 } 00178 00179 protected: 00180 private: 00181 }; 00182 00183 #endif // WPROPERTYLIST_H 00184