OpenWalnut  1.4.0
WPropertyGroup.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 WPROPERTYGROUP_H
26 #define WPROPERTYGROUP_H
27 
28 #include <map>
29 #include <string>
30 #include <vector>
31 
32 #include "WConditionSet.h"
33 #include "WPropertyBase.h"
34 #include "WPropertyGroupBase.h"
35 #include "WPropertyTypes.h"
36 #include "WPropertyVariable.h"
37 #include "WSharedSequenceContainer.h"
38 #include "exceptions/WPropertyNotUnique.h"
39 
40 
41 
42 /**
43  * Class to manage properties of an object and to provide convenience methods for easy access and manipulation. It also allows
44  * thread safe iteration on its elements. The main purpose of this class is to group properties together and to allow searching properties by a
45  * given name. The name of each property in a group has to be unique and is constructed using the group names containing them: hello/you/property
46  * is the property with the name "property" in the group "you" which against is in the group "hello".
47  * \note The root group of each module does not have a name.
48  */
50 {
51 friend class WPropertiesTest;
52 public:
53  // the following typedefs are for convenience.
54  typedef boost::shared_ptr< WPropertyGroup > SPtr; //!< shared pointer to object of this type
55  typedef boost::shared_ptr< const WPropertyGroup > ConstSPtr; //!< const shared pointer to object of this type
56  typedef WPropertyGroup* Ptr; //!< pointer to object of this type
57  typedef const WPropertyGroup* ConstPtr; //!< const pointer to object of this type
58  typedef WPropertyGroup& Ref; //!< ref to object of this type
59  typedef const WPropertyGroup& ConstRef; //!< const ref to object of this type
60 
61  /**
62  * For shortening: a type defining a shared vector of WSubject pointers.
63  */
65 
66  /**
67  * The alias for a shared container.
68  */
70 
71  /**
72  * The const iterator type of the container.
73  */
75 
76  /**
77  * The iterator type of the container.
78  */
80 
81  /**
82  * Constructor. Creates an empty list of properties.
83  *
84  * \note WModule::getProperties always returns an unnamed instance.
85  *
86  * \param name the name of the property group. The GUI is using this name for naming the tabs/group boxes
87  * \param description the description of the group.
88  */
89  WPropertyGroup( std::string name = "unnamed group", std::string description = "an unnamed group of properties" );
90 
91  /**
92  * Copy constructor. Creates a deep copy of this property. As boost::signals2 and condition variables are non-copyable, new instances get
93  * created. The subscriptions to a signal are LOST as well as all listeners to a condition.
94  * The conditions you can grab using getValueChangeConditon and getCondition are not the same as in the original! This is because
95  * the class corresponds to the observer/observable pattern. You won't expect a clone to fire a condition if a original flag is changed
96  * (which after cloning is completely decoupled from the clone).
97  *
98  * \note the properties inside this list are also copied deep
99  *
100  * \param from the instance to copy.
101  */
102  explicit WPropertyGroup( const WPropertyGroup& from );
103 
104  /**
105  * destructor
106  */
107  virtual ~WPropertyGroup();
108 
109  ///////////////////////////////////////////////////////////////////////////////////////////////////
110  // The WPropertyBase interface
111  ///////////////////////////////////////////////////////////////////////////////////////////////////
112 
113  /**
114  * 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
115  * correct type without explicitly requiring the user to specify it. It creates a NEW change condition and change signal. This means, alls
116  * subscribed signal handlers are NOT copied.
117  *
118  * \note this simply ensures the copy constructor of the runtime type is issued.
119  *
120  * \return the deep clone of this property.
121  */
122  virtual boost::shared_ptr< WPropertyBase > clone();
123 
124  /**
125  * Gets the real type of this instance. In this case, PV_GROUP.
126  *
127  * \return the real type.
128  */
129  virtual PROPERTY_TYPE getType() const;
130 
131  /**
132  * This methods allows properties to be set by a string value. This method does nothing here, as groups can not be set in any kind.
133  *
134  * \param value the new value to set. IGNORED.
135  *
136  * \return always true
137  */
138  virtual bool setAsString( std::string value );
139 
140  /**
141  * Returns the current value as a string. This is useful for debugging or project files. It is not implemented as << operator, since the <<
142  * should also print min/max constraints and so on. This simply is the value.
143  *
144  * \return the value as a string.
145  */
146  virtual std::string getAsString();
147 
148  /**
149  * Sets the value from the specified property to this one. This is especially useful to copy a value without explicitly casting/knowing the
150  * dynamic type of the property.
151  * For WPropertyGroup, this tries to set the contained properties to the value of the given group. It does not add/remove properties. It
152  * simply sets the children values to the ones given.
153  *
154  * \param value the new value.
155  * \param recommendedOnly if true, property types which support recommended values apply the given value as recommendation.
156  *
157  * \return true if the values of the children could be set. If one could not be set, false
158  */
159  virtual bool set( boost::shared_ptr< WPropertyBase > value, bool recommendedOnly = false );
160 
161  /**
162  * This method is a special version of \ref WPropertyBase::set for groups. It allows to set the values of the contained properties. It does
163  * not add nor remove properties. It searches the property by name (recursively) and sets the value from the specified property group's
164  * property. You can use the exclusion list to exclude a certain property.
165  *
166  * \param value the source values
167  * \param exclude a list of property names to exclude. Use complete names here, which means, when having nested groups, apply the rules
168  * defined in \ref WPropertyGroupBase::findProperty.
169  * \param recommendedOnly if true, property types which support recommended values apply the given value as recommendation.
170  *
171  * \return true if the values of the children could be set. If one could not be set, false
172  */
173  virtual bool set( boost::shared_ptr< WPropertyGroup > value, std::vector< std::string > exclude = std::vector< std::string >(),
174  bool recommendedOnly = false );
175 
176  ///////////////////////////////////////////////////////////////////////////////////////////////////
177  // Extend the WPropertyGroupBase to allow the property list to be modified
178  ///////////////////////////////////////////////////////////////////////////////////////////////////
179 
180  /**
181  * Removes all properties from the list.
182  */
183  virtual void clear();
184 
185  /**
186  * Insert the specified property into the list.
187  *
188  * \param prop the property to add
189  *
190  * \return The given prop.
191  */
192  template< typename PropType >
193  PropType addProperty( PropType prop );
194 
195  /**
196  * Remove the specified property from the list. If the given property is not in the list, nothing happens.
197  *
198  * \param prop the property to remove.
199  */
200  void removeProperty( boost::shared_ptr< WPropertyBase > prop );
201 
202  ///////////////////////////////////////////////////////////////////////////////////////////////////
203  // Convenience methods to create and add properties
204  ///////////////////////////////////////////////////////////////////////////////////////////////////
205 
206  /**
207  * Create and add a new property group. Use these groups to structure your properties.
208  *
209  * \param name the name of the group.
210  * \param description the description of the group.
211  * \param hide true if group should be completely hidden.
212  *
213  * \return The newly created property group.
214  */
215  WPropGroup addPropertyGroup( std::string name, std::string description, bool hide = false );
216 
217  /**
218  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
219  *
220  * \see WPropertyVariable
221  *
222  * \param name the property name
223  * \param description the property description
224  * \param initial the initial value
225  * \param hide set to true to set the hide flag directly.
226  *
227  * \return the newly created property variable instance.
228  */
229  template< typename T>
230  boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial, bool hide = false );
231 
232  /**
233  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
234  *
235  * \see WPropertyVariable
236  *
237  * \param name the property name
238  * \param description the property description
239  * \param initial the initial value
240  * \param condition use this external condition for notification.
241  * \param hide set to true to set the hide flag directly.
242  *
243  * \return the newly created property variable instance.
244  */
245  template< typename T>
246  boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
247  boost::shared_ptr< WCondition > condition, bool hide = false );
248 
249  /**
250  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
251  *
252  * \see WPropertyVariable
253  *
254  * \param name the property name
255  * \param description the property description
256  * \param initial the initial value
257  * \param notifier use this notifier for change callbacks.
258  * \param hide set to true to set the hide flag directly.
259  *
260  * \return the newly created property variable instance.
261  */
262  template< typename T>
263  boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
264  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
265 
266  /**
267  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
268  *
269  * \see WPropertyVariable
270  *
271  * \param name the property name
272  * \param description the property description
273  * \param initial the initial value
274  * \param notifier use this notifier for change callbacks.
275  * \param condition use this external condition for notification
276  * \param hide set to true to set the hide flag directly.
277  *
278  * \return the newly created property variable instance.
279  */
280  template< typename T>
281  boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
282  boost::shared_ptr< WCondition > condition,
283  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
284 
285  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
286  // Convenience methods to create and add properties
287  // NOTE: these methods use the type of the initial parameter to automatically use the proper type.
288  // This works, since the compiler always calls the function with the best matching parameter types.
289  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
290 
291 
292  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
293  // convenience methods for
294  // template< typename T>
295  // boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial, bool hide = false );
296  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
297 
298  /**
299  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
300  *
301  * \see WPropertyVariable
302  *
303  * \param name the property name
304  * \param description the property description
305  * \param initial the initial value
306  * \param hide set to true to set the hide flag directly.
307  *
308  * \return the newly created property variable instance.
309  */
310  WPropBool addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL& initial, bool hide = false );
311 
312  /**
313  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
314  * It also sets the min and max constraint to [0,100].
315  *
316  * \see WPropertyVariable
317  *
318  * \param name the property name
319  * \param description the property description
320  * \param initial the initial value
321  * \param hide set to true to set the hide flag directly.
322  *
323  * \return the newly created property variable instance.
324  */
325  WPropInt addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT& initial, bool hide = false );
326 
327  /**
328  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
329  * It also sets the min and max constraint to [0,100].
330  *
331  * \see WPropertyVariable
332  *
333  * \param name the property name
334  * \param description the property description
335  * \param initial the initial value
336  * \param hide set to true to set the hide flag directly.
337  *
338  * \return the newly created property variable instance.
339  */
340  WPropDouble addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial, bool hide = false );
341 
342  /**
343  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
344  *
345  * \see WPropertyVariable
346  *
347  * \param name the property name
348  * \param description the property description
349  * \param initial the initial value
350  * \param hide set to true to set the hide flag directly.
351  *
352  * \return the newly created property variable instance.
353  */
354  WPropString addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial, bool hide = false );
355 
356  /**
357  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
358  *
359  * \see WPropertyVariable
360  *
361  * \param name the property name
362  * \param description the property description
363  * \param initial the initial value
364  * \param hide set to true to set the hide flag directly.
365  *
366  * \return the newly created property variable instance.
367  */
368  WPropFilename addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial, bool hide = false );
369 
370  /**
371  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
372  *
373  * \see WPropertyVariable
374  *
375  * \param name the property name
376  * \param description the property description
377  * \param initial the initial value
378  * \param hide set to true to set the hide flag directly.
379  *
380  * \return the newly created property variable instance.
381  */
382  WPropSelection addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION& initial, bool hide = false );
383 
384  /**
385  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
386  *
387  * \see WPropertyVariable
388  *
389  * \param name the property name
390  * \param description the property description
391  * \param initial the initial value
392  * \param hide set to true to set the hide flag directly.
393  *
394  * \return the newly created property variable instance.
395  */
396  WPropPosition addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION& initial, bool hide = false );
397 
398  /**
399  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
400  *
401  * \see WPropertyVariable
402  *
403  * \param name the property name
404  * \param description the property description
405  * \param initial the initial value
406  * \param hide set to true to set the hide flag directly.
407  *
408  * \return the newly created property variable instance.
409  */
410  WPropColor addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial, bool hide = false );
411 
412  /**
413  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
414  *
415  * \see WPropertyVariable
416  *
417  * \param name the property name
418  * \param description the property description
419  * \param initial the initial value
420  * \param hide set to true to set the hide flag directly.
421  *
422  * \return the newly created property variable instance.
423  */
424  WPropTrigger addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial, bool hide = false );
425 
426  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
427  // convenience methods for
428  // template< typename T>
429  // boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
430  // boost::shared_ptr< WCondition > condition, bool hide = false );
431  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
432 
433  /**
434  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
435  *
436  * \see WPropertyVariable
437  *
438  * \param name the property name
439  * \param description the property description
440  * \param initial the initial value
441  * \param condition use this external condition for notification.
442  * \param hide set to true to set the hide flag directly.
443  *
444  * \return the newly created property variable instance.
445  */
446  WPropBool addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL& initial,
447  boost::shared_ptr< WCondition > condition, bool hide = false );
448 
449  /**
450  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
451  * It also sets the min and max constraint to [0,100].
452  *
453  * \see WPropertyVariable
454  *
455  * \param name the property name
456  * \param description the property description
457  * \param initial the initial value
458  * \param condition use this external condition for notification.
459  * \param hide set to true to set the hide flag directly.
460  *
461  * \return the newly created property variable instance.
462  */
463  WPropInt addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT& initial,
464  boost::shared_ptr< WCondition > condition, bool hide = false );
465 
466  /**
467  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
468  * It also sets the min and max constraint to [0,100].
469  *
470  * \see WPropertyVariable
471  *
472  * \param name the property name
473  * \param description the property description
474  * \param initial the initial value
475  * \param condition use this external condition for notification.
476  * \param hide set to true to set the hide flag directly.
477  *
478  * \return the newly created property variable instance.
479  */
480  WPropDouble addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial,
481  boost::shared_ptr< WCondition > condition, bool hide = false );
482 
483  /**
484  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
485  *
486  * \see WPropertyVariable
487  *
488  * \param name the property name
489  * \param description the property description
490  * \param initial the initial value
491  * \param condition use this external condition for notification.
492  * \param hide set to true to set the hide flag directly.
493  *
494  * \return the newly created property variable instance.
495  */
496  WPropString addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial,
497  boost::shared_ptr< WCondition > condition, bool hide = false );
498 
499  /**
500  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
501  *
502  * \see WPropertyVariable
503  *
504  * \param name the property name
505  * \param description the property description
506  * \param initial the initial value
507  * \param condition use this external condition for notification.
508  * \param hide set to true to set the hide flag directly.
509  *
510  * \return the newly created property variable instance.
511  */
512  WPropFilename addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial,
513  boost::shared_ptr< WCondition > condition, bool hide = false );
514 
515  /**
516  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
517  *
518  * \see WPropertyVariable
519  *
520  * \param name the property name
521  * \param description the property description
522  * \param initial the initial value
523  * \param condition use this external condition for notification.
524  * \param hide set to true to set the hide flag directly.
525  *
526  * \return the newly created property variable instance.
527  */
528  WPropSelection addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION& initial,
529  boost::shared_ptr< WCondition > condition, bool hide = false );
530 
531  /**
532  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
533  *
534  * \see WPropertyVariable
535  *
536  * \param name the property name
537  * \param description the property description
538  * \param initial the initial value
539  * \param condition use this external condition for notification.
540  * \param hide set to true to set the hide flag directly.
541  *
542  * \return the newly created property variable instance.
543  */
544  WPropPosition addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION& initial,
545  boost::shared_ptr< WCondition > condition, bool hide = false );
546 
547  /**
548  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
549  *
550  * \see WPropertyVariable
551  *
552  * \param name the property name
553  * \param description the property description
554  * \param initial the initial value
555  * \param condition use this external condition for notification.
556  * \param hide set to true to set the hide flag directly.
557  *
558  * \return the newly created property variable instance.
559  */
560  WPropColor addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial,
561  boost::shared_ptr< WCondition > condition, bool hide = false );
562 
563  /**
564  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
565  *
566  * \see WPropertyVariable
567  *
568  * \param name the property name
569  * \param description the property description
570  * \param initial the initial value
571  * \param condition use this external condition for notification.
572  * \param hide set to true to set the hide flag directly.
573  *
574  * \return the newly created property variable instance.
575  */
576  WPropTrigger addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
577  boost::shared_ptr< WCondition > condition, bool hide = false );
578 
579  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
580  // convenience methods for
581  // template< typename T>
582  // boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
583  // WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
584  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
585 
586  /**
587  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
588  *
589  * \see WPropertyVariable
590  *
591  * \param name the property name
592  * \param description the property description
593  * \param initial the initial value
594  * \param notifier use this notifier for change callbacks.
595  * \param hide set to true to set the hide flag directly.
596  *
597  * \return the newly created property variable instance.
598  */
599  WPropBool addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL& initial,
600  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
601 
602  /**
603  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
604  * It also sets the min and max constraint to [0,100].
605  *
606  * \see WPropertyVariable
607  *
608  * \param name the property name
609  * \param description the property description
610  * \param initial the initial value
611  * \param notifier use this notifier for change callbacks.
612  * \param hide set to true to set the hide flag directly.
613  *
614  * \return the newly created property variable instance.
615  */
616  WPropInt addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT& initial,
617  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
618 
619  /**
620  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
621  * It also sets the min and max constraint to [0,100].
622  *
623  * \see WPropertyVariable
624  *
625  * \param name the property name
626  * \param description the property description
627  * \param initial the initial value
628  * \param notifier use this notifier for change callbacks.
629  * \param hide set to true to set the hide flag directly.
630  *
631  * \return the newly created property variable instance.
632  */
633  WPropDouble addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial,
634  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
635 
636  /**
637  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
638  *
639  * \see WPropertyVariable
640  *
641  * \param name the property name
642  * \param description the property description
643  * \param initial the initial value
644  * \param notifier use this notifier for change callbacks.
645  * \param hide set to true to set the hide flag directly.
646  *
647  * \return the newly created property variable instance.
648  */
649  WPropString addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial,
650  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
651 
652  /**
653  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
654  *
655  * \see WPropertyVariable
656  *
657  * \param name the property name
658  * \param description the property description
659  * \param initial the initial value
660  * \param notifier use this notifier for change callbacks.
661  * \param hide set to true to set the hide flag directly.
662  *
663  * \return the newly created property variable instance.
664  */
665  WPropFilename addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial,
666  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
667 
668  /**
669  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
670  *
671  * \see WPropertyVariable
672  *
673  * \param name the property name
674  * \param description the property description
675  * \param initial the initial value
676  * \param notifier use this notifier for change callbacks.
677  * \param hide set to true to set the hide flag directly.
678  *
679  * \return the newly created property variable instance.
680  */
681  WPropSelection addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION& initial,
682  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
683 
684  /**
685  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
686  *
687  * \see WPropertyVariable
688  *
689  * \param name the property name
690  * \param description the property description
691  * \param initial the initial value
692  * \param notifier use this notifier for change callbacks.
693  * \param hide set to true to set the hide flag directly.
694  *
695  * \return the newly created property variable instance.
696  */
697  WPropPosition addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION& initial,
698  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
699 
700  /**
701  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
702  *
703  * \see WPropertyVariable
704  *
705  * \param name the property name
706  * \param description the property description
707  * \param initial the initial value
708  * \param notifier use this notifier for change callbacks.
709  * \param hide set to true to set the hide flag directly.
710  *
711  * \return the newly created property variable instance.
712  */
713  WPropColor addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial,
714  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
715 
716  /**
717  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
718  *
719  * \see WPropertyVariable
720  *
721  * \param name the property name
722  * \param description the property description
723  * \param initial the initial value
724  * \param notifier use this notifier for change callbacks.
725  * \param hide set to true to set the hide flag directly.
726  *
727  * \return the newly created property variable instance.
728  */
729  WPropTrigger addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
730  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
731 
732  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
733  // convenience methods for
734  // template< typename T>
735  // boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
736  // boost::shared_ptr< WCondition > condition,
737  // WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
738  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
739 
740  /**
741  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
742  *
743  * \see WPropertyVariable
744  *
745  * \param name the property name
746  * \param description the property description
747  * \param initial the initial value
748  * \param notifier use this notifier for change callbacks.
749  * \param condition use this external condition for notification
750  * \param hide set to true to set the hide flag directly.
751  *
752  * \return the newly created property variable instance.
753  */
754  WPropBool addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL& initial,
755  boost::shared_ptr< WCondition > condition,
756  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
757 
758  /**
759  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
760  * It also sets the min and max constraint to [0,100].
761  *
762  * \see WPropertyVariable
763  *
764  * \param name the property name
765  * \param description the property description
766  * \param initial the initial value
767  * \param notifier use this notifier for change callbacks.
768  * \param condition use this external condition for notification
769  * \param hide set to true to set the hide flag directly.
770  *
771  * \return the newly created property variable instance.
772  */
773  WPropInt addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT& initial,
774  boost::shared_ptr< WCondition > condition,
775  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
776 
777  /**
778  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
779  * It also sets the min and max constraint to [0,100].
780  *
781  * \see WPropertyVariable
782  *
783  * \param name the property name
784  * \param description the property description
785  * \param initial the initial value
786  * \param notifier use this notifier for change callbacks.
787  * \param condition use this external condition for notification
788  * \param hide set to true to set the hide flag directly.
789  *
790  * \return the newly created property variable instance.
791  */
792  WPropDouble addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial,
793  boost::shared_ptr< WCondition > condition,
794  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
795 
796 
797  /**
798  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
799  *
800  * \see WPropertyVariable
801  *
802  * \param name the property name
803  * \param description the property description
804  * \param initial the initial value
805  * \param notifier use this notifier for change callbacks.
806  * \param condition use this external condition for notification
807  * \param hide set to true to set the hide flag directly.
808  *
809  * \return the newly created property variable instance.
810  */
811  WPropString addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial,
812  boost::shared_ptr< WCondition > condition,
813  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
814 
815  /**
816  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
817  *
818  * \see WPropertyVariable
819  *
820  * \param name the property name
821  * \param description the property description
822  * \param initial the initial value
823  * \param notifier use this notifier for change callbacks.
824  * \param condition use this external condition for notification
825  * \param hide set to true to set the hide flag directly.
826  *
827  * \return the newly created property variable instance.
828  */
829  WPropFilename addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH& initial,
830  boost::shared_ptr< WCondition > condition,
831  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
832 
833  /**
834  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
835  *
836  * \see WPropertyVariable
837  *
838  * \param name the property name
839  * \param description the property description
840  * \param initial the initial value
841  * \param notifier use this notifier for change callbacks.
842  * \param condition use this external condition for notification
843  * \param hide set to true to set the hide flag directly.
844  *
845  * \return the newly created property variable instance.
846  */
847  WPropSelection addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION& initial,
848  boost::shared_ptr< WCondition > condition,
849  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
850 
851  /**
852  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
853  *
854  * \see WPropertyVariable
855  *
856  * \param name the property name
857  * \param description the property description
858  * \param initial the initial value
859  * \param notifier use this notifier for change callbacks.
860  * \param condition use this external condition for notification
861  * \param hide set to true to set the hide flag directly.
862  *
863  * \return the newly created property variable instance.
864  */
865  WPropPosition addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION& initial,
866  boost::shared_ptr< WCondition > condition,
867  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
868 
869  /**
870  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
871  *
872  * \see WPropertyVariable
873  *
874  * \param name the property name
875  * \param description the property description
876  * \param initial the initial value
877  * \param notifier use this notifier for change callbacks.
878  * \param condition use this external condition for notification
879  * \param hide set to true to set the hide flag directly.
880  *
881  * \return the newly created property variable instance.
882  */
883  WPropColor addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR& initial,
884  boost::shared_ptr< WCondition > condition,
885  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
886 
887  /**
888  * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
889  *
890  * \see WPropertyVariable
891  *
892  * \param name the property name
893  * \param description the property description
894  * \param initial the initial value
895  * \param notifier use this notifier for change callbacks.
896  * \param condition use this external condition for notification
897  * \param hide set to true to set the hide flag directly.
898  *
899  * \return the newly created property variable instance.
900  */
901  WPropTrigger addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER& initial,
902  boost::shared_ptr< WCondition > condition,
903  WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
904 
905 protected:
906  /**
907  * This function implements the set functionality. It works recursively and keeps track of the current path.
908  *
909  * \param value the value source
910  * \param path the current path inside the source property group
911  * \param exclude exclude list with paths relative to the original source group
912  * \param recommendedOnly recommendation flag.
913  *
914  * \return true if everything was set successfully.
915  */
916  virtual bool setImpl( boost::shared_ptr< WPropertyGroup > value, std::string path = "",
917  std::vector< std::string > exclude = std::vector< std::string >(),
918  bool recommendedOnly = false );
919 
920 private:
921 };
922 
923 template< typename PropType >
924 PropType WPropertyGroup::addProperty( PropType prop )
925 {
926  addArbitraryProperty( prop );
927  return prop;
928 }
929 
930 template< typename T>
931 boost::shared_ptr< WPropertyVariable< T > > WPropertyGroup::addProperty( std::string name, std::string description, const T& initial, bool hide )
932 {
933  boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
934  new WPropertyVariable< T >( name, description, initial )
935  );
936  p->setHidden( hide );
937  addProperty( p );
938  return p;
939 }
940 
941 template< typename T>
942 boost::shared_ptr< WPropertyVariable< T > > WPropertyGroup::addProperty( std::string name, std::string description, const T& initial,
943  boost::shared_ptr< WCondition > condition, bool hide )
944 {
945  boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
946  new WPropertyVariable< T >( name, description, initial, condition )
947  );
948  p->setHidden( hide );
949  addProperty( p );
950  return p;
951 }
952 
953 template< typename T>
954 boost::shared_ptr< WPropertyVariable< T > > WPropertyGroup::addProperty( std::string name, std::string description, const T& initial,
955  WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
956 {
957  boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
958  new WPropertyVariable< T >( name, description, initial, notifier )
959  );
960  p->setHidden( hide );
961  addProperty( p );
962  return p;
963 }
964 
965 template< typename T>
966 boost::shared_ptr< WPropertyVariable< T > > WPropertyGroup::addProperty( std::string name, std::string description, const T& initial,
967  boost::shared_ptr< WCondition > condition,
968  WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
969 {
970  boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
971  new WPropertyVariable< T >( name, description, initial, condition, notifier )
972  );
973  p->setHidden( hide );
974  addProperty( p );
975  return p;
976 }
977 
978 #endif // WPROPERTYGROUP_H
WPropertyGroup * Ptr
pointer to object of this type
int32_t PV_INT
base type used for every WPVInt
boost::filesystem::path PV_PATH
base type used for every WPVFilename
const WPropertyGroup & ConstRef
const ref to object of this type
virtual PROPERTY_TYPE getType() const
Gets the real type of this instance.
virtual ~WPropertyGroup()
destructor
virtual bool setImpl(boost::shared_ptr< WPropertyGroup > value, std::string path="", std::vector< std::string > exclude=std::vector< std::string >(), bool recommendedOnly=false)
This function implements the set functionality.
std::vector< boost::shared_ptr< WPropertyBase > > PropertyContainerType
For shortening: a type defining a shared vector of WSubject pointers.
PropertyContainerType::iterator PropertyIterator
The iterator type of the container.
WPropertyGroupBase::PropertySharedContainerType PropertySharedContainerType
The alias for a shared container.
A named property class with a concrete type.
boost::function< void(boost::shared_ptr< WPropertyBase >)> PropertyChangeNotifierType
Signal signature emitted during set operations.
WPropertyGroup(std::string name="unnamed group", std::string description="an unnamed group of properties")
Constructor.
virtual void clear()
Removes all properties from the list.
This only is a 3d double vector.
WPropertyGroupBase::PropertyIterator PropertyIterator
The iterator type of the container.
void removeProperty(boost::shared_ptr< WPropertyBase > prop)
Remove the specified property from the list.
WPropertyGroupBase::PropertyContainerType PropertyContainerType
For shortening: a type defining a shared vector of WSubject pointers.
double PV_DOUBLE
base type used for every WPVDouble
const WPropertyGroup * ConstPtr
const pointer to object of this type
void addArbitraryProperty(WPropertyBase::SPtr prop)
Insert the specified property into the list.
WPropertyGroupBase::PropertyConstIterator PropertyConstIterator
The const iterator type of the container.
virtual bool set(boost::shared_ptr< WPropertyBase > value, bool recommendedOnly=false)
Sets the value from the specified property to this one.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
std::string PV_STRING
base type used for every WPVString
This class represents a subset of a WItemSelection.
Definition: WItemSelector.h:56
This is the base class and interface for property groups.
Test WProperties.
virtual boost::shared_ptr< WPropertyBase > clone()
This method clones a property and returns the clone.
PV_TRIGGER
Enum denoting the possible trigger states.
bool PV_BOOL
base type used for every WPVBool
WColor PV_COLOR
base type used for every WPVColor
boost::shared_ptr< const WPropertyGroup > ConstSPtr
const shared pointer to object of this type
boost::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type
PropType addProperty(PropType prop)
Insert the specified property into the list.
WPropGroup addPropertyGroup(std::string name, std::string description, bool hide=false)
Create and add a new property group.
virtual std::string getAsString()
Returns the current value as a string.
PropertyContainerType::const_iterator PropertyConstIterator
The const iterator type of the container.
WPropertyGroup & Ref
ref to object of this type
virtual bool setAsString(std::string value)
This methods allows properties to be set by a string value.