OpenWalnut  1.4.0
WPropertyList.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
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.
14 //
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.
19 //
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/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WPROPERTYLIST_H
26 #define WPROPERTYLIST_H
27 
28 #include <string>
29 
30 #ifndef Q_MOC_RUN
31 #include <boost/shared_ptr.hpp>
32 #endif
33 
34 #include "WPropertyGroupBase.h"
35 #include "WPropertyTypes.h"
36 
37 /**
38  * This is a dynamic property list. With its help, users can dynamically add items.
39  *
40  * \tparam T This is a property type. The list will then contain several of these properties.
41  */
42 template< typename T >
44 {
45 public:
46  /**
47  * The type of property to store in this list.
48  */
49  typedef T ValueType;
50 
51  /**
52  * Abbreviation for this template with the current value type.
53  */
55 
56  /**
57  * Convenience typedef for a boost::shared_ptr< WPropertyList >.
58  */
59  typedef boost::shared_ptr< WPropertyList< ValueType > > SPtr;
60 
61  /**
62  * Convenience typedef for a boost::shared_ptr< const WPropertyList >.
63  */
64  typedef boost::shared_ptr< const WPropertyList< ValueType > > ConstSPtr;
65 
66  /**
67  * Create an empty named property.
68  *
69  * \param name the name of the property
70  * \param description the description of the property
71  */
72  WPropertyList( std::string name, std::string description ):
73  WPropertyGroupBase( name, description )
74  {
75  // nothing to do here. The list is initially empty
76  }
77 
78  /**
79  * Copy constructor. Creates a deep copy of this property. As boost::signals2 and condition variables are non-copyable, new instances get
80  * created. The subscriptions to a signal are LOST as well as all listeners to a condition.
81  *
82  * \param from the instance to copy.
83  */
84  explicit WPropertyList( const WPropertyListType& from ):
85  WPropertyGroupBase( from )
86  {
87  // this created a NEW update condition and NEW property instances (clones)
88  }
89 
90  /**
91  * Destructor.
92  */
93  virtual ~WPropertyList()
94  {
95  // storing structure is destroyed automatically in WPropertyGroupBase.
96  }
97 
98  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
99  // The WPropertyList specific stuff
100  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 
103 
104 
105 
106 
107  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
108  // The WPropertyBase specific stuff
109  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110 
111  /**
112  * 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
113  * correct type without explicitly requiring the user to specify it. It creates a NEW change condition and change signal. This means, alls
114  * subscribed signal handlers are NOT copied.
115  *
116  * \note this simply ensures the copy constructor of the runtime type is issued.
117  *
118  * \return the deep clone of this property.
119  */
121  {
122  // just use the copy constructor
123  return WPropertyListType::SPtr( new WPropertyListType( *this ) );
124  }
125 
126  /**
127  * Gets the real WPropertyVariable type of this instance.
128  *
129  * \return the real type.
130  */
131  virtual PROPERTY_TYPE getType() const
132  {
133  return PV_LIST;
134  }
135 
136  /**
137  * 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
138  * real type of the property is unknown. This is a shortcut for casting the property and then setting the lexically casted value.
139  *
140  * \param value the new value to set.
141  *
142  * \return true if value could be set.
143  */
144  virtual bool setAsString( std::string value )
145  {
146  return false;
147  }
148 
149  /**
150  * Returns the current value as a string. This is useful for debugging or project files. It is not implemented as << operator, since the <<
151  * should also print min/max constraints and so on. This simply is the value.
152  *
153  * \return the value as a string.
154  */
155  virtual std::string getAsString()
156  {
157  // lock, unlocked if l looses focus
159  return "";
160  }
161 
162  /**
163  * Sets the value from the specified property to this one. This is especially useful to copy a value without explicitly casting/knowing the
164  * dynamic type of the property.
165  *
166  * \param value the new value.
167  *
168  * \return true if the value has been accepted.
169  */
170  virtual bool set( boost::shared_ptr< WPropertyBase > value )
171  {
172  // is this the same type as we are?
173  typename WPropertyListType::SPtr v = boost::dynamic_pointer_cast< WPropertyListType >( value );
174  if( !v )
175  {
176  // it is not a WPropertyList with the same type
177  return false;
178  }
179  }
180 
181 protected:
182 private:
183 };
184 
185 #endif // WPROPERTYLIST_H
186 
virtual WPropertyBase::SPtr clone()
This method clones a property and returns the clone.
virtual std::string getAsString()
Returns the current value as a string.
WPropertyList(const WPropertyListType &from)
Copy constructor.
Definition: WPropertyList.h:84
boost::shared_ptr< WPropertyList< ValueType > > SPtr
Convenience typedef for a boost::shared_ptr< WPropertyList >.
Definition: WPropertyList.h:59
virtual bool set(boost::shared_ptr< WPropertyBase > value)
Sets the value from the specified property to this one.
virtual PROPERTY_TYPE getType() const
Gets the real WPropertyVariable type of this instance.
PropertySharedContainerType m_properties
The set of proerties.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.
virtual ~WPropertyList()
Destructor.
Definition: WPropertyList.h:93
WPropertyList< ValueType > WPropertyListType
Abbreviation for this template with the current value type.
Definition: WPropertyList.h:54
This is a dynamic property list.
Definition: WPropertyList.h:43
WPropertyList(std::string name, std::string description)
Create an empty named property.
Definition: WPropertyList.h:72
This is the base class and interface for property groups.
boost::shared_ptr< WPropertyBase > SPtr
Convenience typedef for a boost::shared_ptr< WPropertyBase >
Definition: WPropertyBase.h:58
T ValueType
The type of property to store in this list.
Definition: WPropertyList.h:49
boost::shared_ptr< const WPropertyList< ValueType > > ConstSPtr
Convenience typedef for a boost::shared_ptr< const WPropertyList >.
Definition: WPropertyList.h:64
virtual bool setAsString(std::string value)
This methods allows properties to be set by a string value.
boost::shared_ptr< WSharedObjectTicketRead< PropertyContainerType > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:64