~ubuntu-branches/ubuntu/raring/openwalnut/raring

« back to all changes in this revision

Viewing changes to src/core/common/WFlag.h

  • Committer: Package Import Robot
  • Author(s): Sebastian Eichelbaum
  • Date: 2012-12-12 11:26:32 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20121212112632-xhiuwkxuz5h0idkh
Tags: 1.3.1+hg5849-1
* Minor changes compared to 1.3.0 but included several bug fixes.
* See http://www.openwalnut.org/versions/4

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
     * \note condition can also be a WConditionOneShot.
61
61
     * \param initial the initial value of this flag.
62
62
     */
63
 
    WFlag( WCondition* condition, T initial );
 
63
    WFlag( WCondition* condition, const T& initial );
64
64
 
65
65
    /**
66
66
     * Constructor. Uses a given condition to realize the wait/notify functionality. By using this constructor, the specified
70
70
     * \note condition can also be a WConditionOneShot.
71
71
     * \param initial the initial value of this flag.
72
72
     */
73
 
    WFlag( boost::shared_ptr< WCondition > condition, T initial );
 
73
    WFlag( boost::shared_ptr< WCondition > condition, const T& initial );
74
74
 
75
75
    /**
76
76
     * Copy constructor. Creates a deep copy of this property. As boost::signals2 and condition variables are non-copyable, new instances get
95
95
     *
96
96
     * \return the value.
97
97
     */
98
 
    virtual const T get( bool resetChangeState = false );
99
 
 
100
 
    /**
101
 
     * Operator returns value of the flag.
102
 
     *
103
 
     * \return the value.
104
 
     */
105
 
    virtual const T get() const;
106
 
 
107
 
    /**
108
 
     * Operator returns value of the flag.
109
 
     *
110
 
     * \return the value.
111
 
     */
112
 
    virtual const T operator()() const;
 
98
    virtual const T& get( bool resetChangeState = false );
 
99
 
 
100
    /**
 
101
     * Operator returns value of the flag.
 
102
     *
 
103
     * \return the value.
 
104
     */
 
105
    virtual const T& get() const;
 
106
 
 
107
    /**
 
108
     * Operator returns value of the flag.
 
109
     *
 
110
     * \return the value.
 
111
     */
 
112
    virtual const T& operator()() const;
113
113
 
114
114
    /**
115
115
     * Operator returns value of the flag. It does not reset the change flag.
133
133
     *
134
134
     * \note set( get() ) == true
135
135
     */
136
 
    virtual bool set( T value, bool suppressNotification = false );
 
136
    virtual bool set( const T& value, bool suppressNotification = false );
137
137
 
138
138
    /**
139
139
     * Sets the new value for this flag. Also notifies waiting threads.
140
140
     *
141
141
     * \param value the new value
142
142
     */
143
 
    virtual void operator()( T value );
 
143
    virtual void operator()( const T& value );
144
144
 
145
145
    /**
146
146
     * Returns the condition that is used by this flag.
165
165
     *
166
166
     * \return true if it is a valid/acceptable value.
167
167
     */
168
 
    virtual bool accept( T newValue );
 
168
    virtual bool accept( const T& newValue );
169
169
 
170
170
    /**
171
171
     * Tests whether a flag is currently valid. It is equal to accept( get() );
185
185
    virtual bool changed( bool reset = false );
186
186
 
187
187
protected:
188
 
 
189
188
    /**
190
189
     * The condition to be used for waiting/notifying. Please note, that it gets deleted during destruction.
191
190
     */
216
215
typedef WFlag< bool > WBoolFlag;
217
216
 
218
217
template < typename T >
219
 
WFlag< T >::WFlag( WCondition* condition, T initial ):
 
218
WFlag< T >::WFlag( WCondition* condition, const T& initial ):
220
219
    m_condition( boost::shared_ptr< WCondition >( condition ) ),
221
220
    m_valueChangeCondition( boost::shared_ptr< WCondition >( new WCondition() ) ),
222
221
    m_flag( initial ),
225
224
}
226
225
 
227
226
template < typename T >
228
 
WFlag< T >::WFlag( boost::shared_ptr< WCondition > condition, T initial ):
 
227
WFlag< T >::WFlag( boost::shared_ptr< WCondition > condition, const T& initial ):
229
228
    m_condition( condition ),
230
229
    m_valueChangeCondition( boost::shared_ptr< WCondition >( new WCondition() ) ),
231
230
    m_flag( initial ),
248
247
}
249
248
 
250
249
template < typename T >
251
 
const T WFlag< T >::operator()() const
 
250
const T& WFlag< T >::operator()() const
252
251
{
253
252
    return get();
254
253
}
255
254
 
256
255
template < typename T >
257
 
const T WFlag< T >::get( bool resetChangeState )
 
256
const T& WFlag< T >::get( bool resetChangeState )
258
257
{
259
258
    if( resetChangeState )
260
259
    {
264
263
}
265
264
 
266
265
template < typename T >
267
 
const T WFlag< T >::get() const
 
266
const T& WFlag< T >::get() const
268
267
{
269
268
    return m_flag;
270
269
}
282
281
}
283
282
 
284
283
template < typename T >
285
 
void WFlag< T >::operator()( T value )
 
284
void WFlag< T >::operator()( const T& value )
286
285
{
287
286
    set( value );
288
287
}
289
288
 
290
289
template < typename T >
291
 
bool WFlag< T >::set( T value, bool suppressNotification )
 
290
bool WFlag< T >::set( const T& value, bool suppressNotification )
292
291
{
293
292
    // if the value is the same as the current one -> do not notify but let the caller know "all ok"
294
293
    if( m_flag == value )
328
327
}
329
328
 
330
329
template < typename T >
331
 
bool WFlag< T >::accept( T /* newValue */ )
 
330
bool WFlag< T >::accept( const T& /* newValue */ )
332
331
{
333
332
    // please implement this method in your class to modify the behaviour.
334
333
    return true;