~noskcaj/ubuntu/saucy/openwalnut/liberation

« back to all changes in this revision

Viewing changes to .pc/boost153/src/core/common/WPropertyList.h

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-05-24 03:12:03 UTC
  • Revision ID: package-import@ubuntu.com-20130524031203-l5g1lzm1vd83fupi
Tags: 1.3.1+hg5849-1ubuntu1
Cherrypick boost1.53 pointer cast fixes.

Show diffs side-by-side

added added

removed removed

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