Skip to content
Snippets Groups Projects
Commit ce142973 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

change return type of Property::declare{Read,Update}Handler from void to Property&,

The reason is that this way one can write code like this:
```C++
  declareProperty("trackMaxChi2", m_trackMaxChi2 = 25.)
    ->declareUpdateHandler( [this](Property&){ this->m_trackChi = std::sqrt(this->m_trackMaxChi2); } )
    .useUpdateHandler();
```
this keeps m_trackChi in sync with m_trackMaxChi2. Without the call
to useUpdateHandler, if there is no entry in the JobOptionsSvc,
m_trackChi would not be set, and one would have to duplicate the
code to 'derive' m_trackChi from m_trackMaxChi2 just to initialize
it to the proper default.

Fixes GAUDI-1160.

See merge request !85
parents cd47f7e4 7314e810
No related branches found
No related tags found
No related merge requests found
......@@ -67,17 +67,17 @@ public:
const std::function<void(Property&)>& updateCallBack() const { return m_updateCallBack; }
/// set new callback for reading
virtual void declareReadHandler ( std::function<void(Property&)> fun ) ;
virtual Property& declareReadHandler ( std::function<void(Property&)> fun ) ;
/// set new callback for update
virtual void declareUpdateHandler ( std::function<void(Property&)> fun ) ;
virtual Property& declareUpdateHandler ( std::function<void(Property&)> fun ) ;
template< class HT >
inline void declareReadHandler( void ( HT::* MF ) ( Property& ) , HT* instance )
{ declareReadHandler( [=](Property& p) { (instance->*MF)(p); } ) ; }
inline Property& declareReadHandler( void ( HT::* MF ) ( Property& ) , HT* instance )
{ return declareReadHandler( [=](Property& p) { (instance->*MF)(p); } ) ; }
template< class HT >
inline void declareUpdateHandler( void ( HT::* MF ) ( Property& ) , HT* instance )
{ declareUpdateHandler ( [=](Property& p) { (instance->*MF)(p); } ); }
inline Property& declareUpdateHandler( void ( HT::* MF ) ( Property& ) , HT* instance )
{ return declareUpdateHandler ( [=](Property& p) { (instance->*MF)(p); } ); }
/// use the call-back function at reading
virtual void useReadHandler () const ;
......
......@@ -61,16 +61,18 @@ Property::Property
// ============================================================================
// set new callback for reading
// ============================================================================
void Property::declareReadHandler( std::function<void(Property&)> fun )
Property& Property::declareReadHandler( std::function<void(Property&)> fun )
{
m_readCallBack = std::move(fun);
return *this;
}
// ============================================================================
// set new callback for update
// ============================================================================
void Property::declareUpdateHandler ( std::function<void(Property&)> fun )
Property& Property::declareUpdateHandler ( std::function<void(Property&)> fun )
{
m_updateCallBack = std::move(fun);
return *this;
}
// ============================================================================
// use the call-back function at reading
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment