WProperties.h 43.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

25 26
#ifndef WPROPERTIES_H
#define WPROPERTIES_H
27 28 29

#include <map>
#include <string>
30
#include <vector>
31 32 33 34 35 36

#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread.hpp>

37
#include "WSharedSequenceContainer.h"
38
#include "WPropertyBase.h"
39
#include "WPropertyTypes.h"
40
#include "WPropertyVariable.h"
41
#include "WExportCommon.h"
42 43

/**
44 45
 * Class to manage properties of an object and to provide convenience methods for easy access and manipulation. It also allows
 * 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 48
 * is the property with the name "property" in the group "you" which against is in the group "hello".
 * \note The root group of each module does not have a name.
49
 */
50
class OWCOMMON_EXPORT WProperties: public WPropertyBase
51
{
52
friend class WPropertiesTest;
53 54
public:

55 56 57 58 59 60 61 62 63 64
    // the following typedefs are for convenience.

    /**
     * For shortening: a type defining a shared vector of WSubject pointers.
     */
    typedef std::vector< boost::shared_ptr< WPropertyBase > > PropertyContainerType;

    /**
     * The alias for a shared container.
     */
65
    typedef WSharedSequenceContainer< PropertyContainerType > PropertySharedContainerType;
66

67
    /**
68
     * The const iterator type of the container.
69
     */
70 71 72 73 74 75
    typedef PropertyContainerType::const_iterator PropertyConstIterator;

    /**
     * The iterator type of the container.
     */
    typedef PropertyContainerType::iterator PropertyIterator;
76

77 78 79 80 81
    /**
     * The access type
     */
    typedef PropertySharedContainerType::WSharedAccess PropertyAccessType;

82
    /**
83 84 85 86 87 88
     * Constructor. Creates an empty list of properties.
     *
     * \note WModule::getProperties always returns an unnamed instance.
     *
     * \param name the name of the property group. The GUI is using this name for naming the tabs/group boxes
     * \param description the description of the group.
89
     */
90
    WProperties( std::string name = "unnamed group", std::string description = "an unnamed group of properties" );
91

92 93 94
    /**
     * Copy constructor. Creates a deep copy of this property. As boost::signals2 and condition variables are non-copyable, new instances get
     * created. The subscriptions to a signal are LOST as well as all listeners to a condition.
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
95 96 97
     * The conditions you can grab using getValueChangeConditon and getCondition are not the same as in the original! This is because
     * the class corresponds to the observer/observable pattern. You won't expect a clone to fire a condition if a original flag is changed
     * (which after cloning is completely decoupled from the clone).
98 99 100 101 102
     *
     * \note the properties inside this list are also copied deep
     *
     * \param from the instance to copy.
     */
103
    explicit WProperties( const WProperties& from );
104

105 106 107
    /**
     * destructor
     */
108
    virtual ~WProperties();
109

110 111 112 113 114 115 116 117 118 119 120
    /**
     * 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
     * correct type without explicitly requiring the user to specify it. It creates a NEW change condition and change signal. This means, alls
     * subscribed signal handlers are NOT copied.
     *
     * \note this simply ensures the copy constructor of the runtime type is issued.
     *
     * \return the deep clone of this property.
     */
    virtual boost::shared_ptr< WPropertyBase > clone();

121 122 123 124 125 126 127
    /**
     * Simply insert the specified property to the list.
     *
     * \param prop the property to add
     */
    void addProperty( boost::shared_ptr< WPropertyBase > prop );

128 129 130 131 132 133 134
    /**
     * Simply remove the specified property from the list. If the given property is not in the list, nothing happens.
     *
     * \param prop the property to remove.
     */
    void removeProperty( boost::shared_ptr< WPropertyBase > prop );

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    /**
     * Helper function that finds a property by its name. Use this method to find out whether the property exists or not, since
     * findProperty throws an exception.
     *
     * \param name name of searched property.
     */
    bool existsProperty( std::string name );

    /**
     * Function searches the property. If it does not exists, it throws an exception.
     *
     * \param name the name of the property
     *
     * \return a WProperty object
     */
    boost::shared_ptr< WPropertyBase > getProperty( std::string name );

152
    /**
153
     * Returns a read ticket for read-access to the list of properties.
154
     *
155
     * \return the read ticket.
156
     */
157
    PropertySharedContainerType::ReadTicket getProperties() const;
158

159
    /**
160
     * Returns the access object usable to iterate/modify the property list in a thread safe manner.
161
     *
162
     * \deprecated the method should not be used anymore.
163
     * \return the access control object.
164
     */
165
    PropertySharedContainerType::WSharedAccess getAccessObject();
166

167 168 169 170 171 172 173 174 175
    /**
     * Searches the property with a given name. It does not throw any exception. It simply returns NULL if it can't be found.
     *
     * \param name the name of the property to search
     *
     * \return the property or NULL if not found.
     */
    boost::shared_ptr< WPropertyBase > findProperty( std::string name );

176 177 178 179 180
    /**
     * Removes all properties from the list.
     */
    virtual void clear();

181 182 183 184
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    // Convenience methods to create and add properties
    ///////////////////////////////////////////////////////////////////////////////////////////////////

185 186 187 188 189 190 191 192 193
    /**
     * Create and add a new property group. Use these groups to structure your properties.
     *
     * \param name the name of the group.
     * \param description the description of the group.
     * \param hide true if group should be completely hidden.
     */
    WPropGroup addPropertyGroup( std::string name, std::string description, bool hide = false );

194 195 196 197 198 199 200 201
    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
202 203 204
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
205 206
     */
    template< typename T>
207
    boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial, bool hide = false );
208 209 210 211 212 213 214 215 216 217

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param condition use this external condition for notification.
218 219 220
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
221 222 223
     */
    template< typename T>
    boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
224
                                                             boost::shared_ptr< WCondition > condition, bool hide = false );
225 226 227 228 229 230 231 232 233 234

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param notifier use this notifier for change callbacks.
235 236 237
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
238 239 240
     */
    template< typename T>
    boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
241
                                                             WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
242 243 244 245 246 247 248 249 250 251 252

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
253 254 255
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
256 257 258 259
     */
    template< typename T>
    boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
                                                             boost::shared_ptr< WCondition > condition,
260
                                                             WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
261

262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
    /**
     * Gets the real type of this instance. In this case, PV_GROUP.
     *
     * \return the real type.
     */
    virtual PROPERTY_TYPE getType() const;

    /**
     * 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.
     *
     * \param value the new value to set. IGNORED.
     *
     * \return always true
     */
    virtual bool setAsString( std::string value );

278 279 280 281 282 283 284 285
    /**
     * Returns the current value as a string. This is useful for debugging or project files. It is not implemented as << operator, since the <<
     * should also print min/max constraints and so on. This simply is the value.
     *
     * \return the value as a string.
     */
    virtual std::string getAsString();

286 287 288 289 290 291 292 293 294 295 296 297
    /**
     * Sets the value from the specified property to this one. This is especially useful to copy a value without explicitly casting/knowing the
     * dynamic type of the property.
     *
     * \note for WProperties, this actually does nothing an.
     *
     * \param value the new value.
     *
     * \return true, always.
     */
    virtual bool set( boost::shared_ptr< WPropertyBase > value );

298
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
299 300 301
    // Convenience methods to create and add properties
    // NOTE: these methods use the type of the initial parameter to automatically use the proper type.
    // This works, since the compiler always calls the function with the best matching parameter types.
302 303 304 305 306 307 308 309
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // convenience methods for
    // template< typename T>
    // boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial, bool hide = false );
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropBool      addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL&   initial, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
327
     * It also sets the min and max constraint to [0,100].
328 329 330 331 332 333 334 335 336 337 338 339 340 341
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropInt       addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT&    initial, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
342
     * It also sets the min and max constraint to [0,100].
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropDouble    addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropString    addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropFilename  addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH&   initial, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
395
    WPropSelection      addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION&   initial, bool hide = false );
396

Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropPosition      addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION&   initial, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropColor         addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR&  initial, bool hide = false );

425 426 427 428 429 430 431 432 433 434 435 436 437
    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropTrigger       addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER&  initial, bool hide = false );
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // convenience methods for
    // template< typename T>
    // boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
    //                                                          boost::shared_ptr< WCondition > condition, bool hide = false );
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
454
     * \param condition use this external condition for notification.
455 456 457 458 459 460 461 462 463
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropBool      addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL&   initial,
                                boost::shared_ptr< WCondition > condition, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
464
     * It also sets the min and max constraint to [0,100].
465 466 467 468 469 470
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
471
     * \param condition use this external condition for notification.
472 473 474 475 476 477 478 479 480
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropInt       addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT&    initial,
                                boost::shared_ptr< WCondition > condition, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
481
     * It also sets the min and max constraint to [0,100].
482 483 484 485 486 487
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
488
     * \param condition use this external condition for notification.
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropDouble    addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial,
                                boost::shared_ptr< WCondition > condition, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
504
     * \param condition use this external condition for notification.
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropString    addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial,
                                boost::shared_ptr< WCondition > condition, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
520
     * \param condition use this external condition for notification.
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropFilename  addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH&   initial,
                                boost::shared_ptr< WCondition > condition, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
536
     * \param condition use this external condition for notification.
537 538 539 540
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
541
    WPropSelection addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION&   initial,
542 543
                                boost::shared_ptr< WCondition > condition, bool hide = false );

Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param condition use this external condition for notification.
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropPosition  addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION&   initial,
                                boost::shared_ptr< WCondition > condition, bool hide = false );

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param condition use this external condition for notification.
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropColor     addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR&   initial,
                                boost::shared_ptr< WCondition > condition, bool hide = false );

576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param condition use this external condition for notification.
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropTrigger   addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER&   initial,
                                boost::shared_ptr< WCondition > condition, bool hide = false );

592 593 594 595
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // convenience methods for
    // template< typename T>
    // boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
596
    //                                                          WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
597 598 599 600 601 602 603 604 605 606
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
607
     * \param notifier use this notifier for change callbacks.
608 609 610 611 612
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropBool      addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL&   initial,
613
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
614 615 616

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
617
     * It also sets the min and max constraint to [0,100].
618 619 620 621 622 623
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
624
     * \param notifier use this notifier for change callbacks.
625 626 627 628 629
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropInt       addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT&    initial,
630
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
631 632 633

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
634
     * It also sets the min and max constraint to [0,100].
635 636 637 638 639 640
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
641
     * \param notifier use this notifier for change callbacks.
642 643 644 645 646
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropDouble    addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial,
647
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
648 649 650 651 652 653 654 655 656

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
657
     * \param notifier use this notifier for change callbacks.
658 659 660 661 662
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropString    addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial,
663
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
664 665 666 667 668 669 670 671 672

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
673
     * \param notifier use this notifier for change callbacks.
674 675 676 677 678
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropFilename  addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH&   initial,
679
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
680 681 682 683 684 685 686 687 688

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
689
     * \param notifier use this notifier for change callbacks.
690 691 692 693
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
694
    WPropSelection addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION&   initial,
695
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
696

Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
697 698 699 700 701 702 703 704 705 706 707 708 709 710
    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param notifier use this notifier for change callbacks.
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropPosition  addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION& initial,
711
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param notifier use this notifier for change callbacks.
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropColor     addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR&  initial,
727
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param notifier use this notifier for change callbacks.
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropTrigger   addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER&  initial,
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );

745 746 747 748 749
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // convenience methods for
    // template< typename T>
    // boost::shared_ptr< WPropertyVariable< T > > addProperty( std::string name, std::string description, const T& initial,
    //                                                          boost::shared_ptr< WCondition > condition,
750
    //                                                          WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
751 752 753 754 755 756 757 758 759 760
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
761 762
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
763 764 765 766 767 768
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropBool      addProperty( std::string name, std::string description, const WPVBaseTypes::PV_BOOL&   initial,
                                boost::shared_ptr< WCondition > condition,
769
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
770 771 772

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
773
     * It also sets the min and max constraint to [0,100].
774 775 776 777 778 779
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
780 781
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
782 783 784 785 786 787
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropInt       addProperty( std::string name, std::string description, const WPVBaseTypes::PV_INT&    initial,
                                boost::shared_ptr< WCondition > condition,
788
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
789 790 791

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
792
     * It also sets the min and max constraint to [0,100].
793 794 795 796 797 798
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
799 800
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
801 802 803 804 805 806
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropDouble    addProperty( std::string name, std::string description, const WPVBaseTypes::PV_DOUBLE& initial,
                                boost::shared_ptr< WCondition > condition,
807
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
808 809 810 811 812 813 814 815 816 817


    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
818 819
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
820 821 822 823 824 825
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropString    addProperty( std::string name, std::string description, const WPVBaseTypes::PV_STRING& initial,
                                boost::shared_ptr< WCondition > condition,
826
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
827 828 829 830 831 832 833 834 835

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
836 837
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
838 839 840 841 842 843
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropFilename  addProperty( std::string name, std::string description, const WPVBaseTypes::PV_PATH&   initial,
                                boost::shared_ptr< WCondition > condition,
844
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
845 846 847 848 849 850 851 852 853

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
Sebastian Eichelbaum's avatar
[DOC]  
Sebastian Eichelbaum committed
854 855
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
856 857 858 859
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
860
    WPropSelection addProperty( std::string name, std::string description, const WPVBaseTypes::PV_SELECTION&   initial,
861
                                boost::shared_ptr< WCondition > condition,
862
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropPosition  addProperty( std::string name, std::string description, const WPVBaseTypes::PV_POSITION&   initial,
                                boost::shared_ptr< WCondition > condition,
880
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897

    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropColor     addProperty( std::string name, std::string description, const WPVBaseTypes::PV_COLOR&   initial,
                                boost::shared_ptr< WCondition > condition,
898
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );
899

900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
    /**
     * Create and add a new property of the template type. For more details see appropriate constructor ow WPropertyVariable.
     *
     * \see WPropertyVariable
     *
     * \param name  the property name
     * \param description the property description
     * \param initial the initial value
     * \param notifier use this notifier for change callbacks.
     * \param condition use this external condition for notification
     * \param hide set to true to set the hide flag directly.
     *
     * \return the newly created property variable instance.
     */
    WPropTrigger   addProperty( std::string name, std::string description, const WPVBaseTypes::PV_TRIGGER&   initial,
                                boost::shared_ptr< WCondition > condition,
                                WPropertyBase::PropertyChangeNotifierType notifier, bool hide = false );

918 919 920 921 922 923 924 925 926 927 928 929 930
protected:

   /**
    * Helping function to find a property inside a specific group. It does not recursively find properties nested inside other property groups.
    *
    * \param props the group to search in. This is not a shared pointer since it is not needed. It simply can't happen that it is freed during
    * findProperty as it is contained in this or a nested properties instance.
    * \param name the name of the property inside THIS group.
    *
    * \return the property if found, else NULL.
    */
    boost::shared_ptr< WPropertyBase > findProperty( WProperties* props, std::string name );

931 932 933
private:

    /**
934
     * The set of proerties. This uses the operators ==,<,> WProperty to determine equalness.
935
     */
936
    PropertySharedContainerType m_properties;
937

938 939 940 941 942 943 944
    /**
     * Compares the names of two properties and returns true if they are equal.
     *
     * \param prop1 the first prop.
     * \param prop2 the second prop.
     */
    bool propNamePredicate( boost::shared_ptr< WPropertyBase > prop1, boost::shared_ptr< WPropertyBase > prop2 ) const;
945 946 947
};

template< typename T>
948
boost::shared_ptr< WPropertyVariable< T > > WProperties::addProperty( std::string name, std::string description, const T& initial, bool hide )
949
{
950 951 952
    boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
            new WPropertyVariable< T >( name, description, initial )
    );
953
    p->setHidden( hide );
954 955
    addProperty( p );
    return p;
956 957 958
}

template< typename T>
959
boost::shared_ptr< WPropertyVariable< T > > WProperties::addProperty( std::string name, std::string description, const T& initial,
960
                                                                       boost::shared_ptr< WCondition > condition, bool hide )
961
{
962 963 964
    boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
            new WPropertyVariable< T >( name, description, initial, condition )
    );
965
    p->setHidden( hide );
966
    addProperty( p );
967
    return p;
968 969 970
}

template< typename T>
971
boost::shared_ptr< WPropertyVariable< T > > WProperties::addProperty( std::string name, std::string description, const T& initial,
972
                                                                       WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
973
{
974 975 976
    boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
            new WPropertyVariable< T >( name, description, initial, notifier )
    );
977
    p->setHidden( hide );
978 979
    addProperty( p );
    return p;
980 981 982
}

template< typename T>
983
boost::shared_ptr< WPropertyVariable< T > > WProperties::addProperty( std::string name, std::string description, const T& initial,
984
                                                                       boost::shared_ptr< WCondition > condition,
985
                                                                       WPropertyBase::PropertyChangeNotifierType notifier, bool hide )
986
{
987 988 989
    boost::shared_ptr< WPropertyVariable< T > > p = boost::shared_ptr< WPropertyVariable< T > >(
            new WPropertyVariable< T >( name, description, initial, condition, notifier )
    );
990
    p->setHidden( hide );
991 992
    addProperty( p );
    return p;
993 994
}

995
#endif  // WPROPERTIES_H