The Gaudi Framework  v30r0 (c919700c)
Property.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_PROPERTY_H
2 #define GAUDIKERNEL_PROPERTY_H
3 // ============================================================================
4 // STD & STL
5 // ============================================================================
6 #include <boost/utility/string_ref.hpp>
7 #include <stdexcept>
8 #include <string>
9 #include <typeinfo>
10 // ============================================================================
11 // Application C++ Class Headers
12 // ============================================================================
13 #include "GaudiKernel/IProperty.h"
14 #include "GaudiKernel/Kernel.h"
15 #include "GaudiKernel/Parsers.h"
17 #include "GaudiKernel/SmartIF.h"
18 #include "GaudiKernel/ToStream.h"
19 
20 namespace Gaudi
21 {
22  namespace Details
23  {
24  // ============================================================================
33  {
34  private:
35  // the default constructor is disabled
36  PropertyBase() = delete;
37 
38  public:
40  const std::string name() const { return m_name.to_string(); }
42  std::string documentation() const { return m_documentation.to_string(); }
44  const std::type_info* type_info() const { return m_typeinfo; }
46  std::string type() const { return m_typeinfo->name(); }
48  virtual bool load( PropertyBase& dest ) const = 0;
50  virtual bool assign( const PropertyBase& source ) = 0;
51 
52  public:
54  virtual std::string toString() const = 0;
56  virtual void toStream( std::ostream& out ) const = 0;
58  virtual StatusCode fromString( const std::string& value ) = 0;
59 
60  public:
62  virtual PropertyBase& declareReadHandler( std::function<void( PropertyBase& )> fun ) = 0;
64  virtual PropertyBase& declareUpdateHandler( std::function<void( PropertyBase& )> fun ) = 0;
65 
67  virtual const std::function<void( PropertyBase& )> readCallBack() const = 0;
69  virtual const std::function<void( PropertyBase& )> updateCallBack() const = 0;
70 
72  virtual bool useUpdateHandler() = 0;
73 
74  template <class HT>
75  inline PropertyBase& declareReadHandler( void ( HT::*MF )( PropertyBase& ), HT* instance )
76  {
77  return declareReadHandler( [=]( PropertyBase& p ) { ( instance->*MF )( p ); } );
78  }
79 
80  template <class HT>
81  inline PropertyBase& declareUpdateHandler( void ( HT::*MF )( PropertyBase& ), HT* instance )
82  {
83  return declareUpdateHandler( [=]( PropertyBase& p ) { ( instance->*MF )( p ); } );
84  }
85 
86  public:
88  virtual ~PropertyBase() = default;
90  void setName( std::string value ) { m_name = to_view( std::move( value ) ); }
92  void setDocumentation( std::string value ) { m_documentation = to_view( std::move( value ) ); }
94  virtual std::ostream& fillStream( std::ostream& ) const;
96  virtual PropertyBase* clone() const = 0;
97 
99  void setOwnerType( const std::type_info& ownerType ) { m_ownerType = &ownerType; }
100 
102  template <class OWNER>
104  {
105  setOwnerType( typeid( OWNER ) );
106  }
107 
109  const std::type_info* ownerType() const { return m_ownerType; }
110 
113  {
114  return m_ownerType ? System::typeinfoName( *m_ownerType ) : std::string( "unknown owner type" );
115  }
116 
117  protected:
120  : m_name( to_view( std::move( name ) ) ), m_documentation( to_view( std::move( doc ) ) ), m_typeinfo( &type )
121  {
122  }
125  : m_name( to_view( std::move( name ) ) ), m_documentation( m_name ), m_typeinfo( &type )
126  {
127  }
129  PropertyBase( const PropertyBase& ) = default;
131  PropertyBase& operator=( const PropertyBase& ) = default;
132 
133  private:
135  static boost::string_ref to_view( std::string str );
137  boost::string_ref m_name;
139  boost::string_ref m_documentation;
143  const std::type_info* m_ownerType = nullptr;
144  };
145 
146  inline std::ostream& operator<<( std::ostream& stream, const PropertyBase& prop )
147  {
148  return prop.fillStream( stream );
149  }
150 
151  namespace Property
152  {
153  template <class TYPE>
155  inline std::string toString( const TYPE& v )
156  {
158  return toString( v );
159  }
160  inline TYPE fromString( const std::string& s )
161  {
162  TYPE tmp{};
163  using Gaudi::Parsers::parse;
164  if ( !parse( tmp, s ).isSuccess() ) {
165  throw std::invalid_argument( "cannot parse '" + s + "' to " + System::typeinfoName( typeid( TYPE ) ) );
166  }
167  return tmp;
168  }
169  };
170  template <>
172  {
173  return v;
174  }
175  struct NullVerifier {
176  template <class TYPE>
177  void operator()( const TYPE& ) const
178  {
179  }
180  };
181  template <class TYPE>
183  void operator()( const TYPE& value ) const
184  {
186  // throw the exception if the limit is defined and value is outside
187  if ( ( m_hasLowerBound && ( value < m_lowerBound ) ) || ( m_hasUpperBound && ( m_upperBound < value ) ) )
188  throw std::out_of_range( "value " + toString( value ) + " outside range" );
189  }
190 
192  bool hasLower() const { return m_hasLowerBound; }
194  bool hasUpper() const { return m_hasUpperBound; }
196  const TYPE& lower() const { return m_lowerBound; }
198  const TYPE& upper() const { return m_upperBound; }
199 
201  void setLower( const TYPE& value )
202  {
203  m_hasLowerBound = true;
204  m_lowerBound = value;
205  }
207  void setUpper( const TYPE& value )
208  {
209  m_hasUpperBound = true;
210  m_upperBound = value;
211  }
213  void clearLower()
214  {
215  m_hasLowerBound = false;
216  m_lowerBound = TYPE();
217  }
219  void clearUpper()
220  {
221  m_hasUpperBound = false;
222  m_upperBound = TYPE();
223  }
224 
226  void setBounds( const TYPE& lower, const TYPE& upper )
227  {
228  setLower( lower );
229  setUpper( upper );
230  }
231 
233  void clearBounds()
234  {
235  clearLower();
236  clearUpper();
237  }
238 
239  private:
241  bool m_hasLowerBound{false};
242  bool m_hasUpperBound{false};
243  TYPE m_lowerBound{};
244  TYPE m_upperBound{};
245  };
246 
248  struct SwapCall {
250  callback_t tmp, &orig;
251  SwapCall( callback_t& input ) : orig( input ) { tmp.swap( orig ); }
252  ~SwapCall() { orig.swap( tmp ); }
253  void operator()( PropertyBase& p ) const { tmp( p ); }
254  };
255 
256  struct NoHandler {
257  void useReadHandler( const PropertyBase& ) const {}
259  {
260  throw std::logic_error( "setReadHandler not implemented for this class" );
261  }
263  void useUpdateHandler( const PropertyBase& ) const {}
265  {
266  throw std::logic_error( "setUpdateHandler not implemented for this class" );
267  }
269  };
272  void useReadHandler( const PropertyBase& p ) const
273  {
274  if ( m_readCallBack ) {
275  SwapCall{m_readCallBack}( const_cast<PropertyBase&>( p ) );
276  }
277  }
278  void setReadHandler( std::function<void( PropertyBase& )> fun ) { m_readCallBack = std::move( fun ); }
279  std::function<void( PropertyBase& )> getReadHandler() const { return m_readCallBack; }
280  };
284  {
285  if ( m_updateCallBack ) {
286  try {
287  SwapCall{m_updateCallBack}( p );
288  } catch ( const std::exception& x ) {
289  throw std::invalid_argument( "failure in update handler of '" + p.name() + "': " + x.what() );
290  }
291  }
292  }
293  void setUpdateHandler( std::function<void( PropertyBase& )> fun ) { m_updateCallBack = std::move( fun ); }
294  std::function<void( PropertyBase& )> getUpdateHandler() const { return m_updateCallBack; }
295  };
297  using ReadHandler::useReadHandler;
298  using ReadHandler::setReadHandler;
299  using ReadHandler::getReadHandler;
300  using UpdateHandler::useUpdateHandler;
301  using UpdateHandler::setUpdateHandler;
302  using UpdateHandler::getUpdateHandler;
303  };
304  }
305 
306  } // namespace Details
307 
308  // ============================================================================
316  // ============================================================================
317  template <class TYPE, class VERIFIER = Details::Property::NullVerifier,
318  class HANDLERS = Details::Property::UpdateHandler>
320  {
321  public:
322  // ==========================================================================
324  using StorageType = TYPE;
326  using VerifierType = VERIFIER;
327  using HandlersType = HANDLERS;
328 
329  private:
336  template <class T>
338  template <class T>
339  using not_copying = std::enable_if_t<!is_this_type<T>::value>;
341  public:
342  // ==========================================================================
344  template <class T = StorageType>
345  inline Property( std::string name, T&& value, std::string doc = "" )
346  : Details::PropertyBase( typeid( ValueType ), std::move( name ), std::move( doc ) )
347  , m_value( std::forward<T>( value ) )
348  {
349  m_verifier( m_value );
350  }
353  template <typename OWNER, typename T = ValueType,
354  typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>,
355  typename = std::enable_if_t<std::is_default_constructible<T>::value>>
356  inline Property( OWNER* owner, std::string name ) : Property( std::move( name ), ValueType{}, "" )
357  {
358  owner->declareProperty( *this );
359  setOwnerType<OWNER>();
360  }
361 
364  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
365  inline Property( OWNER* owner, std::string name, T&& value, std::string doc = "" )
366  : Property( std::move( name ), std::forward<T>( value ), std::move( doc ) )
367  {
368  owner->declareProperty( *this );
369  setOwnerType<OWNER>();
370  }
371 
375  template <typename T, typename = not_copying<T>>
376  Property( T&& v ) : Details::PropertyBase( typeid( ValueType ), "", "" ), m_value( std::forward<T>( v ) )
377  {
378  }
379 
382  template <typename T = StorageType, typename = std::enable_if_t<!std::is_reference<T>::value>>
383  Property() : Details::PropertyBase( typeid( ValueType ), "", "" ), m_value()
384  {
385  }
386 
389 
392  {
393  m_handlers.setReadHandler( std::move( fun ) );
394  return *this;
395  }
398  {
399  m_handlers.setUpdateHandler( std::move( fun ) );
400  return *this;
401  }
402 
405  {
406  return m_handlers.getReadHandler();
407  }
410  {
411  return m_handlers.getUpdateHandler();
412  }
413 
415  bool useUpdateHandler() override
416  {
417  m_handlers.useUpdateHandler( *this );
418  return true;
419  }
420 
422  operator const ValueType&() const
423  {
424  m_handlers.useReadHandler( *this );
425  return m_value;
426  }
427  // /// Automatic conversion to value (reference).
428  // operator ValueType& () {
429  // useReadHandler();
430  // return m_value;
431  // }
432 
434  template <class T>
435  inline bool operator==( const T& other ) const
436  {
437  return m_value == other;
438  }
439 
441  template <class T>
442  inline bool operator!=( const T& other ) const
443  {
444  return m_value != other;
445  }
446 
448  template <class T>
449  inline bool operator<( const T& other ) const
450  {
451  return m_value < other;
452  }
453 
455  template <class T>
456  decltype( std::declval<ValueType>() + std::declval<T>() ) operator+( const T& other ) const
457  {
458  return m_value + other;
459  }
460 
462  template <class T = ValueType>
463  Property& operator=( T&& v )
464  {
465  m_verifier( v );
466  m_value = std::forward<T>( v );
467  m_handlers.useUpdateHandler( *this );
468  return *this;
469  }
470 
472  const VerifierType& verifier() const { return m_verifier; }
474  VerifierType& verifier() { return m_verifier; }
475 
478  const ValueType& value() const { return *this; }
479  ValueType& value() { return const_cast<ValueType&>( (const ValueType&)*this ); }
480  bool setValue( const ValueType& v )
481  {
482  *this = v;
483  return true;
484  }
485  bool set( const ValueType& v )
486  {
487  *this = v;
488  return true;
489  }
490  Details::PropertyBase* clone() const override { return new Property( *this ); }
492 
496  template <class T = const ValueType>
497  inline decltype( std::declval<T>().size() ) size() const
498  {
499  return value().size();
500  }
501  template <class T = const ValueType>
502  inline decltype( std::declval<T>().length() ) length() const
503  {
504  return value().length();
505  }
506  template <class T = const ValueType>
507  inline decltype( std::declval<T>().empty() ) empty() const
508  {
509  return value().empty();
510  }
511  template <class T = ValueType>
512  inline decltype( std::declval<T>().clear() ) clear()
513  {
514  value().clear();
515  }
516  template <class T = const ValueType>
517  inline decltype( std::declval<T>().begin() ) begin() const
518  {
519  return value().begin();
520  }
521  template <class T = const ValueType>
522  inline decltype( std::declval<T>().end() ) end() const
523  {
524  return value().end();
525  }
526  template <class T = ValueType>
527  inline decltype( std::declval<T>().begin() ) begin()
528  {
529  return value().begin();
530  }
531  template <class T = ValueType>
532  inline decltype( std::declval<T>().end() ) end()
533  {
534  return value().end();
535  }
536  template <class ARG, class T = const ValueType>
537  inline decltype( std::declval<T>()[ARG{}] ) operator[]( const ARG& arg ) const
538  {
539  return value()[arg];
540  }
541  template <class ARG, class T = ValueType>
542  inline decltype( std::declval<T>()[ARG{}] ) operator[]( const ARG& arg )
543  {
544  return value()[arg];
545  }
546  template <class T = const ValueType>
547  inline decltype( std::declval<T>().find( typename T::key_type{} ) ) find( const typename T::key_type& key ) const
548  {
549  return value().find( key );
550  }
551  template <class T = ValueType>
552  inline decltype( std::declval<T>().find( typename T::key_type{} ) ) find( const typename T::key_type& key )
553  {
554  return value().find( key );
555  }
556  template <class ARG, class T = ValueType>
557  inline decltype( std::declval<T>().erase( ARG{} ) ) erase( ARG arg )
558  {
559  return value().erase( arg );
560  }
561  template <class = ValueType>
563  {
564  ++value();
565  return *this;
566  }
567  template <class = ValueType>
568  inline ValueType operator++( int )
569  {
570  return m_value++;
571  }
572  template <class = ValueType>
574  {
575  --value();
576  return *this;
577  }
578  template <class = ValueType>
579  inline ValueType operator--( int )
580  {
581  return m_value--;
582  }
583  template <class T = ValueType>
584  inline Property& operator+=( const T& other )
585  {
586  m_value += other;
587  return *this;
588  }
589  template <class T = ValueType>
590  inline Property& operator-=( const T& other )
591  {
592  m_value -= other;
593  return *this;
594  }
596  template <class T = const ValueType>
597  inline decltype( std::declval<T>().key() ) key() const
598  {
599  return value().key();
600  }
601  template <class T = const ValueType>
602  inline decltype( std::declval<T>().objKey() ) objKey() const
603  {
604  return value().objKey();
605  }
606  template <class T = const ValueType>
607  inline decltype( std::declval<T>().fullKey() ) fullKey() const
608  {
609  return value().fullKey();
610  }
611  template <class T = ValueType>
612  inline decltype( std::declval<T>().initialize() ) initialize()
613  {
614  return value().initialize();
615  }
616  template <class T = ValueType>
617  inline decltype( std::declval<T>().makeHandles() ) makeHandles() const
618  {
619  return value().makeHandles();
620  }
621  template <class ARG, class T = ValueType>
622  inline decltype( std::declval<T>().makeHandles( std::declval<ARG>() ) ) makeHandles( const ARG& arg ) const
623  {
624  return value().makeHandles( arg );
625  }
627  // ==========================================================================
628  public:
630  bool assign( const Details::PropertyBase& source ) override
631  {
632  // Check if the property of is of "the same" type, except for strings
633  const Property* p =
634  ( std::is_same<ValueType, std::string>::value ) ? nullptr : dynamic_cast<const Property*>( &source );
635  if ( p ) {
636  *this = p->value();
637  } else {
638  this->fromString( source.toString() ).ignore();
639  }
640  return true;
641  }
643  bool load( Details::PropertyBase& dest ) const override
644  {
645  // delegate to the 'opposite' method
646  return dest.assign( *this );
647  }
649  StatusCode fromString( const std::string& source ) override
650  {
651  using Converter = Details::Property::StringConverter<ValueType>;
652  *this = Converter().fromString( source );
653  return StatusCode::SUCCESS;
654  }
656  std::string toString() const override
657  {
658  using Converter = Details::Property::StringConverter<ValueType>;
659  return Converter().toString( *this );
660  }
662  void toStream( std::ostream& out ) const override
663  {
664  m_handlers.useReadHandler( *this );
665  using Utils::toStream;
666  toStream( m_value, out );
667  }
668  };
669 
671  template <class T, class TP, class V, class H>
672  bool operator==( const T& v, const Property<TP, V, H>& p )
673  {
674  return p == v;
675  }
676 
678  template <class T, class TP, class V, class H>
679  bool operator!=( const T& v, const Property<TP, V, H>& p )
680  {
681  return p != v;
682  }
683 
685  template <class T, class TP, class V, class H>
686  decltype( std::declval<TP>() + std::declval<T>() ) operator+( const T& v, const Property<TP, V, H>& p )
687  {
688  return v + p.value();
689  }
690 
691  template <class TYPE, class HANDLERS = Details::Property::UpdateHandler>
693 
694  template <class TYPE>
697 
698 } // namespace Gaudi
699 
700 template <class TYPE>
702 
703 template <class TYPE>
705 
706 // Typedef Properties for built-in types
722 
724 
725 // Typedef PropertyRefs for built-in types
741 
743 
744 // Typedef "Arrays" of Properties for built-in types
760 
762 
763 // Typedef "Arrays" of PropertyRefs for built-in types
779 
781 
784 template <typename Handler = typename Gaudi::Details::Property::UpdateHandler>
786 {
787  Handler m_handlers;
788 
789 public:
791 
793  PropertyBase& declareReadHandler( std::function<void( PropertyBase& )> fun ) override
794  {
795  m_handlers.setReadHandler( std::move( fun ) );
796  return *this;
797  }
799  PropertyBase& declareUpdateHandler( std::function<void( PropertyBase& )> fun ) override
800  {
801  m_handlers.setUpdateHandler( std::move( fun ) );
802  return *this;
803  }
804 
806  const std::function<void( PropertyBase& )> readCallBack() const override { return m_handlers.getReadHandler(); }
808  const std::function<void( PropertyBase& )> updateCallBack() const override { return m_handlers.getUpdateHandler(); }
809 
811  void useReadHandler() const { m_handlers.useReadHandler( *this ); }
812 
814  bool useUpdateHandler() override
815  {
816  m_handlers.useUpdateHandler( *this );
817  return true;
818  }
819 };
820 
821 // forward-declaration is sufficient here
822 class GaudiHandleBase;
823 
824 // implementation in header file only where the GaudiHandleBase class
825 // definition is not needed. The rest goes into the .cpp file.
826 // The goal is to decouple the header files, to avoid that the whole
827 // world depends on GaudiHandle.h
829 {
830 public:
832 
834  {
835  setValue( value );
836  return *this;
837  }
838 
839  GaudiHandleProperty* clone() const override { return new GaudiHandleProperty( *this ); }
840 
841  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
842 
843  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
844 
845  std::string toString() const override;
846 
847  void toStream( std::ostream& out ) const override;
848 
849  StatusCode fromString( const std::string& s ) override;
850 
851  const GaudiHandleBase& value() const
852  {
853  useReadHandler();
854  return *m_pValue;
855  }
856 
857  bool setValue( const GaudiHandleBase& value );
858 
859 private:
863 };
864 
865 // forward-declaration is sufficient here
867 
869 {
870 public:
872 
874  {
875  setValue( value );
876  return *this;
877  }
878 
879  GaudiHandleArrayProperty* clone() const override { return new GaudiHandleArrayProperty( *this ); }
880 
881  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
882 
883  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
884 
885  std::string toString() const override;
886 
887  void toStream( std::ostream& out ) const override;
888 
889  StatusCode fromString( const std::string& s ) override;
890 
892  {
893  useReadHandler();
894  return *m_pValue;
895  }
896 
897  bool setValue( const GaudiHandleArrayBase& value );
898 
899 private:
903 };
904 
905 namespace Gaudi
906 {
907  namespace Utils
908  {
909  // ========================================================================
927  GAUDI_API bool hasProperty( const IProperty* p, const std::string& name );
928  // ========================================================================
946  GAUDI_API bool hasProperty( const IInterface* p, const std::string& name );
947  // ========================================================================
966  // ========================================================================
985  // ========================================================================
1009  // ========================================================================
1034  // ========================================================================
1058  template <class TYPE>
1059  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc );
1060  // ========================================================================
1083  template <class TYPE>
1084  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value )
1085  {
1086  return setProperty( component, name, value, std::string() );
1087  }
1088  // ========================================================================
1102  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const std::string& value,
1103  const std::string& doc = "" );
1104  // ========================================================================
1118  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const char* value,
1119  const std::string& doc = "" );
1120  // ========================================================================
1134  template <unsigned N>
1135  StatusCode setProperty( IProperty* component, const std::string& name, const char ( &value )[N],
1136  const std::string& doc = "" )
1137  {
1138  return component ? setProperty( component, name, std::string( value, value + N ), doc ) : StatusCode::FAILURE;
1139  }
1140  // ========================================================================
1171  template <class TYPE>
1172  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc )
1173  {
1174  using Gaudi::Utils::toString;
1175  return component && hasProperty( component, name )
1176  ? Gaudi::Utils::setProperty( component, name, toString( value ), doc )
1178  }
1179  // ========================================================================
1201  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name,
1202  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1203  // ========================================================================
1225  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name,
1226  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1227  // ========================================================================
1250  template <class TYPE>
1251  StatusCode setProperty( IProperty* component, const std::string& name, const Gaudi::Property<TYPE>& value,
1252  const std::string& doc = "" )
1253  {
1254  return setProperty( component, name, &value, doc );
1255  }
1256  // ========================================================================
1277  template <class TYPE>
1278  StatusCode setProperty( IInterface* component, const std::string& name, const TYPE& value,
1279  const std::string& doc = "" )
1280  {
1281  if ( !component ) {
1282  return StatusCode::FAILURE;
1283  }
1284  auto property = SmartIF<IProperty>{component};
1285  return property ? setProperty( property, name, value, doc ) : StatusCode::FAILURE;
1286  }
1287  // ========================================================================
1300  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const std::string& value,
1301  const std::string& doc = "" );
1302  // ========================================================================
1315  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const char* value,
1316  const std::string& doc = "" );
1317  // ========================================================================
1331  template <unsigned N>
1332  StatusCode setProperty( IInterface* component, const std::string& name, const char ( &value )[N],
1333  const std::string& doc = "" )
1334  {
1335  if ( 0 == component ) {
1336  return StatusCode::FAILURE;
1337  }
1338  return setProperty( component, name, std::string{value, value + N}, doc );
1339  }
1340  // ========================================================================
1362  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name,
1363  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1364  // ========================================================================
1386  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name,
1387  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1388  // ========================================================================
1411  template <class TYPE>
1412  StatusCode setProperty( IInterface* component, const std::string& name, const Gaudi::Property<TYPE>& value,
1413  const std::string& doc = "" )
1414  {
1415  return setProperty( component, name, &value, doc );
1416  }
1417  // ========================================================================
1418  } // end of namespace Gaudi::Utils
1419 } // end of namespace Gaudi
1420 // ============================================================================
1421 // The END
1422 // ============================================================================
1423 #endif // GAUDIKERNEL_PROPERTY_H
1424 // ============================================================================
Gaudi::Property< std::vector< float > & > FloatArrayPropertyRef
Definition: Property.h:776
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1172
Gaudi::Property< signed char & > SignedCharPropertyRef
Definition: Property.h:728
Details::Property::NullVerifier VerifierType
Definition: Property.h:326
Gaudi::Property< std::vector< signed char > & > SignedCharArrayPropertyRef
Definition: Property.h:766
Property(OWNER *owner, std::string name)
Autodeclaring constructor with property name, value and documentation.
Definition: Property.h:356
std::function< void(PropertyBase &)> m_readCallBack
Definition: Property.h:271
std::string toString(const TYPE &v)
Definition: Property.h:155
Gaudi::Property< unsigned int & > UnsignedIntegerPropertyRef
Definition: Property.h:733
T empty(T...args)
bool operator!=(const T &v, const Property< TP, V, H > &p)
delegate (value != property) to property operator!=
Definition: Property.h:679
GaudiHandleProperty * clone() const override
clones the current property
Definition: Property.h:839
bool setValue(const ValueType &v)
Definition: Property.h:480
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition: ToStream.h:293
std::function< void(PropertyBase &)> getReadHandler() const
Definition: Property.h:262
void useUpdateHandler(const PropertyBase &) const
Definition: Property.h:263
Gaudi::Property< std::vector< unsigned short > > UnsignedShortArrayProperty
Definition: Property.h:750
Gaudi::Property< TYPE > SimpleProperty
Definition: Property.h:701
Gaudi::Property< long long & > LongLongPropertyRef
Definition: Property.h:736
PropertyBase & declareReadHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Definition: Property.h:75
Gaudi::Property< std::vector< int > > IntegerArrayProperty
Definition: Property.h:751
std::ostream & operator<<(std::ostream &stream, const PropertyBase &prop)
Definition: Property.h:146
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
Definition: Property.h:672
bool useUpdateHandler() override
manual trigger for callback for update
Definition: Property.h:415
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:92
Gaudi::Property< long long > LongLongProperty
Definition: Property.h:717
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:806
Implementation of property with value of concrete type.
Definition: Property.h:319
Gaudi::Property< long & > LongPropertyRef
Definition: Property.h:734
std::function< void(PropertyBase &)> m_updateCallBack
Definition: Property.h:282
virtual PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun)=0
set new callback for update
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:336
Gaudi::Property< std::vector< double > & > DoubleArrayPropertyRef
Definition: Property.h:777
virtual bool assign(const PropertyBase &source)=0
import the property value form the source
T swap(T...args)
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
bool load(PropertyBase &destination) const override
Definition: Property.h:841
const std::string name() const
property name
Definition: Property.h:40
Property & operator=(T &&v)
Assignment from value.
Definition: Property.h:463
Gaudi::Property< float > FloatProperty
Definition: Property.h:719
Gaudi::Property< int > IntegerProperty
Definition: Property.h:713
Gaudi::Property< std::vector< unsigned long long > & > UnsignedLongLongArrayPropertyRef
Definition: Property.h:775
void setOwnerType()
set the type of the owner class (used for documentation)
Definition: Property.h:103
void clearUpper()
Clear upper bound value.
Definition: Property.h:219
const TYPE & upper() const
Return the upper bound value.
Definition: Property.h:198
GaudiHandleArrayProperty * clone() const override
clones the current property
Definition: Property.h:879
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:346
Gaudi::Property< unsigned long long > UnsignedLongLongProperty
Definition: Property.h:718
Gaudi::Property< float & > FloatPropertyRef
Definition: Property.h:738
vector< std::string > StorageType
Hosted type.
Definition: Property.h:324
Gaudi::Details::PropertyBase * property(const std::string &name) const
std::string ownerTypeName() const
get the string for the type of the owner class (used for documentation)
Definition: Property.h:112
STL namespace.
std::string toString() const override
value -> string
Definition: Property.h:656
Gaudi::Property< std::vector< std::string > > StringArrayProperty
Definition: Property.h:761
Gaudi::Property< std::vector< unsigned short > & > UnsignedShortArrayPropertyRef
Definition: Property.h:769
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
Gaudi::Property< std::vector< unsigned char > > UnsignedCharArrayProperty
Definition: Property.h:748
void setLower(const TYPE &value)
Set lower bound value.
Definition: Property.h:201
HandlersType m_handlers
Definition: Property.h:333
Gaudi::Property< unsigned short > UnsignedShortProperty
Definition: Property.h:712
const std::function< void(Details::PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: Property.h:409
T end(T...args)
Gaudi::Property< unsigned long > UnsignedLongProperty
Definition: Property.h:716
Gaudi::Property< std::string & > StringPropertyRef
Definition: Property.h:742
StorageType m_value
Storage.
Definition: Property.h:331
Gaudi::Property< char & > CharPropertyRef
Definition: Property.h:727
Gaudi::Property< std::vector< bool > & > BooleanArrayPropertyRef
Definition: Property.h:764
Gaudi::Property< std::vector< long double > > LongDoubleArrayProperty
Definition: Property.h:759
Gaudi::Property< std::vector< long long > > LongLongArrayProperty
Definition: Property.h:755
Gaudi::Property< std::vector< double > > DoubleArrayProperty
Definition: Property.h:758
bool operator<(const T &other) const
"less" comparison
Definition: Property.h:449
void setOwnerType(const std::type_info &ownerType)
set the type of the owner class (used for documentation)
Definition: Property.h:99
virtual std::string toString() const =0
value -> string
Gaudi::Property< std::vector< short > > ShortArrayProperty
Definition: Property.h:749
Gaudi::Details::PropertyBase Property
backward compatibility hack for old Property base class
Definition: PropertyFwd.h:28
Gaudi::Property< std::vector< unsigned long > & > UnsignedLongArrayPropertyRef
Definition: Property.h:773
Gaudi::Property< std::vector< unsigned int > > UnsignedIntegerArrayProperty
Definition: Property.h:752
PropertyBase(const std::type_info &type, std::string name="", std::string doc="")
constructor from the property name and the type
Definition: Property.h:119
Details::PropertyBase & declareUpdateHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:397
Property()
Construct an anonymous property with default constructed value.
Definition: Property.h:383
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:58
Helper class to simplify the migration old properties deriving directly from PropertyBase.
Definition: Property.h:785
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
Property & operator+=(const T &other)
Definition: Property.h:584
Gaudi::Property< std::vector< long > > LongArrayProperty
Definition: Property.h:753
typename std::remove_reference< StorageType >::type ValueType
Definition: Property.h:325
Gaudi::Property< std::vector< long > & > LongArrayPropertyRef
Definition: Property.h:772
void operator()(PropertyBase &p) const
Definition: Property.h:253
void operator()(const TYPE &value) const
Definition: Property.h:183
Gaudi::Property< signed char > SignedCharProperty
Definition: Property.h:709
std::ostream & toStream(const Type &, std::ostream &)
Gaudi::Property< char > CharProperty
Definition: Property.h:708
int N
Definition: IOTest.py:101
Property & operator-=(const T &other)
Definition: Property.h:590
const VerifierType & verifier() const
Accessor to verifier.
Definition: Property.h:472
Gaudi::Property< int & > IntegerPropertyRef
Definition: Property.h:732
GaudiHandleBase * m_pValue
Pointer to the real property.
Definition: Property.h:862
Gaudi::Property< unsigned long & > UnsignedLongPropertyRef
Definition: Property.h:735
const std::type_info * ownerType() const
get the type of the owner class (used for documentation)
Definition: Property.h:109
boost::string_ref m_name
property name
Definition: Property.h:137
Property & operator++()
Definition: Property.h:562
T what(T...args)
PropertyBase(std::string name, const std::type_info &type)
constructor from the property name and the type
Definition: Property.h:124
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
void setBounds(const TYPE &lower, const TYPE &upper)
Set both bounds (lower and upper) at the same time.
Definition: Property.h:226
Gaudi::Property< std::vector< long double > & > LongDoubleArrayPropertyRef
Definition: Property.h:778
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Property(std::string name, T &&value, std::string doc="")
the constructor with property name, value and documentation.
Definition: Property.h:345
Definition of the basic interface.
Definition: IInterface.h:277
const std::type_info * m_typeinfo
property type
Definition: Property.h:141
Gaudi::Property< unsigned int > UnsignedIntegerProperty
Definition: Property.h:714
TYPE fromString(const std::string &s)
Definition: Property.h:160
const TYPE & lower() const
Return the lower bound value.
Definition: Property.h:196
T erase(T...args)
Gaudi::Property< std::vector< char > > CharArrayProperty
Definition: Property.h:746
virtual PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun)=0
set new callback for reading
const GaudiHandleBase & value() const
Definition: Property.h:851
Gaudi::Property< bool > BooleanProperty
Definition: Property.h:707
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:799
Gaudi::Property< std::vector< unsigned long long > > UnsignedLongLongArrayProperty
Definition: Property.h:756
VerifierType & verifier()
Accessor to verifier.
Definition: Property.h:474
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
Definition: Property.h:793
const GaudiHandleArrayBase & value() const
Definition: Property.h:891
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:64
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
Definition: Property.cpp:52
PropertyBase & declareUpdateHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Definition: Property.h:81
T clear(T...args)
bool hasLower() const
Return if it has a lower bound.
Definition: Property.h:192
Gaudi::Property< double > DoubleProperty
Definition: Property.h:720
Converter base class.
Definition: Converter.h:24
STL class.
void setName(std::string value)
set the new value for the property name
Definition: Property.h:90
Gaudi::Property< std::vector< int > & > IntegerArrayPropertyRef
Definition: Property.h:770
T move(T...args)
bool assign(const PropertyBase &source) override
Definition: Property.h:883
Property & operator--()
Definition: Property.h:573
void operator()(const TYPE &) const
Definition: Property.h:177
Gaudi::Property< std::vector< long long > & > LongLongArrayPropertyRef
Definition: Property.h:774
std::enable_if_t<!is_this_type< T >::value > not_copying
Definition: Property.h:339
Gaudi::Property< double & > DoublePropertyRef
Definition: Property.h:739
std::function< void(PropertyBase &)> getUpdateHandler() const
Definition: Property.h:268
bool operator==(const T &other) const
equality comparison
Definition: Property.h:435
Gaudi::Property< std::vector< unsigned char > & > UnsignedCharArrayPropertyRef
Definition: Property.h:767
void useReadHandler(const PropertyBase &p) const
Definition: Property.h:272
bool hasUpper() const
Return if it has a lower bound.
Definition: Property.h:194
T find(T...args)
bool load(Details::PropertyBase &dest) const override
set value to another property
Definition: Property.h:643
T size(T...args)
Base class of array&#39;s of various gaudihandles.
Definition: GaudiHandle.h:351
std::function< void(PropertyBase &)> getUpdateHandler() const
Definition: Property.h:294
Gaudi::Property< long double & > LongDoublePropertyRef
Definition: Property.h:740
ValueType & value()
Definition: Property.h:479
STL class.
void useReadHandler() const
use the call-back function at reading, if available
Definition: Property.h:811
Gaudi::Property< std::vector< signed char > > SignedCharArrayProperty
Definition: Property.h:747
bool useUpdateHandler() override
use the call-back function at update, if available
Definition: Property.h:814
Gaudi::Property< std::string > StringProperty
Definition: Property.h:723
T begin(T...args)
STL class.
void setUpdateHandler(std::function< void(PropertyBase &)> fun)
Definition: Property.h:293
Gaudi::Property< long double > LongDoubleProperty
Definition: Property.h:721
GaudiHandleArrayProperty & operator=(const GaudiHandleArrayBase &value)
Definition: Property.h:873
SwapCall(callback_t &input)
Definition: Property.h:251
GaudiHandleArrayBase * m_pValue
Pointer to the real property.
Definition: Property.h:902
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
Gaudi::Property< short > ShortProperty
Definition: Property.h:711
std::string type() const
property type
Definition: Property.h:46
std::string documentation() const
property documentation
Definition: Property.h:42
Gaudi::Property< std::vector< unsigned long > > UnsignedLongArrayProperty
Definition: Property.h:754
Details::PropertyBase * clone() const override
clones the current property
Definition: Property.h:490
Gaudi::Property< TYPE & > SimplePropertyRef
Definition: Property.h:704
string s
Definition: gaudirun.py:253
Gaudi::Property< unsigned long long & > UnsignedLongLongPropertyRef
Definition: Property.h:737
void clearBounds()
Clear both bounds (lower and upper) at the same time.
Definition: Property.h:233
void setReadHandler(std::function< void(PropertyBase &)> fun)
Definition: Property.h:278
GAUDI_API const Gaudi::Details::PropertyBase * getProperty(const std::vector< const Gaudi::Details::PropertyBase * > *p, const std::string &name)
get the property by name from the list of the properties
Definition: Property.cpp:320
StatusCode setProperty(IInterface *component, const std::string &name, const Gaudi::Property< TYPE > &value, const std::string &doc="")
simple function to set the property of the given object from another property
Definition: Property.h:1412
std::function< void(PropertyBase &)> getReadHandler() const
Definition: Property.h:279
Gaudi::Property< std::vector< std::string > & > StringArrayPropertyRef
Definition: Property.h:780
bool assign(const Details::PropertyBase &source) override
get the value from another property
Definition: Property.h:630
bool assign(const PropertyBase &source) override
Definition: Property.h:843
bool operator!=(const T &other) const
inequality comparison
Definition: Property.h:442
Gaudi::Property< long > LongProperty
Definition: Property.h:715
void setUpdateHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:264
Gaudi::Property< std::vector< char > & > CharArrayPropertyRef
Definition: Property.h:765
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:478
void clearLower()
Clear lower bound value.
Definition: Property.h:213
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:93
implementation of various functions for streaming.
Property(T &&v)
Construct an anonymous property from a value.
Definition: Property.h:376
Gaudi::Property< unsigned short & > UnsignedShortPropertyRef
Definition: Property.h:731
Gaudi::Property< std::vector< float > > FloatArrayProperty
Definition: Property.h:757
ValueType operator++(int)
Definition: Property.h:568
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:20
helper to disable a while triggering it, to avoid infinite recursion
Definition: Property.h:248
boost::string_ref m_documentation
property doc string
Definition: Property.h:139
bool load(PropertyBase &destination) const override
Definition: Property.h:881
#define GAUDI_API
Definition: Kernel.h:110
GaudiHandleProperty & operator=(const GaudiHandleBase &value)
Definition: Property.h:833
Gaudi::Property< std::vector< short > & > ShortArrayPropertyRef
Definition: Property.h:768
STL class.
Property(OWNER *owner, std::string name, T &&value, std::string doc="")
Autodeclaring constructor with property name, value and documentation.
Definition: Property.h:365
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: Property.h:808
Details::PropertyBase & declareReadHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for reading
Definition: Property.h:391
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::Property< unsigned char > UnsignedCharProperty
Definition: Property.h:710
VerifierType m_verifier
Definition: Property.h:332
const std::function< void(Details::PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:404
Gaudi::Property< short & > ShortPropertyRef
Definition: Property.h:730
std::string toString(const Type &)
void setUpper(const TYPE &value)
Set upper bound value.
Definition: Property.h:207
void setReadHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:258
Details::Property::UpdateHandler HandlersType
Definition: Property.h:327
Gaudi::Property< unsigned char & > UnsignedCharPropertyRef
Definition: Property.h:729
ValueType operator--(int)
Definition: Property.h:579
decltype(std::declval< TP >()+std::declval< T >()) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:686
void useReadHandler(const PropertyBase &) const
Definition: Property.h:257
Gaudi::Property< std::vector< bool > > BooleanArrayProperty
Definition: Property.h:745
const std::type_info * type_info() const
property type-info
Definition: Property.h:44
Gaudi::Property< std::vector< unsigned int > & > UnsignedIntegerArrayPropertyRef
Definition: Property.h:771
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:649
void toStream(std::ostream &out) const override
value -> stream
Definition: Property.h:662
Gaudi::Property< bool & > BooleanPropertyRef
Definition: Property.h:726
void useUpdateHandler(PropertyBase &p)
Definition: Property.h:283