1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
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.
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.
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/>.
23
//---------------------------------------------------------------------------
25
#ifndef WPROPERTYLIST_H
26
#define WPROPERTYLIST_H
30
#include <boost/shared_ptr.hpp>
32
#include "WPropertyGroupBase.h"
33
#include "WPropertyTypes.h"
36
* This is a dynamic property list. With its help, users can dynamically add items.
38
* \tparam T This is a property type. The list will then contain several of these properties.
40
template< typename T >
41
class WPropertyList: public WPropertyGroupBase
45
* The type of property to store in this list.
50
* Abbreviation for this template with the current value type.
52
typedef WPropertyList< ValueType > WPropertyListType;
55
* Convenience typedef for a boost::shared_ptr< WPropertyList >.
57
typedef boost::shared_ptr< WPropertyList< ValueType > > SPtr;
60
* Convenience typedef for a boost::shared_ptr< const WPropertyList >.
62
typedef boost::shared_ptr< const WPropertyList< ValueType > > ConstSPtr;
65
* Create an empty named property.
67
* \param name the name of the property
68
* \param description the description of the property
70
WPropertyList( std::string name, std::string description ):
71
WPropertyGroupBase( name, description )
73
// nothing to do here. The list is initially empty
77
* Copy constructor. Creates a deep copy of this property. As boost::signals2 and condition variables are non-copyable, new instances get
78
* created. The subscriptions to a signal are LOST as well as all listeners to a condition.
80
* \param from the instance to copy.
82
explicit WPropertyList( const WPropertyListType& from ):
83
WPropertyGroupBase( from )
85
// this created a NEW update condition and NEW property instances (clones)
91
virtual ~WPropertyList()
93
// storing structure is destroyed automatically in WPropertyGroupBase.
96
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
97
// The WPropertyList specific stuff
98
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
105
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106
// The WPropertyBase specific stuff
107
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110
* 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
111
* correct type without explicitly requiring the user to specify it. It creates a NEW change condition and change signal. This means, alls
112
* subscribed signal handlers are NOT copied.
114
* \note this simply ensures the copy constructor of the runtime type is issued.
116
* \return the deep clone of this property.
118
virtual WPropertyBase::SPtr clone()
120
// just use the copy constructor
121
return WPropertyListType::SPtr( new WPropertyListType( *this ) );
125
* Gets the real WPropertyVariable type of this instance.
127
* \return the real type.
129
virtual PROPERTY_TYPE getType() const
135
* 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
136
* real type of the property is unknown. This is a shortcut for casting the property and then setting the lexically casted value.
138
* \param value the new value to set.
140
* \return true if value could be set.
142
virtual bool setAsString( std::string value )
148
* Returns the current value as a string. This is useful for debugging or project files. It is not implemented as << operator, since the <<
149
* should also print min/max constraints and so on. This simply is the value.
151
* \return the value as a string.
153
virtual std::string getAsString()
155
// lock, unlocked if l looses focus
156
PropertySharedContainerType::ReadTicket l = m_properties.getReadTicket();
161
* Sets the value from the specified property to this one. This is especially useful to copy a value without explicitly casting/knowing the
162
* dynamic type of the property.
164
* \param value the new value.
166
* \return true if the value has been accepted.
168
virtual bool set( boost::shared_ptr< WPropertyBase > value )
170
// is this the same type as we are?
171
typename WPropertyListType::SPtr v = boost::shared_dynamic_cast< WPropertyListType >( value );
174
// it is not a WPropertyList with the same type
183
#endif // WPROPERTYLIST_H