The Gaudi Framework  v32r2 (46d42edc)
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 <stdexcept>
7 #include <string>
8 #include <string_view>
9 #include <typeinfo>
10 // ============================================================================
11 // Application C++ Class Headers
12 // ============================================================================
13 #include "GaudiKernel/IProperty.h"
14 #include "GaudiKernel/Kernel.h"
16 #include "GaudiKernel/SmartIF.h"
17 #include "GaudiKernel/TaggedBool.h"
18 #include "GaudiKernel/ToStream.h"
21 
22 namespace Gaudi {
23  namespace Details {
24  // ============================================================================
33 
34  public:
36  const std::string name() const { return std::string{m_name}; }
38  std::string documentation() const { return std::string{m_documentation}; }
40  const std::type_info* type_info() const { return m_typeinfo; }
42  std::string type() const { return m_typeinfo->name(); }
44  virtual bool load( PropertyBase& dest ) const = 0;
46  virtual bool assign( const PropertyBase& source ) = 0;
47 
48  public:
50  virtual std::string toString() const = 0;
52  virtual void toStream( std::ostream& out ) const = 0;
54  virtual StatusCode fromString( const std::string& value ) = 0;
55 
56  public:
58  virtual PropertyBase& declareReadHandler( std::function<void( PropertyBase& )> fun ) = 0;
60  virtual PropertyBase& declareUpdateHandler( std::function<void( PropertyBase& )> fun ) = 0;
61 
63  virtual const std::function<void( PropertyBase& )> readCallBack() const = 0;
65  virtual const std::function<void( PropertyBase& )> updateCallBack() const = 0;
66 
68  virtual bool useUpdateHandler() = 0;
69 
70  template <class HT>
71  PropertyBase& declareReadHandler( void ( HT::*MF )( PropertyBase& ), HT* instance ) {
72  return declareReadHandler( [=]( PropertyBase& p ) { ( instance->*MF )( p ); } );
73  }
74 
75  template <class HT>
76  PropertyBase& declareUpdateHandler( void ( HT::*MF )( PropertyBase& ), HT* instance ) {
77  return declareUpdateHandler( [=]( PropertyBase& p ) { ( instance->*MF )( p ); } );
78  }
79 
80  public:
82  virtual ~PropertyBase() = default;
84  void setName( std::string value ) { m_name = to_view( std::move( value ) ); }
86  void setDocumentation( std::string value ) { m_documentation = to_view( std::move( value ) ); }
88  virtual std::ostream& fillStream( std::ostream& ) const;
90  virtual PropertyBase* clone() const = 0;
91 
93  void setOwnerType( const std::type_info& ownerType ) { m_ownerType = &ownerType; }
94 
96  template <class OWNER>
97  void setOwnerType() {
98  setOwnerType( typeid( OWNER ) );
99  }
100 
102  const std::type_info* ownerType() const { return m_ownerType; }
103 
106  return m_ownerType ? System::typeinfoName( *m_ownerType ) : std::string( "unknown owner type" );
107  }
108 
109  protected:
112  : m_name( to_view( std::move( name ) ) )
113  , m_documentation( to_view( std::move( doc ) ) )
114  , m_typeinfo( &type ) {}
117  : m_name( to_view( std::move( name ) ) ), m_documentation( m_name ), m_typeinfo( &type ) {}
119  PropertyBase( const PropertyBase& ) = default;
121  PropertyBase& operator=( const PropertyBase& ) = default;
122 
123  private:
125  static std::string_view to_view( std::string str );
127  std::string_view m_name;
129  std::string_view m_documentation;
133  const std::type_info* m_ownerType = nullptr;
134  };
135 
136  inline std::ostream& operator<<( std::ostream& stream, const PropertyBase& prop ) {
137  return prop.fillStream( stream );
138  }
139 
140  namespace Property {
141  using ImmediatelyInvokeHandler = Gaudi::tagged_bool<class ImmediatelyInvokeHandler_tag>;
142 
143  // ==========================================================================
144  // The following code is going to be a bit unpleasant, but as far as its
145  // author can tell, it is as simple as the design constraints and C++'s
146  // implementation constraints will allow. If you disagree, please submit
147  // a patch which simplifies it. Here is the underlying design rationale:
148  //
149  // - For any given type T used in a Property, we want to have an
150  // associated StringConverter<T> struct which explains how to convert a
151  // value of that type into a string (toString) and parse that string
152  // back (fromString).
153  // - There is a default implementation, called DefaultStringConverter<T>,
154  // which is based on the overloadable parse() and toStream() global
155  // methods of Gaudi. Its exact behaviour varies depending on whether T
156  // is default-constructible or only copy-constructible, which requires a
157  // layer of SFINAE indirection.
158  // - Some people want to be able to specialize StringConverter as an
159  // alternative to defining parse/toStream overloads. This interferes
160  // with the SFINAE tricks used by DefaultStringConverter, so we cannot
161  // just call a DefaultStringConverter a StringConverter and must add one
162  // more layer to the StringConverter type hierarchy.
163 
164  // This class factors out commonalities between DefaultStringConverters
165  template <class TYPE>
167  public:
168  virtual ~DefaultStringConverterImpl() = default;
169  std::string toString( const TYPE& v ) {
171  return toString( v );
172  }
173 
174  // Implementation of fromString depends on whether TYPE is default-
175  // constructible (fastest, easiest) or only copy-constructible (still
176  // doable as long as the caller can provide a valid value of TYPE)
177  virtual TYPE fromString( const TYPE& ref_value, const std::string& s ) = 0;
178 
179  protected:
180  void fromStringImpl( TYPE& buffer, const std::string& s ) {
182  if ( !parse( buffer, InputData{s} ).isSuccess() ) {
183  throw std::invalid_argument( "cannot parse '" + s + "' to " + System::typeinfoName( typeid( TYPE ) ) );
184  }
185  }
186  };
187  // Specialization of toString for strings (identity function)
188  template <>
190  return v;
191  }
192 
193  // This class provides a default implementation of StringConverter based
194  // on the overloadable parse() and toStream() global Gaudi methods.
195  //
196  // It leverages the fact that TYPE is default-constructible if it can, and
197  // falls back fo a requirement of copy-constructibility if it must. So
198  // here is the "default" implementation for copy-constructible types...
199  //
200  template <typename TYPE, typename Enable = void>
202  TYPE fromString( const TYPE& ref_value, const std::string& s ) final override {
203  TYPE buffer = ref_value;
204  this->fromStringImpl( buffer, s );
205  return buffer;
206  }
207  };
208  // ...and here is the preferred impl for default-constructible types:
209  template <class TYPE>
210  struct DefaultStringConverter<TYPE, std::enable_if_t<std::is_default_constructible_v<TYPE>>>
212  TYPE fromString( const TYPE& /* ref_value */, const std::string& s ) final override {
213  TYPE buffer{};
214  this->fromStringImpl( buffer, s );
215  return buffer;
216  }
217  };
218 
219  // Specializable StringConverter struct with a default implementation
220  template <typename TYPE>
221  struct StringConverter : DefaultStringConverter<TYPE> {};
222 
223  struct NullVerifier {
224  template <class TYPE>
225  void operator()( const TYPE& ) const {}
226  };
227  template <class TYPE>
229  void operator()( const TYPE& value ) const {
231  // throw the exception if the limit is defined and value is outside
232  if ( ( m_hasLowerBound && ( value < m_lowerBound ) ) || ( m_hasUpperBound && ( m_upperBound < value ) ) )
233  throw std::out_of_range( "value " + toString( value ) + " outside range" );
234  }
235 
237  bool hasLower() const { return m_hasLowerBound; }
239  bool hasUpper() const { return m_hasUpperBound; }
241  const TYPE& lower() const { return m_lowerBound; }
243  const TYPE& upper() const { return m_upperBound; }
244 
246  void setLower( const TYPE& value ) {
247  m_hasLowerBound = true;
248  m_lowerBound = value;
249  }
251  void setUpper( const TYPE& value ) {
252  m_hasUpperBound = true;
253  m_upperBound = value;
254  }
256  void clearLower() {
257  m_hasLowerBound = false;
258  m_lowerBound = TYPE();
259  }
261  void clearUpper() {
262  m_hasUpperBound = false;
263  m_upperBound = TYPE();
264  }
265 
267  void setBounds( const TYPE& lower, const TYPE& upper ) {
268  setLower( lower );
269  setUpper( upper );
270  }
271 
273  void clearBounds() {
274  clearLower();
275  clearUpper();
276  }
277 
278  private:
280  bool m_hasLowerBound{false};
281  bool m_hasUpperBound{false};
282  TYPE m_lowerBound{};
283  TYPE m_upperBound{};
284  };
285 
287  struct SwapCall {
290  SwapCall( callback_t& input ) : orig( input ) { tmp.swap( orig ); }
291  ~SwapCall() { orig.swap( tmp ); }
292  void operator()( PropertyBase& p ) const { tmp( p ); }
293  };
294 
295  struct NoHandler {
296  void useReadHandler( const PropertyBase& ) const {}
298  throw std::logic_error( "setReadHandler not implemented for this class" );
299  }
300  std::function<void( PropertyBase& )> getReadHandler() const { return nullptr; }
301  void useUpdateHandler( const PropertyBase& ) const {}
303  throw std::logic_error( "setUpdateHandler not implemented for this class" );
304  }
305  std::function<void( PropertyBase& )> getUpdateHandler() const { return nullptr; }
306  };
309  void useReadHandler( const PropertyBase& p ) const {
310  if ( m_readCallBack ) { SwapCall{m_readCallBack}( const_cast<PropertyBase&>( p ) ); }
311  }
314  };
318  if ( m_updateCallBack ) {
319  try {
321  } catch ( const std::exception& x ) {
322  throw std::invalid_argument( "failure in update handler of '" + p.name() + "': " + x.what() );
323  }
324  }
325  }
328  };
336  };
337  } // namespace Property
338 
339  } // namespace Details
340 
341  // ============================================================================
349  // ============================================================================
350  template <class TYPE, class VERIFIER = Details::Property::NullVerifier,
351  class HANDLERS = Details::Property::UpdateHandler>
353  public:
354  // ==========================================================================
356  using StorageType = TYPE;
358  using VerifierType = VERIFIER;
359  using HandlersType = HANDLERS;
360  // ==========================================================================
361 
362  private:
369  template <class T>
370  static inline constexpr bool is_this_type_v = std::is_same_v<Property, std::remove_reference_t<T>>;
371  template <class T>
372  using not_copying = std::enable_if_t<!is_this_type_v<T>>;
374  public:
375  // ==========================================================================
377  template <class T = StorageType>
379  : Details::PropertyBase( typeid( ValueType ), std::move( name ), std::move( doc ) )
380  , m_value( std::forward<T>( value ) ) {
381  m_verifier( m_value );
382  }
385  template <typename OWNER, typename T = ValueType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>,
386  typename = std::enable_if_t<std::is_default_constructible_v<T>>>
387  Property( OWNER* owner, std::string name ) : Property( std::move( name ), ValueType{}, "" ) {
388  owner->declareProperty( *this );
389  setOwnerType<OWNER>();
390  }
391 
394  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
395  Property( OWNER* owner, std::string name, T&& value, std::string doc = "" )
396  : Property( std::move( name ), std::forward<T>( value ), std::move( doc ) ) {
397  owner->declareProperty( *this );
398  setOwnerType<OWNER>();
399  }
400 
403  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
404  Property( OWNER* owner, std::string name, T&& value, std::function<void( PropertyBase& )> handler,
405  std::string doc = "" )
406  : Property( owner, std::move( name ), std::forward<T>( value ), std::move( doc ) ) {
407  declareUpdateHandler( std::move( handler ) );
408  }
409 
412  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
413  Property( OWNER* owner, std::string name, T&& value, void ( OWNER::*handler )( PropertyBase& ),
414  std::string doc = "" )
415  : Property(
416  owner, std::move( name ), std::forward<T>( value ),
417  [owner, handler]( PropertyBase& p ) { ( owner->*handler )( p ); }, std::move( doc ) ) {}
420  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
421  Property( OWNER* owner, std::string name, T&& value, void ( OWNER::*handler )(), std::string doc = "" )
422  : Property(
423  owner, std::move( name ), std::forward<T>( value ),
424  [owner, handler]( PropertyBase& ) { ( owner->*handler )(); }, std::move( doc ) ) {}
425 
428  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
429  Property( OWNER* owner, std::string name, T&& value, std::function<void( PropertyBase& )> handler,
431  : Property( owner, std::move( name ), std::forward<T>( value ), std::move( handler ), std::move( doc ) ) {
432  if ( invoke ) useUpdateHandler();
433  }
434 
438  template <typename T, typename = not_copying<T>>
439  Property( T&& v ) : Details::PropertyBase( typeid( ValueType ), "", "" ), m_value( std::forward<T>( v ) ) {}
440 
443  template <typename T = StorageType, typename = std::enable_if_t<!std::is_reference_v<T>>>
444  Property() : Details::PropertyBase( typeid( ValueType ), "", "" ), m_value() {}
445 
448 
451  m_handlers.setReadHandler( std::move( fun ) );
452  return *this;
453  }
456  m_handlers.setUpdateHandler( std::move( fun ) );
457  return *this;
458  }
459 
461  const std::function<void( Details::PropertyBase& )> readCallBack() const override {
462  return m_handlers.getReadHandler();
463  }
465  const std::function<void( Details::PropertyBase& )> updateCallBack() const override {
466  return m_handlers.getUpdateHandler();
467  }
468 
470  bool useUpdateHandler() override {
471  m_handlers.useUpdateHandler( *this );
472  return true;
473  }
474 
476  operator const ValueType&() const {
477  m_handlers.useReadHandler( *this );
478  return m_value;
479  }
480  // /// Automatic conversion to value (reference).
481  // operator ValueType& () {
482  // useReadHandler();
483  // return m_value;
484  // }
485 
487  template <class T>
488  bool operator==( const T& other ) const {
489  return m_value == other;
490  }
491 
493  template <class T>
494  bool operator!=( const T& other ) const {
495  return m_value != other;
496  }
497 
499  template <class T>
500  bool operator<( const T& other ) const {
501  return m_value < other;
502  }
503 
505  template <class T>
506  decltype( auto ) operator+( const T& other ) const {
507  return m_value + other;
508  }
509 
511  template <class T = ValueType>
512  Property& operator=( T&& v ) {
513  m_verifier( v );
514  m_value = std::forward<T>( v );
515  m_handlers.useUpdateHandler( *this );
516  return *this;
517  }
518 
520  const VerifierType& verifier() const { return m_verifier; }
523 
526  const ValueType& value() const { return *this; }
527  ValueType& value() { return const_cast<ValueType&>( (const ValueType&)*this ); }
528  bool setValue( const ValueType& v ) {
529  *this = v;
530  return true;
531  }
532  bool set( const ValueType& v ) {
533  *this = v;
534  return true;
535  }
536  Details::PropertyBase* clone() const override { return new Property( *this ); }
538 
542  template <class T = const ValueType>
543  decltype( auto ) size() const {
544  return value().size();
545  }
546  template <class T = const ValueType>
547  decltype( auto ) length() const {
548  return value().length();
549  }
550  template <class T = const ValueType>
551  decltype( auto ) empty() const {
552  return value().empty();
553  }
554  template <class T = ValueType>
555  decltype( auto ) clear() {
556  value().clear();
557  }
558  template <class T = const ValueType>
559  decltype( auto ) begin() const {
560  return value().begin();
561  }
562  template <class T = const ValueType>
563  decltype( auto ) end() const {
564  return value().end();
565  }
566  template <class T = ValueType>
567  decltype( auto ) begin() {
568  return value().begin();
569  }
570  template <class T = ValueType>
571  decltype( auto ) end() {
572  return value().end();
573  }
574  template <class ARG>
575  decltype( auto ) operator[]( const ARG& arg ) const {
576  return value()[arg];
577  }
578  template <class ARG>
579  decltype( auto ) operator[]( const ARG& arg ) {
580  return value()[arg];
581  }
582  template <class T = const ValueType>
583  decltype( auto ) find( const typename T::key_type& key ) const {
584  return value().find( key );
585  }
586  template <class T = ValueType>
587  decltype( auto ) find( const typename T::key_type& key ) {
588  return value().find( key );
589  }
590  template <class ARG, class T = ValueType>
591  decltype( auto ) erase( ARG arg ) {
592  return value().erase( arg );
593  }
594  template <class = ValueType>
596  ++value();
597  return *this;
598  }
599  template <class = ValueType>
601  return m_value++;
602  }
603  template <class = ValueType>
605  --value();
606  return *this;
607  }
608  template <class = ValueType>
610  return m_value--;
611  }
612  template <class T = ValueType>
613  Property& operator+=( const T& other ) {
614  m_value += other;
615  return *this;
616  }
617  template <class T = ValueType>
618  Property& operator-=( const T& other ) {
619  m_value -= other;
620  return *this;
621  }
623  template <class T = const ValueType>
624  decltype( auto ) key() const {
625  return value().key();
626  }
627  template <class T = const ValueType>
628  decltype( auto ) objKey() const {
629  return value().objKey();
630  }
631  template <class T = const ValueType>
632  decltype( auto ) fullKey() const {
633  return value().fullKey();
634  }
635  template <class T = ValueType>
636  decltype( auto ) initialize() {
637  return value().initialize();
638  }
639  template <class T = ValueType>
640  decltype( auto ) makeHandles() const {
641  return value().makeHandles();
642  }
643  template <class ARG, class T = ValueType>
644  decltype( auto ) makeHandles( const ARG& arg ) const {
645  return value().makeHandles( arg );
646  }
648  // ==========================================================================
649 
650  // Delegate operator() to the value
651  template <class... Args>
652  decltype( std::declval<ValueType>()( std::declval<Args&&>()... ) ) operator()( Args&&... args ) const
653  noexcept( noexcept( std::declval<ValueType>()( std::declval<Args&&>()... ) ) ) {
654  return value()( std::forward<Args>( args )... );
655  }
656 
657  public:
659  bool assign( const Details::PropertyBase& source ) override {
660  // Check if the property of is of "the same" type, except for strings
661  const Property* p =
662  ( std::is_same_v<ValueType, std::string> ) ? nullptr : dynamic_cast<const Property*>( &source );
663  if ( p ) {
664  *this = p->value();
665  } else {
666  this->fromString( source.toString() ).ignore();
667  }
668  return true;
669  }
671  bool load( Details::PropertyBase& dest ) const override {
672  // delegate to the 'opposite' method
673  return dest.assign( *this );
674  }
676  StatusCode fromString( const std::string& source ) override {
677  using Converter = Details::Property::StringConverter<ValueType>;
678  *this = Converter().fromString( m_value, source );
679  return StatusCode::SUCCESS;
680  }
682  std::string toString() const override {
683  using Converter = Details::Property::StringConverter<ValueType>;
684  return Converter().toString( *this );
685  }
687  void toStream( std::ostream& out ) const override {
688  m_handlers.useReadHandler( *this );
689  using Utils::toStream;
690  toStream( m_value, out );
691  }
692  };
693 
695  template <class T, class TP, class V, class H>
696  bool operator==( const T& v, const Property<TP, V, H>& p ) {
697  return p == v;
698  }
699 
701  template <class T, class TP, class V, class H>
702  bool operator!=( const T& v, const Property<TP, V, H>& p ) {
703  return p != v;
704  }
705 
707  template <class T, class TP, class V, class H>
708  decltype( auto ) operator+( const T& v, const Property<TP, V, H>& p ) {
709  return v + p.value();
710  }
711 
712  template <class TYPE, class HANDLERS = Details::Property::UpdateHandler>
714 
715  template <class TYPE>
718 
719 } // namespace Gaudi
720 
721 template <class TYPE>
723 
724 template <class TYPE>
726 
727 // Typedef Properties for built-in types
743 
745 
746 // Typedef PropertyRefs for built-in types
762 
764 
765 // Typedef "Arrays" of Properties for built-in types
781 
783 
784 // Typedef "Arrays" of PropertyRefs for built-in types
800 
802 
805 template <typename Handler = typename Gaudi::Details::Property::UpdateHandler>
807  Handler m_handlers;
808 
809 public:
810  using PropertyBase::PropertyBase;
811 
814  m_handlers.setReadHandler( std::move( fun ) );
815  return *this;
816  }
819  m_handlers.setUpdateHandler( std::move( fun ) );
820  return *this;
821  }
822 
824  const std::function<void( PropertyBase& )> readCallBack() const override { return m_handlers.getReadHandler(); }
826  const std::function<void( PropertyBase& )> updateCallBack() const override { return m_handlers.getUpdateHandler(); }
827 
829  void useReadHandler() const { m_handlers.useReadHandler( *this ); }
830 
832  bool useUpdateHandler() override {
833  m_handlers.useUpdateHandler( *this );
834  return true;
835  }
836 };
837 
838 // forward-declaration is sufficient here
839 class GaudiHandleBase;
840 
841 // implementation in header file only where the GaudiHandleBase class
842 // definition is not needed. The rest goes into the .cpp file.
843 // The goal is to decouple the header files, to avoid that the whole
844 // world depends on GaudiHandle.h
846 public:
848 
850  setValue( value );
851  return *this;
852  }
853 
854  GaudiHandleProperty* clone() const override { return new GaudiHandleProperty( *this ); }
855 
856  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
857 
858  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
859 
860  std::string toString() const override;
861 
862  void toStream( std::ostream& out ) const override;
863 
864  StatusCode fromString( const std::string& s ) override;
865 
866  const GaudiHandleBase& value() const {
867  useReadHandler();
868  return *m_pValue;
869  }
870 
871  bool setValue( const GaudiHandleBase& value );
872 
873 private:
877 };
878 
879 // forward-declaration is sufficient here
881 
883 public:
885 
887  setValue( value );
888  return *this;
889  }
890 
891  GaudiHandleArrayProperty* clone() const override { return new GaudiHandleArrayProperty( *this ); }
892 
893  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
894 
895  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
896 
897  std::string toString() const override;
898 
899  void toStream( std::ostream& out ) const override;
900 
901  StatusCode fromString( const std::string& s ) override;
902 
903  const GaudiHandleArrayBase& value() const {
904  useReadHandler();
905  return *m_pValue;
906  }
907 
908  bool setValue( const GaudiHandleArrayBase& value );
909 
910 private:
914 };
915 
916 namespace Gaudi {
917  namespace Utils {
918  // ========================================================================
936  GAUDI_API bool hasProperty( const IProperty* p, const std::string& name );
937  // ========================================================================
955  GAUDI_API bool hasProperty( const IInterface* p, const std::string& name );
956  // ========================================================================
975  // ========================================================================
994  // ========================================================================
1018  // ========================================================================
1043  // ========================================================================
1067  template <class TYPE>
1068  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc );
1069  // ========================================================================
1092  template <class TYPE>
1093  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value ) {
1094  return setProperty( component, name, value, std::string() );
1095  }
1096  // ========================================================================
1110  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const std::string& value,
1111  const std::string& doc = "" );
1112  // ========================================================================
1126  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const char* value,
1127  const std::string& doc = "" );
1128  // ========================================================================
1142  template <unsigned N>
1143  StatusCode setProperty( IProperty* component, const std::string& name, const char ( &value )[N],
1144  const std::string& doc = "" ) {
1145  return component ? setProperty( component, name, std::string( value, value + N ), doc ) : StatusCode::FAILURE;
1146  }
1147  // ========================================================================
1178  template <class TYPE>
1179  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc ) {
1180  using Gaudi::Utils::toString;
1181  return component && hasProperty( component, name )
1182  ? Gaudi::Utils::setProperty( component, name, toString( value ), doc )
1184  }
1185  // ========================================================================
1208  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1209  // ========================================================================
1232  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1233  // ========================================================================
1256  template <class TYPE>
1258  const std::string& doc = "" ) {
1259  return setProperty( component, name, &value, doc );
1260  }
1261  // ========================================================================
1282  template <class TYPE>
1283  StatusCode setProperty( IInterface* component, const std::string& name, const TYPE& value,
1284  const std::string& doc = "" ) {
1285  if ( !component ) { return StatusCode::FAILURE; }
1286  auto property = SmartIF<IProperty>{component};
1287  return property ? setProperty( property, name, value, doc ) : StatusCode::FAILURE;
1288  }
1289  // ========================================================================
1302  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const std::string& value,
1303  const std::string& doc = "" );
1304  // ========================================================================
1317  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const char* value,
1318  const std::string& doc = "" );
1319  // ========================================================================
1333  template <unsigned N>
1334  StatusCode setProperty( IInterface* component, const std::string& name, const char ( &value )[N],
1335  const std::string& doc = "" ) {
1336  if ( 0 == component ) { return StatusCode::FAILURE; }
1337  return setProperty( component, name, std::string{value, value + N}, doc );
1338  }
1339  // ========================================================================
1362  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1363  // ========================================================================
1386  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1387  // ========================================================================
1410  template <class TYPE>
1412  const std::string& doc = "" ) {
1413  return setProperty( component, name, &value, doc );
1414  }
1415  // ========================================================================
1416  } // namespace Utils
1417 } // end of namespace Gaudi
1418 // ============================================================================
1419 // The END
1420 // ============================================================================
1421 #endif // GAUDIKERNEL_PROPERTY_H
Gaudi::Property< std::vector< float > & > FloatArrayPropertyRef
Definition: Property.h:797
std::string toString() const override
value -> string
Definition: Property.h:682
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:1179
Gaudi::Property< signed char & > SignedCharPropertyRef
Definition: Property.h:749
Details::Property::NullVerifier VerifierType
Definition: Property.h:358
Gaudi::Property< std::vector< signed char > & > SignedCharArrayPropertyRef
Definition: Property.h:787
constexpr auto size(const T &, Args &&...) noexcept
Property(OWNER *owner, std::string name)
Autodeclaring constructor with property name, value and documentation.
Definition: Property.h:387
std::function< void(PropertyBase &)> m_readCallBack
Definition: Property.h:308
std::function< void(PropertyBase &)> getUpdateHandler() const
Definition: Property.h:327
Gaudi::Property< unsigned int & > UnsignedIntegerPropertyRef
Definition: Property.h:754
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:202
Property(OWNER *owner, std::string name, T &&value, std::function< void(PropertyBase &)> handler, Details::Property::ImmediatelyInvokeHandler invoke, std::string doc="")
Autodeclaring constructor with property name, value, updateHandler and documentation.
Definition: Property.h:429
bool operator!=(const T &v, const Property< TP, V, H > &p)
delegate (value != property) to property operator!=
Definition: Property.h:702
bool setValue(const ValueType &v)
Definition: Property.h:528
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:284
Gaudi::Property< std::vector< unsigned short > > UnsignedShortArrayProperty
Definition: Property.h:771
Gaudi::Property< TYPE > SimpleProperty
Definition: Property.h:722
Gaudi::Property< long long & > LongLongPropertyRef
Definition: Property.h:757
PropertyBase & declareReadHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Definition: Property.h:71
static constexpr bool is_this_type_v
helper typedefs for SFINAE
Definition: Property.h:370
Gaudi::Property< std::vector< int > > IntegerArrayProperty
Definition: Property.h:772
std::ostream & operator<<(std::ostream &stream, const PropertyBase &prop)
Definition: Property.h:136
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
Definition: Property.h:696
bool useUpdateHandler() override
manual trigger for callback for update
Definition: Property.h:470
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:86
Gaudi::Property< long long > LongLongProperty
Definition: Property.h:738
const GaudiHandleArrayBase & value() const
Definition: Property.h:903
Implementation of property with value of concrete type.
Definition: Property.h:352
Gaudi::Property< long & > LongPropertyRef
Definition: Property.h:755
std::enable_if_t<!is_this_type_v< T > > not_copying
Definition: Property.h:372
std::function< void(PropertyBase &)> m_updateCallBack
Definition: Property.h:316
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:298
Gaudi::Property< std::vector< double > & > DoubleArrayPropertyRef
Definition: Property.h:798
bool load(PropertyBase &destination) const override
Definition: Property.h:893
std::string ownerTypeName() const
get the string for the type of the owner class (used for documentation)
Definition: Property.h:105
T swap(T... args)
bool hasLower() const
Return if it has a lower bound.
Definition: Property.h:237
Property & operator=(T &&v)
Assignment from value.
Definition: Property.h:512
Gaudi::Property< float > FloatProperty
Definition: Property.h:740
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:824
GAUDI_API bool hasProperty(const IProperty *p, const std::string &name)
simple function which check the existence of the property with the given name.
Definition: Property.cpp:95
Gaudi::Property< int > IntegerProperty
Definition: Property.h:734
Gaudi::Property< std::vector< unsigned long long > & > UnsignedLongLongArrayPropertyRef
Definition: Property.h:796
void setOwnerType()
set the type of the owner class (used for documentation)
Definition: Property.h:97
void clearUpper()
Clear upper bound value.
Definition: Property.h:261
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:334
Gaudi::tagged_bool< class ImmediatelyInvokeHandler_tag > ImmediatelyInvokeHandler
Definition: Property.h:141
Gaudi::Property< unsigned long long > UnsignedLongLongProperty
Definition: Property.h:739
Gaudi::Property< float & > FloatPropertyRef
Definition: Property.h:759
vector< std::string > StorageType
Hosted type.
Definition: Property.h:356
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std::function< void(PropertyBase &)> getReadHandler() const
Definition: Property.h:300
virtual void toStream(std::ostream &out) const =0
value -> stream
STL namespace.
virtual TYPE fromString(const TYPE &ref_value, const std::string &s)=0
Gaudi::Property< std::vector< std::string > > StringArrayProperty
Definition: Property.h:782
Gaudi::Property< std::vector< unsigned short > & > UnsignedShortArrayPropertyRef
Definition: Property.h:790
Property(OWNER *owner, std::string name, T &&value, void(OWNER::*handler)(), std::string doc="")
Autodeclaring constructor with property name, value, pointer to member function updateHandler and doc...
Definition: Property.h:421
Gaudi::Property< std::vector< unsigned char > > UnsignedCharArrayProperty
Definition: Property.h:769
const TYPE & upper() const
Return the upper bound value.
Definition: Property.h:243
void setLower(const TYPE &value)
Set lower bound value.
Definition: Property.h:246
HandlersType m_handlers
Definition: Property.h:366
Gaudi::Property< unsigned short > UnsignedShortProperty
Definition: Property.h:733
Gaudi::Property< unsigned long > UnsignedLongProperty
Definition: Property.h:737
bool load(PropertyBase &destination) const override
Definition: Property.h:856
const std::function< void(Details::PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:461
Gaudi::Property< std::string & > StringPropertyRef
Definition: Property.h:763
StorageType m_value
Storage.
Definition: Property.h:364
std::string_view m_name
property name
Definition: Property.h:127
Gaudi::Property< char & > CharPropertyRef
Definition: Property.h:748
const std::string name() const
property name
Definition: Property.h:36
Gaudi::Property< std::vector< bool > & > BooleanArrayPropertyRef
Definition: Property.h:785
Gaudi::Property< std::vector< long double > > LongDoubleArrayProperty
Definition: Property.h:780
Gaudi::Property< std::vector< long long > > LongLongArrayProperty
Definition: Property.h:776
Gaudi::Property< std::vector< double > > DoubleArrayProperty
Definition: Property.h:779
void setOwnerType(const std::type_info &ownerType)
set the type of the owner class (used for documentation)
Definition: Property.h:93
Gaudi::Property< std::vector< short > > ShortArrayProperty
Definition: Property.h:770
Gaudi::Property< std::vector< unsigned long > & > UnsignedLongArrayPropertyRef
Definition: Property.h:794
Gaudi::Property< std::vector< unsigned int > > UnsignedIntegerArrayProperty
Definition: Property.h:773
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
PropertyBase(const std::type_info &type, std::string name="", std::string doc="")
constructor from the property name and the type
Definition: Property.h:111
Details::PropertyBase & declareUpdateHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:455
Property()
Construct an anonymous property with default constructed value.
Definition: Property.h:444
virtual StatusCode fromString(const std::string &value)=0
string -> value
Helper class to simplify the migration old properties deriving directly from PropertyBase.
Definition: Property.h:806
void operator()(const TYPE &) const
Definition: Property.h:225
STL class.
Property & operator+=(const T &other)
Definition: Property.h:613
const std::type_info * type_info() const
property type-info
Definition: Property.h:40
Gaudi::Property< std::vector< long > > LongArrayProperty
Definition: Property.h:774
typename std::remove_reference< StorageType >::type ValueType
Definition: Property.h:357
Gaudi::Property< std::vector< long > & > LongArrayPropertyRef
Definition: Property.h:793
Gaudi::Property< signed char > SignedCharProperty
Definition: Property.h:730
Details::PropertyBase * clone() const override
clones the current property
Definition: Property.h:536
Gaudi::Property< char > CharProperty
Definition: Property.h:729
int N
Definition: IOTest.py:100
Property & operator-=(const T &other)
Definition: Property.h:618
Gaudi::Property< int & > IntegerPropertyRef
Definition: Property.h:753
GaudiHandleBase * m_pValue
Pointer to the real property.
Definition: Property.h:876
Gaudi::Property< unsigned long & > UnsignedLongPropertyRef
Definition: Property.h:756
const TYPE & lower() const
Return the lower bound value.
Definition: Property.h:241
Property(OWNER *owner, std::string name, T &&value, void(OWNER::*handler)(PropertyBase &), std::string doc="")
Autodeclaring constructor with property name, value, pointer to member function updateHandler and doc...
Definition: Property.h:413
GaudiHandleProperty * clone() const override
clones the current property
Definition: Property.h:854
Property & operator++()
Definition: Property.h:595
T what(T... args)
PropertyBase(std::string name, const std::type_info &type)
constructor from the property name and the type
Definition: Property.h:116
void setBounds(const TYPE &lower, const TYPE &upper)
Set both bounds (lower and upper) at the same time.
Definition: Property.h:267
void operator()(PropertyBase &p) const
Definition: Property.h:292
Gaudi::Property< std::vector< long double > & > LongDoubleArrayPropertyRef
Definition: Property.h:799
bool load(Details::PropertyBase &dest) const override
set value to another property
Definition: Property.h:671
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
void useReadHandler(const PropertyBase &) const
Definition: Property.h:296
Property(std::string name, T &&value, std::string doc="")
the constructor with property name, value and documentation.
Definition: Property.h:378
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:526
Definition of the basic interface.
Definition: IInterface.h:244
const std::type_info * m_typeinfo
property type
Definition: Property.h:131
Gaudi::Property< unsigned int > UnsignedIntegerProperty
Definition: Property.h:735
void toStream(std::ostream &out) const override
value -> stream
Definition: Property.h:687
std::function< void(PropertyBase &)> getReadHandler() const
Definition: Property.h:313
Gaudi::Property< std::vector< char > > CharArrayProperty
Definition: Property.h:767
virtual PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun)=0
set new callback for reading
Gaudi::Property< bool > BooleanProperty
Definition: Property.h:728
const std::type_info * ownerType() const
get the type of the owner class (used for documentation)
Definition: Property.h:102
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:818
Gaudi::Property< std::vector< unsigned long long > > UnsignedLongLongArrayProperty
Definition: Property.h:777
VerifierType & verifier()
Accessor to verifier.
Definition: Property.h:522
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
Definition: Property.h:813
bool operator<(const T &other) const
"less" comparison
Definition: Property.h:500
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
def end
Definition: IOTest.py:113
PropertyBase & declareUpdateHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Definition: Property.h:76
void fromStringImpl(TYPE &buffer, const std::string &s)
Definition: Property.h:180
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:82
std::string_view m_documentation
property doc string
Definition: Property.h:129
Gaudi::Property< double > DoubleProperty
Definition: Property.h:741
GaudiHandleArrayProperty * clone() const override
clones the current property
Definition: Property.h:891
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:84
Gaudi::Property< std::vector< int > & > IntegerArrayPropertyRef
Definition: Property.h:791
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
Definition: Property.cpp:49
T move(T... args)
bool assign(const PropertyBase &source) override
Definition: Property.h:895
Property & operator--()
Definition: Property.h:604
Gaudi::Property< std::vector< long long > & > LongLongArrayPropertyRef
Definition: Property.h:795
Gaudi::Property< double & > DoublePropertyRef
Definition: Property.h:760
void useReadHandler(const PropertyBase &p) const
Definition: Property.h:309
Gaudi::Property< std::vector< unsigned char > & > UnsignedCharArrayPropertyRef
Definition: Property.h:788
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:46
Base class of array's of various gaudihandles.
Definition: GaudiHandle.h:330
Gaudi::Property< long double & > LongDoublePropertyRef
Definition: Property.h:761
ValueType & value()
Definition: Property.h:527
STL class.
std::string type() const
property type
Definition: Property.h:42
Helper class to enable ADL for parsers.
Definition: InputData.h:8
Gaudi::Property< std::vector< signed char > > SignedCharArrayProperty
Definition: Property.h:768
bool useUpdateHandler() override
use the call-back function at update, if available
Definition: Property.h:832
Gaudi::Property< std::string > StringProperty
Definition: Property.h:744
void setUpdateHandler(std::function< void(PropertyBase &)> fun)
Definition: Property.h:326
Gaudi::Property< long double > LongDoubleProperty
Definition: Property.h:742
GaudiHandleArrayProperty & operator=(const GaudiHandleArrayBase &value)
Definition: Property.h:886
SwapCall(callback_t &input)
Definition: Property.h:290
GaudiHandleArrayBase * m_pValue
Pointer to the real property.
Definition: Property.h:913
Gaudi::Property< short > ShortProperty
Definition: Property.h:732
bool set(const ValueType &v)
Definition: Property.h:532
std::function< void(PropertyBase &)> getUpdateHandler() const
Definition: Property.h:305
Gaudi::Property< std::vector< unsigned long > > UnsignedLongArrayProperty
Definition: Property.h:775
Gaudi::Property< TYPE & > SimplePropertyRef
Definition: Property.h:725
string s
Definition: gaudirun.py:318
Gaudi::Property< unsigned long long & > UnsignedLongLongPropertyRef
Definition: Property.h:758
constexpr static const auto FAILURE
Definition: StatusCode.h:86
void operator()(const TYPE &value) const
Definition: Property.h:229
bool operator!=(const T &other) const
inequality comparison
Definition: Property.h:494
void clearBounds()
Clear both bounds (lower and upper) at the same time.
Definition: Property.h:273
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: Property.h:826
void setReadHandler(std::function< void(PropertyBase &)> fun)
Definition: Property.h:312
const VerifierType & verifier() const
Accessor to verifier.
Definition: Property.h:520
Gaudi::Property< std::vector< std::string > & > StringArrayPropertyRef
Definition: Property.h:801
bool assign(const Details::PropertyBase &source) override
get the value from another property
Definition: Property.h:659
bool assign(const PropertyBase &source) override
Definition: Property.h:858
Gaudi::Property< long > LongProperty
Definition: Property.h:736
void setUpdateHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:302
Gaudi::Property< std::vector< char > & > CharArrayPropertyRef
Definition: Property.h:786
Property(OWNER *owner, std::string name, T &&value, std::function< void(PropertyBase &)> handler, std::string doc="")
Autodeclaring constructor with property name, value, updateHandler and documentation.
Definition: Property.h:404
void clearLower()
Clear lower bound value.
Definition: Property.h:256
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:89
AttribStringParser::Iterator begin(const AttribStringParser &parser)
bool hasUpper() const
Return if it has a lower bound.
Definition: Property.h:239
const GaudiHandleBase & value() const
Definition: Property.h:866
implementation of various functions for streaming.
Property(T &&v)
Construct an anonymous property from a value.
Definition: Property.h:439
Gaudi::Property< unsigned short & > UnsignedShortPropertyRef
Definition: Property.h:752
Gaudi::Property< std::vector< float > > FloatArrayProperty
Definition: Property.h:778
ValueType operator++(int)
Definition: Property.h:600
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:287
#define GAUDI_API
Definition: Kernel.h:71
GaudiHandleProperty & operator=(const GaudiHandleBase &value)
Definition: Property.h:849
Gaudi::Property< std::vector< short > & > ShortArrayPropertyRef
Definition: Property.h:789
STL class.
Property(OWNER *owner, std::string name, T &&value, std::string doc="")
Autodeclaring constructor with property name, value and documentation.
Definition: Property.h:395
virtual std::string toString() const =0
value -> string
Details::PropertyBase & declareReadHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for reading
Definition: Property.h:450
void useUpdateHandler(const PropertyBase &) const
Definition: Property.h:301
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Property< unsigned char > UnsignedCharProperty
Definition: Property.h:731
VerifierType m_verifier
Definition: Property.h:365
Gaudi::Property< short & > ShortPropertyRef
Definition: Property.h:751
void setUpper(const TYPE &value)
Set upper bound value.
Definition: Property.h:251
std::string documentation() const
property documentation
Definition: Property.h:38
void setReadHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:297
Details::Property::UpdateHandler HandlersType
Definition: Property.h:359
Gaudi::Property< unsigned char & > UnsignedCharPropertyRef
Definition: Property.h:750
ValueType operator--(int)
Definition: Property.h:609
Gaudi::Property< std::vector< bool > > BooleanArrayProperty
Definition: Property.h:766
Gaudi::Property< std::vector< unsigned int > & > UnsignedIntegerArrayPropertyRef
Definition: Property.h:792
bool operator==(const T &other) const
equality comparison
Definition: Property.h:488
const std::function< void(Details::PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: Property.h:465
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:676
GAUDI_API Gaudi::Details::PropertyBase * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
Definition: Property.cpp:204
Gaudi::Property< bool & > BooleanPropertyRef
Definition: Property.h:747
void useUpdateHandler(PropertyBase &p)
Definition: Property.h:317
void useReadHandler() const
use the call-back function at reading, if available
Definition: Property.h:829