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