The Gaudi Framework  v33r1 (b1225454)
Property.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_PROPERTY_H
12 #define GAUDIKERNEL_PROPERTY_H
13 // ============================================================================
14 // STD & STL
15 // ============================================================================
16 #include <stdexcept>
17 #include <string>
18 #include <string_view>
19 #include <typeinfo>
20 // ============================================================================
21 // Application C++ Class Headers
22 // ============================================================================
23 #include "GaudiKernel/IProperty.h"
24 #include "GaudiKernel/Kernel.h"
26 #include "GaudiKernel/SmartIF.h"
27 #include "GaudiKernel/TaggedBool.h"
28 #include "GaudiKernel/ToStream.h"
31 
32 namespace Gaudi {
33  namespace Details {
34  // ============================================================================
43 
44  public:
46  const std::string name() const { return std::string{m_name}; }
48  std::string documentation() const { return std::string{m_documentation}; }
50  std::string semantics() const { return std::string{m_semantics}; }
52  const std::type_info* type_info() const { return m_typeinfo; }
54  std::string type() const { return m_typeinfo->name(); }
56  virtual bool load( PropertyBase& dest ) const = 0;
58  virtual bool assign( const PropertyBase& source ) = 0;
59 
60  public:
62  virtual std::string toString() const = 0;
64  virtual void toStream( std::ostream& out ) const = 0;
66  virtual StatusCode fromString( const std::string& value ) = 0;
67 
68  public:
70  virtual PropertyBase& declareReadHandler( std::function<void( PropertyBase& )> fun ) = 0;
72  virtual PropertyBase& declareUpdateHandler( std::function<void( PropertyBase& )> fun ) = 0;
73 
75  virtual const std::function<void( PropertyBase& )> readCallBack() const = 0;
77  virtual const std::function<void( PropertyBase& )> updateCallBack() const = 0;
78 
80  virtual bool useUpdateHandler() = 0;
81 
82  template <class HT>
83  PropertyBase& declareReadHandler( void ( HT::*MF )( PropertyBase& ), HT* instance ) {
84  return declareReadHandler( [=]( PropertyBase& p ) { ( instance->*MF )( p ); } );
85  }
86 
87  template <class HT>
88  PropertyBase& declareUpdateHandler( void ( HT::*MF )( PropertyBase& ), HT* instance ) {
89  return declareUpdateHandler( [=]( PropertyBase& p ) { ( instance->*MF )( p ); } );
90  }
91 
92  public:
94  virtual ~PropertyBase() = default;
96  void setName( std::string value ) { m_name = to_view( std::move( value ) ); }
98  void setDocumentation( std::string value ) { m_documentation = to_view( std::move( value ) ); }
100  void setSemantics( std::string value ) { m_semantics = to_view( std::move( value ) ); }
102  virtual std::ostream& fillStream( std::ostream& ) const;
104  virtual PropertyBase* clone() const = 0;
105 
107  void setOwnerType( const std::type_info& ownerType ) { m_ownerType = &ownerType; }
108 
110  template <class OWNER>
111  void setOwnerType() {
112  setOwnerType( typeid( OWNER ) );
113  }
114 
116  const std::type_info* ownerType() const { return m_ownerType; }
117 
120  return m_ownerType ? System::typeinfoName( *m_ownerType ) : std::string( "unknown owner type" );
121  }
122 
123  protected:
126  std::string semantics = "" )
127  : m_name( to_view( std::move( name ) ) )
128  , m_documentation( to_view( std::move( doc ) ) )
129  , m_semantics( to_view( std::move( semantics ) ) )
130  , m_typeinfo( &type ) {}
133  : m_name( to_view( std::move( name ) ) ), m_documentation( m_name ), m_typeinfo( &type ) {}
135  PropertyBase( const PropertyBase& ) = default;
137  PropertyBase& operator=( const PropertyBase& ) = default;
138 
139  private:
141  static std::string_view to_view( std::string str );
143  std::string_view m_name;
145  std::string_view m_documentation;
147  std::string_view m_semantics;
151  const std::type_info* m_ownerType = nullptr;
152  };
153 
154  inline std::ostream& operator<<( std::ostream& stream, const PropertyBase& prop ) {
155  return prop.fillStream( stream );
156  }
157 
158  namespace Property {
159  using ImmediatelyInvokeHandler = Gaudi::tagged_bool<class ImmediatelyInvokeHandler_tag>;
160 
161  // ==========================================================================
162  // The following code is going to be a bit unpleasant, but as far as its
163  // author can tell, it is as simple as the design constraints and C++'s
164  // implementation constraints will allow. If you disagree, please submit
165  // a patch which simplifies it. Here is the underlying design rationale:
166  //
167  // - For any given type T used in a Property, we want to have an
168  // associated StringConverter<T> struct which explains how to convert a
169  // value of that type into a string (toString) and parse that string
170  // back (fromString).
171  // - There is a default implementation, called DefaultStringConverter<T>,
172  // which is based on the overloadable parse() and toStream() global
173  // methods of Gaudi. Its exact behaviour varies depending on whether T
174  // is default-constructible or only copy-constructible, which requires a
175  // layer of SFINAE indirection.
176  // - Some people want to be able to specialize StringConverter as an
177  // alternative to defining parse/toStream overloads. This interferes
178  // with the SFINAE tricks used by DefaultStringConverter, so we cannot
179  // just call a DefaultStringConverter a StringConverter and must add one
180  // more layer to the StringConverter type hierarchy.
181 
182  // This class factors out commonalities between DefaultStringConverters
183  template <class TYPE>
185  public:
186  virtual ~DefaultStringConverterImpl() = default;
187  std::string toString( const TYPE& v ) {
189  return toString( v );
190  }
191 
192  // Implementation of fromString depends on whether TYPE is default-
193  // constructible (fastest, easiest) or only copy-constructible (still
194  // doable as long as the caller can provide a valid value of TYPE)
195  virtual TYPE fromString( const TYPE& ref_value, const std::string& s ) = 0;
196 
197  protected:
198  void fromStringImpl( TYPE& buffer, const std::string& s ) {
200  if ( !parse( buffer, InputData{s} ).isSuccess() ) {
201  throw std::invalid_argument( "cannot parse '" + s + "' to " + System::typeinfoName( typeid( TYPE ) ) );
202  }
203  }
204  };
205  // Specialization of toString for strings (identity function)
206  template <>
208  return v;
209  }
210 
211  // This class provides a default implementation of StringConverter based
212  // on the overloadable parse() and toStream() global Gaudi methods.
213  //
214  // It leverages the fact that TYPE is default-constructible if it can, and
215  // falls back fo a requirement of copy-constructibility if it must. So
216  // here is the "default" implementation for copy-constructible types...
217  //
218  template <typename TYPE, typename Enable = void>
220  TYPE fromString( const TYPE& ref_value, const std::string& s ) final override {
221  TYPE buffer = ref_value;
222  this->fromStringImpl( buffer, s );
223  return buffer;
224  }
225  };
226  // ...and here is the preferred impl for default-constructible types:
227  template <class TYPE>
228  struct DefaultStringConverter<TYPE, std::enable_if_t<std::is_default_constructible_v<TYPE>>>
230  TYPE fromString( const TYPE& /* ref_value */, const std::string& s ) final override {
231  TYPE buffer{};
232  this->fromStringImpl( buffer, s );
233  return buffer;
234  }
235  };
236 
237  // Specializable StringConverter struct with a default implementation
238  template <typename TYPE>
239  struct StringConverter : DefaultStringConverter<TYPE> {};
240 
241  struct NullVerifier {
242  template <class TYPE>
243  void operator()( const TYPE& ) const {}
244  };
245  template <class TYPE>
247  void operator()( const TYPE& value ) const {
249  // throw the exception if the limit is defined and value is outside
250  if ( ( m_hasLowerBound && ( value < m_lowerBound ) ) || ( m_hasUpperBound && ( m_upperBound < value ) ) )
251  throw std::out_of_range( "value " + toString( value ) + " outside range" );
252  }
253 
255  bool hasLower() const { return m_hasLowerBound; }
257  bool hasUpper() const { return m_hasUpperBound; }
259  const TYPE& lower() const { return m_lowerBound; }
261  const TYPE& upper() const { return m_upperBound; }
262 
264  void setLower( const TYPE& value ) {
265  m_hasLowerBound = true;
266  m_lowerBound = value;
267  }
269  void setUpper( const TYPE& value ) {
270  m_hasUpperBound = true;
271  m_upperBound = value;
272  }
274  void clearLower() {
275  m_hasLowerBound = false;
276  m_lowerBound = TYPE();
277  }
279  void clearUpper() {
280  m_hasUpperBound = false;
281  m_upperBound = TYPE();
282  }
283 
285  void setBounds( const TYPE& lower, const TYPE& upper ) {
286  setLower( lower );
287  setUpper( upper );
288  }
289 
291  void clearBounds() {
292  clearLower();
293  clearUpper();
294  }
295 
296  private:
298  bool m_hasLowerBound{false};
299  bool m_hasUpperBound{false};
300  TYPE m_lowerBound{};
301  TYPE m_upperBound{};
302  };
303 
305  struct SwapCall {
308  SwapCall( callback_t& input ) : orig( input ) { tmp.swap( orig ); }
309  ~SwapCall() { orig.swap( tmp ); }
310  void operator()( PropertyBase& p ) const { tmp( p ); }
311  };
312 
313  struct NoHandler {
314  void useReadHandler( const PropertyBase& ) const {}
316  throw std::logic_error( "setReadHandler not implemented for this class" );
317  }
318  std::function<void( PropertyBase& )> getReadHandler() const { return nullptr; }
319  void useUpdateHandler( const PropertyBase& ) const {}
321  throw std::logic_error( "setUpdateHandler not implemented for this class" );
322  }
323  std::function<void( PropertyBase& )> getUpdateHandler() const { return nullptr; }
324  };
327  void useReadHandler( const PropertyBase& p ) const {
328  if ( m_readCallBack ) { SwapCall{m_readCallBack}( const_cast<PropertyBase&>( p ) ); }
329  }
332  };
336  if ( m_updateCallBack ) {
337  try {
339  } catch ( const std::exception& x ) {
340  throw std::invalid_argument( "failure in update handler of '" + p.name() + "': " + x.what() );
341  }
342  }
343  }
346  };
354  };
355  } // namespace Property
356 
357  } // namespace Details
358 
359  // ============================================================================
367  // ============================================================================
368  template <class TYPE, class VERIFIER = Details::Property::NullVerifier,
369  class HANDLERS = Details::Property::UpdateHandler>
371  public:
372  // ==========================================================================
374  using StorageType = TYPE;
376  using VerifierType = VERIFIER;
377  using HandlersType = HANDLERS;
378  // ==========================================================================
379 
380  private:
387  template <class T>
388  static inline constexpr bool is_this_type_v = std::is_same_v<Property, std::remove_reference_t<T>>;
389  template <class T>
390  using not_copying = std::enable_if_t<!is_this_type_v<T>>;
392  public:
393  // ==========================================================================
395  template <class T = StorageType>
397  : Details::PropertyBase( typeid( ValueType ), std::move( name ), std::move( doc ), std::move( semantics ) )
398  , m_value( std::forward<T>( value ) ) {
399  m_verifier( m_value );
400  }
403  template <typename OWNER, typename T = ValueType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>,
404  typename = std::enable_if_t<std::is_default_constructible_v<T>>>
405  Property( OWNER* owner, std::string name ) : Property( std::move( name ), ValueType{}, "" ) {
406  owner->declareProperty( *this );
407  setOwnerType<OWNER>();
408  }
409 
412  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
413  Property( OWNER* owner, std::string name, T&& value, std::string doc = "", std::string semantics = "" )
414  : Property( std::move( name ), std::forward<T>( value ), std::move( doc ), std::move( semantics ) ) {
415  owner->declareProperty( *this );
416  setOwnerType<OWNER>();
417  }
418 
421  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
422  Property( OWNER* owner, std::string name, T&& value, std::function<void( PropertyBase& )> handler,
423  std::string doc = "", std::string semantics = "" )
424  : Property( owner, std::move( name ), std::forward<T>( value ), std::move( doc ), std::move( semantics ) ) {
425  declareUpdateHandler( std::move( handler ) );
426  }
427 
430  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
431  Property( OWNER* owner, std::string name, T&& value, void ( OWNER::*handler )( PropertyBase& ),
432  std::string doc = "", std::string semantics = "" )
433  : Property(
434  owner, std::move( name ), std::forward<T>( value ),
435  [owner, handler]( PropertyBase& p ) { ( owner->*handler )( p ); }, std::move( doc ),
436  std::move( semantics ) ) {}
439  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
440  Property( OWNER* owner, std::string name, T&& value, void ( OWNER::*handler )(), std::string doc = "",
441  std::string semantics = "" )
442  : Property(
443  owner, std::move( name ), std::forward<T>( value ),
444  [owner, handler]( PropertyBase& ) { ( owner->*handler )(); }, std::move( doc ), std::move( semantics ) ) {
445  }
446 
449  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of_v<IProperty, OWNER>>>
450  Property( OWNER* owner, std::string name, T&& value, std::function<void( PropertyBase& )> handler,
452  : Property( owner, std::move( name ), std::forward<T>( value ), std::move( handler ), std::move( doc ),
453  std::move( semantics ) ) {
454  if ( invoke ) useUpdateHandler();
455  }
456 
460  template <typename T, typename = not_copying<T>>
461  Property( T&& v ) : Details::PropertyBase( typeid( ValueType ), "", "" ), m_value( std::forward<T>( v ) ) {}
462 
465  template <typename T = StorageType, typename = std::enable_if_t<!std::is_reference_v<T>>>
466  Property() : Details::PropertyBase( typeid( ValueType ), "", "" ), m_value() {}
467 
470 
473  m_handlers.setReadHandler( std::move( fun ) );
474  return *this;
475  }
478  m_handlers.setUpdateHandler( std::move( fun ) );
479  return *this;
480  }
481 
483  const std::function<void( Details::PropertyBase& )> readCallBack() const override {
484  return m_handlers.getReadHandler();
485  }
487  const std::function<void( Details::PropertyBase& )> updateCallBack() const override {
488  return m_handlers.getUpdateHandler();
489  }
490 
492  bool useUpdateHandler() override {
493  m_handlers.useUpdateHandler( *this );
494  return true;
495  }
496 
498  operator const ValueType&() const {
499  m_handlers.useReadHandler( *this );
500  return m_value;
501  }
502  // /// Automatic conversion to value (reference).
503  // operator ValueType& () {
504  // useReadHandler();
505  // return m_value;
506  // }
507 
508  template <typename Dummy = TYPE, typename = std::enable_if_t<std::is_constructible_v<std::string_view, Dummy>>>
509  operator std::string_view() const {
510  m_handlers.useReadHandler( *this );
511  return m_value;
512  }
513 
515  template <class T>
516  bool operator==( const T& other ) const {
517  return m_value == other;
518  }
519 
521  template <class T>
522  bool operator!=( const T& other ) const {
523  return m_value != other;
524  }
525 
527  template <class T>
528  bool operator<( const T& other ) const {
529  return m_value < other;
530  }
531 
533  template <class T>
534  decltype( auto ) operator+( const T& other ) const {
535  return m_value + other;
536  }
537 
539  template <class T = ValueType>
540  Property& operator=( T&& v ) {
541  m_verifier( v );
542  m_value = std::forward<T>( v );
543  m_handlers.useUpdateHandler( *this );
544  return *this;
545  }
546 
548  const VerifierType& verifier() const { return m_verifier; }
551 
554  const ValueType& value() const { return *this; }
555  ValueType& value() { return const_cast<ValueType&>( (const ValueType&)*this ); }
556  bool setValue( const ValueType& v ) {
557  *this = v;
558  return true;
559  }
560  bool set( const ValueType& v ) {
561  *this = v;
562  return true;
563  }
564  Details::PropertyBase* clone() const override { return new Property( *this ); }
566 
570  template <class T = const ValueType>
571  decltype( auto ) size() const {
572  return value().size();
573  }
574  template <class T = const ValueType>
575  decltype( auto ) length() const {
576  return value().length();
577  }
578  template <class T = const ValueType>
579  decltype( auto ) empty() const {
580  return value().empty();
581  }
582  template <class T = ValueType>
583  decltype( auto ) clear() {
584  value().clear();
585  }
586  template <class T = const ValueType>
587  decltype( auto ) begin() const {
588  return value().begin();
589  }
590  template <class T = const ValueType>
591  decltype( auto ) end() const {
592  return value().end();
593  }
594  template <class T = ValueType>
595  decltype( auto ) begin() {
596  return value().begin();
597  }
598  template <class T = ValueType>
599  decltype( auto ) end() {
600  return value().end();
601  }
602  template <class ARG>
603  decltype( auto ) operator[]( const ARG& arg ) const {
604  return value()[arg];
605  }
606  template <class ARG>
607  decltype( auto ) operator[]( const ARG& arg ) {
608  return value()[arg];
609  }
610  template <class T = const ValueType>
611  decltype( auto ) find( const typename T::key_type& key ) const {
612  return value().find( key );
613  }
614  template <class T = ValueType>
615  decltype( auto ) find( const typename T::key_type& key ) {
616  return value().find( key );
617  }
618  template <class ARG, class T = ValueType>
619  decltype( auto ) erase( ARG arg ) {
620  return value().erase( arg );
621  }
622  template <class = ValueType>
624  ++value();
625  return *this;
626  }
627  template <class = ValueType>
629  return m_value++;
630  }
631  template <class = ValueType>
633  --value();
634  return *this;
635  }
636  template <class = ValueType>
638  return m_value--;
639  }
640  template <class T = ValueType>
641  Property& operator+=( const T& other ) {
642  m_value += other;
643  return *this;
644  }
645  template <class T = ValueType>
646  Property& operator-=( const T& other ) {
647  m_value -= other;
648  return *this;
649  }
651  template <class T = const ValueType>
652  decltype( auto ) key() const {
653  return value().key();
654  }
655  template <class T = const ValueType>
656  decltype( auto ) objKey() const {
657  return value().objKey();
658  }
659  template <class T = const ValueType>
660  decltype( auto ) fullKey() const {
661  return value().fullKey();
662  }
663  template <class T = ValueType>
664  decltype( auto ) initialize() {
665  return value().initialize();
666  }
667  template <class T = ValueType>
668  decltype( auto ) makeHandles() const {
669  return value().makeHandles();
670  }
671  template <class ARG, class T = ValueType>
672  decltype( auto ) makeHandles( const ARG& arg ) const {
673  return value().makeHandles( arg );
674  }
676  // ==========================================================================
677 
678  // Delegate operator() to the value
679  template <class... Args>
680  decltype( std::declval<ValueType>()( std::declval<Args&&>()... ) ) operator()( Args&&... args ) const
681  noexcept( noexcept( std::declval<ValueType>()( std::declval<Args&&>()... ) ) ) {
682  return value()( std::forward<Args>( args )... );
683  }
684 
685  public:
687  bool assign( const Details::PropertyBase& source ) override {
688  // Check if the property of is of "the same" type, except for strings
689  const Property* p =
690  ( std::is_same_v<ValueType, std::string> ) ? nullptr : dynamic_cast<const Property*>( &source );
691  if ( p ) {
692  *this = p->value();
693  } else {
694  this->fromString( source.toString() ).ignore();
695  }
696  return true;
697  }
699  bool load( Details::PropertyBase& dest ) const override {
700  // delegate to the 'opposite' method
701  return dest.assign( *this );
702  }
704  StatusCode fromString( const std::string& source ) override {
705  using Converter = Details::Property::StringConverter<ValueType>;
706  *this = Converter().fromString( m_value, source );
707  return StatusCode::SUCCESS;
708  }
710  std::string toString() const override {
711  using Converter = Details::Property::StringConverter<ValueType>;
712  return Converter().toString( *this );
713  }
715  void toStream( std::ostream& out ) const override {
716  m_handlers.useReadHandler( *this );
717  using Utils::toStream;
718  toStream( m_value, out );
719  }
720  };
721 
723  template <class T, class TP, class V, class H>
724  bool operator==( const T& v, const Property<TP, V, H>& p ) {
725  return p == v;
726  }
727 
729  template <class T, class TP, class V, class H>
730  bool operator!=( const T& v, const Property<TP, V, H>& p ) {
731  return p != v;
732  }
733 
735  template <class T, class TP, class V, class H>
736  decltype( auto ) operator+( const T& v, const Property<TP, V, H>& p ) {
737  return v + p.value();
738  }
739 
740  template <class TYPE, class HANDLERS = Details::Property::UpdateHandler>
742 
743  template <class TYPE>
746 
747 } // namespace Gaudi
748 
749 template <class TYPE>
751 
752 template <class TYPE>
754 
755 // Typedef Properties for built-in types
771 
773 
774 // Typedef PropertyRefs for built-in types
790 
792 
793 // Typedef "Arrays" of Properties for built-in types
809 
811 
812 // Typedef "Arrays" of PropertyRefs for built-in types
828 
830 
833 template <typename Handler = typename Gaudi::Details::Property::UpdateHandler>
835  Handler m_handlers;
836 
837 public:
838  using PropertyBase::PropertyBase;
839 
842  m_handlers.setReadHandler( std::move( fun ) );
843  return *this;
844  }
847  m_handlers.setUpdateHandler( std::move( fun ) );
848  return *this;
849  }
850 
852  const std::function<void( PropertyBase& )> readCallBack() const override { return m_handlers.getReadHandler(); }
854  const std::function<void( PropertyBase& )> updateCallBack() const override { return m_handlers.getUpdateHandler(); }
855 
857  void useReadHandler() const { m_handlers.useReadHandler( *this ); }
858 
860  bool useUpdateHandler() override {
861  m_handlers.useUpdateHandler( *this );
862  return true;
863  }
864 };
865 
866 // forward-declaration is sufficient here
867 class GaudiHandleBase;
868 
869 // implementation in header file only where the GaudiHandleBase class
870 // definition is not needed. The rest goes into the .cpp file.
871 // The goal is to decouple the header files, to avoid that the whole
872 // world depends on GaudiHandle.h
874 public:
876 
878  setValue( value );
879  return *this;
880  }
881 
882  GaudiHandleProperty* clone() const override { return new GaudiHandleProperty( *this ); }
883 
884  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
885 
886  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
887 
888  std::string toString() const override;
889 
890  void toStream( std::ostream& out ) const override;
891 
892  StatusCode fromString( const std::string& s ) override;
893 
894  const GaudiHandleBase& value() const {
895  useReadHandler();
896  return *m_pValue;
897  }
898 
899  bool setValue( const GaudiHandleBase& value );
900 
901 private:
905 };
906 
907 // forward-declaration is sufficient here
909 
911 public:
913 
915  setValue( value );
916  return *this;
917  }
918 
919  GaudiHandleArrayProperty* clone() const override { return new GaudiHandleArrayProperty( *this ); }
920 
921  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
922 
923  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
924 
925  std::string toString() const override;
926 
927  void toStream( std::ostream& out ) const override;
928 
929  StatusCode fromString( const std::string& s ) override;
930 
931  const GaudiHandleArrayBase& value() const {
932  useReadHandler();
933  return *m_pValue;
934  }
935 
936  bool setValue( const GaudiHandleArrayBase& value );
937 
938 private:
942 };
943 
944 namespace Gaudi {
945  namespace Utils {
946  // ========================================================================
964  GAUDI_API bool hasProperty( const IProperty* p, const std::string& name );
965  // ========================================================================
983  GAUDI_API bool hasProperty( const IInterface* p, const std::string& name );
984  // ========================================================================
1003  // ========================================================================
1022  // ========================================================================
1046  // ========================================================================
1071  // ========================================================================
1095  template <class TYPE>
1096  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc );
1097  // ========================================================================
1120  template <class TYPE>
1121  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value ) {
1122  return setProperty( component, name, value, std::string() );
1123  }
1124  // ========================================================================
1138  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const std::string& value,
1139  const std::string& doc = "" );
1140  // ========================================================================
1154  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const char* value,
1155  const std::string& doc = "" );
1156  // ========================================================================
1170  template <unsigned N>
1171  StatusCode setProperty( IProperty* component, const std::string& name, const char ( &value )[N],
1172  const std::string& doc = "" ) {
1173  return component ? setProperty( component, name, std::string( value, value + N ), doc ) : StatusCode::FAILURE;
1174  }
1175  // ========================================================================
1206  template <class TYPE>
1207  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc ) {
1208  using Gaudi::Utils::toString;
1209  return component && hasProperty( component, name )
1210  ? Gaudi::Utils::setProperty( component, name, toString( value ), doc )
1212  }
1213  // ========================================================================
1236  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1237  // ========================================================================
1260  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1261  // ========================================================================
1284  template <class TYPE>
1286  const std::string& doc = "" ) {
1287  return setProperty( component, name, &value, doc );
1288  }
1289  // ========================================================================
1310  template <class TYPE>
1311  StatusCode setProperty( IInterface* component, const std::string& name, const TYPE& value,
1312  const std::string& doc = "" ) {
1313  if ( !component ) { return StatusCode::FAILURE; }
1314  auto property = SmartIF<IProperty>{component};
1315  return property ? setProperty( property, name, value, doc ) : StatusCode::FAILURE;
1316  }
1317  // ========================================================================
1330  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const std::string& value,
1331  const std::string& doc = "" );
1332  // ========================================================================
1345  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const char* value,
1346  const std::string& doc = "" );
1347  // ========================================================================
1361  template <unsigned N>
1362  StatusCode setProperty( IInterface* component, const std::string& name, const char ( &value )[N],
1363  const std::string& doc = "" ) {
1364  if ( 0 == component ) { return StatusCode::FAILURE; }
1365  return setProperty( component, name, std::string{value, value + N}, doc );
1366  }
1367  // ========================================================================
1390  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1391  // ========================================================================
1414  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1415  // ========================================================================
1438  template <class TYPE>
1440  const std::string& doc = "" ) {
1441  return setProperty( component, name, &value, doc );
1442  }
1443  // ========================================================================
1444  } // namespace Utils
1445 } // end of namespace Gaudi
1446 // ============================================================================
1447 // The END
1448 // ============================================================================
1449 #endif // GAUDIKERNEL_PROPERTY_H
Gaudi::Property< std::vector< float > & > FloatArrayPropertyRef
Definition: Property.h:825
std::string toString() const override
value -> string
Definition: Property.h:710
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:1207
Gaudi::Property< signed char & > SignedCharPropertyRef
Definition: Property.h:777
Details::Property::NullVerifier VerifierType
Definition: Property.h:376
Gaudi::Property< std::vector< signed char > & > SignedCharArrayPropertyRef
Definition: Property.h:815
std::string_view m_semantics
property semantics
Definition: Property.h:147
constexpr auto size(const T &, Args &&...) noexcept
Property(OWNER *owner, std::string name)
Autodeclaring constructor with property name, value and documentation.
Definition: Property.h:405
std::function< void(PropertyBase &)> m_readCallBack
Definition: Property.h:326
std::function< void(PropertyBase &)> getUpdateHandler() const
Definition: Property.h:345
void setSemantics(std::string value)
set the semantics string
Definition: Property.h:100
Gaudi::Property< unsigned int & > UnsignedIntegerPropertyRef
Definition: Property.h:782
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:220
bool operator!=(const T &v, const Property< TP, V, H > &p)
delegate (value != property) to property operator!=
Definition: Property.h:730
bool setValue(const ValueType &v)
Definition: Property.h:556
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:291
Gaudi::Property< std::vector< unsigned short > > UnsignedShortArrayProperty
Definition: Property.h:799
Gaudi::Property< TYPE > SimpleProperty
Definition: Property.h:750
Gaudi::Property< long long & > LongLongPropertyRef
Definition: Property.h:785
PropertyBase & declareReadHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Definition: Property.h:83
static constexpr bool is_this_type_v
helper typedefs for SFINAE
Definition: Property.h:388
Gaudi::Property< std::vector< int > > IntegerArrayProperty
Definition: Property.h:800
std::ostream & operator<<(std::ostream &stream, const PropertyBase &prop)
Definition: Property.h:154
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
Definition: Property.h:724
bool useUpdateHandler() override
manual trigger for callback for update
Definition: Property.h:492
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:98
Gaudi::Property< long long > LongLongProperty
Definition: Property.h:766
const GaudiHandleArrayBase & value() const
Definition: Property.h:931
Implementation of property with value of concrete type.
Definition: Property.h:370
Gaudi::Property< long & > LongPropertyRef
Definition: Property.h:783
std::enable_if_t<!is_this_type_v< T > > not_copying
Definition: Property.h:390
std::function< void(PropertyBase &)> m_updateCallBack
Definition: Property.h:334
Property(OWNER *owner, std::string name, T &&value, void(OWNER::*handler)(PropertyBase &), std::string doc="", std::string semantics="")
Autodeclaring constructor with property name, value, pointer to member function updateHandler and doc...
Definition: Property.h:431
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:308
Gaudi::Property< std::vector< double > & > DoubleArrayPropertyRef
Definition: Property.h:826
bool load(PropertyBase &destination) const override
Definition: Property.h:921
std::string ownerTypeName() const
get the string for the type of the owner class (used for documentation)
Definition: Property.h:119
T swap(T... args)
bool hasLower() const
Return if it has a lower bound.
Definition: Property.h:255
Property & operator=(T &&v)
Assignment from value.
Definition: Property.h:540
Gaudi::Property< float > FloatProperty
Definition: Property.h:768
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:852
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:105
Gaudi::Property< int > IntegerProperty
Definition: Property.h:762
Gaudi::Property< std::vector< unsigned long long > & > UnsignedLongLongArrayPropertyRef
Definition: Property.h:824
void setOwnerType()
set the type of the owner class (used for documentation)
Definition: Property.h:111
void clearUpper()
Clear upper bound value.
Definition: Property.h:279
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:341
Gaudi::tagged_bool< class ImmediatelyInvokeHandler_tag > ImmediatelyInvokeHandler
Definition: Property.h:159
Gaudi::Property< unsigned long long > UnsignedLongLongProperty
Definition: Property.h:767
Gaudi::Property< float & > FloatPropertyRef
Definition: Property.h:787
vector< std::string > StorageType
Hosted type.
Definition: Property.h:374
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std::function< void(PropertyBase &)> getReadHandler() const
Definition: Property.h:318
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:810
Gaudi::Property< std::vector< unsigned short > & > UnsignedShortArrayPropertyRef
Definition: Property.h:818
Gaudi::Property< std::vector< unsigned char > > UnsignedCharArrayProperty
Definition: Property.h:797
const TYPE & upper() const
Return the upper bound value.
Definition: Property.h:261
void setLower(const TYPE &value)
Set lower bound value.
Definition: Property.h:264
HandlersType m_handlers
Definition: Property.h:384
Gaudi::Property< unsigned short > UnsignedShortProperty
Definition: Property.h:761
Gaudi::Property< unsigned long > UnsignedLongProperty
Definition: Property.h:765
bool load(PropertyBase &destination) const override
Definition: Property.h:884
const std::function< void(Details::PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:483
Gaudi::Property< std::string & > StringPropertyRef
Definition: Property.h:791
StorageType m_value
Storage.
Definition: Property.h:382
std::string_view m_name
property name
Definition: Property.h:143
Property(OWNER *owner, std::string name, T &&value, void(OWNER::*handler)(), std::string doc="", std::string semantics="")
Autodeclaring constructor with property name, value, pointer to member function updateHandler and doc...
Definition: Property.h:440
Gaudi::Property< char & > CharPropertyRef
Definition: Property.h:776
const std::string name() const
property name
Definition: Property.h:46
Gaudi::Property< std::vector< bool > & > BooleanArrayPropertyRef
Definition: Property.h:813
Gaudi::Property< std::vector< long double > > LongDoubleArrayProperty
Definition: Property.h:808
Gaudi::Property< std::vector< long long > > LongLongArrayProperty
Definition: Property.h:804
Gaudi::Property< std::vector< double > > DoubleArrayProperty
Definition: Property.h:807
void setOwnerType(const std::type_info &ownerType)
set the type of the owner class (used for documentation)
Definition: Property.h:107
Gaudi::Property< std::vector< short > > ShortArrayProperty
Definition: Property.h:798
Gaudi::Property< std::vector< unsigned long > & > UnsignedLongArrayPropertyRef
Definition: Property.h:822
Gaudi::Property< std::vector< unsigned int > > UnsignedIntegerArrayProperty
Definition: Property.h:801
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
Details::PropertyBase & declareUpdateHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:477
Property()
Construct an anonymous property with default constructed value.
Definition: Property.h:466
virtual StatusCode fromString(const std::string &value)=0
string -> value
Property(OWNER *owner, std::string name, T &&value, std::function< void(PropertyBase &)> handler, Details::Property::ImmediatelyInvokeHandler invoke, std::string doc="", std::string semantics="")
Autodeclaring constructor with property name, value, updateHandler and documentation.
Definition: Property.h:450
Helper class to simplify the migration old properties deriving directly from PropertyBase.
Definition: Property.h:834
void operator()(const TYPE &) const
Definition: Property.h:243
STL class.
Property & operator+=(const T &other)
Definition: Property.h:641
const std::type_info * type_info() const
property type-info
Definition: Property.h:52
Gaudi::Property< std::vector< long > > LongArrayProperty
Definition: Property.h:802
typename std::remove_reference< StorageType >::type ValueType
Definition: Property.h:375
Gaudi::Property< std::vector< long > & > LongArrayPropertyRef
Definition: Property.h:821
Gaudi::Property< signed char > SignedCharProperty
Definition: Property.h:758
std::string semantics() const
property semantics
Definition: Property.h:50
Details::PropertyBase * clone() const override
clones the current property
Definition: Property.h:564
PropertyBase(const std::type_info &type, std::string name="", std::string doc="", std::string semantics="")
constructor from the property name and the type
Definition: Property.h:125
Gaudi::Property< char > CharProperty
Definition: Property.h:757
int N
Definition: IOTest.py:110
Property & operator-=(const T &other)
Definition: Property.h:646
Gaudi::Property< int & > IntegerPropertyRef
Definition: Property.h:781
GaudiHandleBase * m_pValue
Pointer to the real property.
Definition: Property.h:904
Gaudi::Property< unsigned long & > UnsignedLongPropertyRef
Definition: Property.h:784
const TYPE & lower() const
Return the lower bound value.
Definition: Property.h:259
GaudiHandleProperty * clone() const override
clones the current property
Definition: Property.h:882
Property & operator++()
Definition: Property.h:623
T what(T... args)
PropertyBase(std::string name, const std::type_info &type)
constructor from the property name and the type
Definition: Property.h:132
void setBounds(const TYPE &lower, const TYPE &upper)
Set both bounds (lower and upper) at the same time.
Definition: Property.h:285
void operator()(PropertyBase &p) const
Definition: Property.h:310
Gaudi::Property< std::vector< long double > & > LongDoubleArrayPropertyRef
Definition: Property.h:827
bool load(Details::PropertyBase &dest) const override
set value to another property
Definition: Property.h:699
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
void useReadHandler(const PropertyBase &) const
Definition: Property.h:314
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:554
Definition of the basic interface.
Definition: IInterface.h:254
const std::type_info * m_typeinfo
property type
Definition: Property.h:149
Gaudi::Property< unsigned int > UnsignedIntegerProperty
Definition: Property.h:763
Property(OWNER *owner, std::string name, T &&value, std::string doc="", std::string semantics="")
Autodeclaring constructor with property name, value and documentation.
Definition: Property.h:413
void toStream(std::ostream &out) const override
value -> stream
Definition: Property.h:715
std::function< void(PropertyBase &)> getReadHandler() const
Definition: Property.h:331
Gaudi::Property< std::vector< char > > CharArrayProperty
Definition: Property.h:795
virtual PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun)=0
set new callback for reading
Gaudi::Property< bool > BooleanProperty
Definition: Property.h:756
const std::type_info * ownerType() const
get the type of the owner class (used for documentation)
Definition: Property.h:116
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:846
Gaudi::Property< std::vector< unsigned long long > > UnsignedLongLongArrayProperty
Definition: Property.h:805
VerifierType & verifier()
Accessor to verifier.
Definition: Property.h:550
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
Definition: Property.h:841
bool operator<(const T &other) const
"less" comparison
Definition: Property.h:528
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
def end
Definition: IOTest.py:123
PropertyBase & declareUpdateHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Definition: Property.h:88
void fromStringImpl(TYPE &buffer, const std::string &s)
Definition: Property.h:198
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:93
std::string_view m_documentation
property doc string
Definition: Property.h:145
Gaudi::Property< double > DoubleProperty
Definition: Property.h:769
GaudiHandleArrayProperty * clone() const override
clones the current property
Definition: Property.h:919
Converter base class.
Definition: Converter.h:34
STL class.
void setName(std::string value)
set the new value for the property name
Definition: Property.h:96
Gaudi::Property< std::vector< int > & > IntegerArrayPropertyRef
Definition: Property.h:819
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
Definition: Property.cpp:59
T move(T... args)
bool assign(const PropertyBase &source) override
Definition: Property.h:923
Property & operator--()
Definition: Property.h:632
Gaudi::Property< std::vector< long long > & > LongLongArrayPropertyRef
Definition: Property.h:823
Gaudi::Property< double & > DoublePropertyRef
Definition: Property.h:788
void useReadHandler(const PropertyBase &p) const
Definition: Property.h:327
Gaudi::Property< std::vector< unsigned char > & > UnsignedCharArrayPropertyRef
Definition: Property.h:816
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:57
Base class of array's of various gaudihandles.
Definition: GaudiHandle.h:340
Gaudi::Property< long double & > LongDoublePropertyRef
Definition: Property.h:789
Property(std::string name, T &&value, std::string doc="", std::string semantics="")
the constructor with property name, value and documentation.
Definition: Property.h:396
ValueType & value()
Definition: Property.h:555
STL class.
std::string type() const
property type
Definition: Property.h:54
Helper class to enable ADL for parsers.
Definition: InputData.h:18
Gaudi::Property< std::vector< signed char > > SignedCharArrayProperty
Definition: Property.h:796
bool useUpdateHandler() override
use the call-back function at update, if available
Definition: Property.h:860
Gaudi::Property< std::string > StringProperty
Definition: Property.h:772
void setUpdateHandler(std::function< void(PropertyBase &)> fun)
Definition: Property.h:344
Gaudi::Property< long double > LongDoubleProperty
Definition: Property.h:770
GaudiHandleArrayProperty & operator=(const GaudiHandleArrayBase &value)
Definition: Property.h:914
SwapCall(callback_t &input)
Definition: Property.h:308
GaudiHandleArrayBase * m_pValue
Pointer to the real property.
Definition: Property.h:941
Gaudi::Property< short > ShortProperty
Definition: Property.h:760
bool set(const ValueType &v)
Definition: Property.h:560
std::function< void(PropertyBase &)> getUpdateHandler() const
Definition: Property.h:323
Gaudi::Property< std::vector< unsigned long > > UnsignedLongArrayProperty
Definition: Property.h:803
Property(OWNER *owner, std::string name, T &&value, std::function< void(PropertyBase &)> handler, std::string doc="", std::string semantics="")
Autodeclaring constructor with property name, value, updateHandler and documentation.
Definition: Property.h:422
Gaudi::Property< TYPE & > SimplePropertyRef
Definition: Property.h:753
string s
Definition: gaudirun.py:328
Gaudi::Property< unsigned long long & > UnsignedLongLongPropertyRef
Definition: Property.h:786
constexpr static const auto FAILURE
Definition: StatusCode.h:101
void operator()(const TYPE &value) const
Definition: Property.h:247
bool operator!=(const T &other) const
inequality comparison
Definition: Property.h:522
void clearBounds()
Clear both bounds (lower and upper) at the same time.
Definition: Property.h:291
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: Property.h:854
void setReadHandler(std::function< void(PropertyBase &)> fun)
Definition: Property.h:330
const VerifierType & verifier() const
Accessor to verifier.
Definition: Property.h:548
Gaudi::Property< std::vector< std::string > & > StringArrayPropertyRef
Definition: Property.h:829
bool assign(const Details::PropertyBase &source) override
get the value from another property
Definition: Property.h:687
bool assign(const PropertyBase &source) override
Definition: Property.h:886
Gaudi::Property< long > LongProperty
Definition: Property.h:764
void setUpdateHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:320
Gaudi::Property< std::vector< char > & > CharArrayPropertyRef
Definition: Property.h:814
void clearLower()
Clear lower bound value.
Definition: Property.h:274
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:99
AttribStringParser::Iterator begin(const AttribStringParser &parser)
bool hasUpper() const
Return if it has a lower bound.
Definition: Property.h:257
const GaudiHandleBase & value() const
Definition: Property.h:894
implementation of various functions for streaming.
Property(T &&v)
Construct an anonymous property from a value.
Definition: Property.h:461
Gaudi::Property< unsigned short & > UnsignedShortPropertyRef
Definition: Property.h:780
Gaudi::Property< std::vector< float > > FloatArrayProperty
Definition: Property.h:806
ValueType operator++(int)
Definition: Property.h:628
The IProperty is the basic interface for all components which have properties that can be set or get.
Definition: IProperty.h:30
helper to disable a while triggering it, to avoid infinite recursion
Definition: Property.h:305
#define GAUDI_API
Definition: Kernel.h:81
GaudiHandleProperty & operator=(const GaudiHandleBase &value)
Definition: Property.h:877
Gaudi::Property< std::vector< short > & > ShortArrayPropertyRef
Definition: Property.h:817
STL class.
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:472
void useUpdateHandler(const PropertyBase &) const
Definition: Property.h:319
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Property< unsigned char > UnsignedCharProperty
Definition: Property.h:759
VerifierType m_verifier
Definition: Property.h:383
Gaudi::Property< short & > ShortPropertyRef
Definition: Property.h:779
void setUpper(const TYPE &value)
Set upper bound value.
Definition: Property.h:269
std::string documentation() const
property documentation
Definition: Property.h:48
void setReadHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:315
Details::Property::UpdateHandler HandlersType
Definition: Property.h:377
Gaudi::Property< unsigned char & > UnsignedCharPropertyRef
Definition: Property.h:778
ValueType operator--(int)
Definition: Property.h:637
Gaudi::Property< std::vector< bool > > BooleanArrayProperty
Definition: Property.h:794
Gaudi::Property< std::vector< unsigned int > & > UnsignedIntegerArrayPropertyRef
Definition: Property.h:820
bool operator==(const T &other) const
equality comparison
Definition: Property.h:516
const std::function< void(Details::PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: Property.h:487
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:704
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:214
Gaudi::Property< bool & > BooleanPropertyRef
Definition: Property.h:775
void useUpdateHandler(PropertyBase &p)
Definition: Property.h:335
void useReadHandler() const
use the call-back function at reading, if available
Definition: Property.h:857