The Gaudi Framework  v33r2 (a6f0ec87)
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 
722 #if __cpp_impl_three_way_comparison < 201711
723  // Don't want this with c++20 --- it'll just call itself.
724  // The default c++20 rules will properly use Property::operator==.
726  template <class T, class TP, class V, class H>
727  bool operator==( const T& v, const Property<TP, V, H>& p ) {
728  return p == v;
729  }
730 #endif
731 
733  template <class T, class TP, class V, class H>
734  bool operator!=( const T& v, const Property<TP, V, H>& p ) {
735  return p != v;
736  }
737 
739  template <class T, class TP, class V, class H>
740  decltype( auto ) operator+( const T& v, const Property<TP, V, H>& p ) {
741  return v + p.value();
742  }
743 
744  template <class TYPE, class HANDLERS = Details::Property::UpdateHandler>
746 
747  template <class TYPE>
750 
751 } // namespace Gaudi
752 
753 template <class TYPE>
755 
756 template <class TYPE>
758 
759 // Typedef Properties for built-in types
775 
777 
778 // Typedef PropertyRefs for built-in types
794 
796 
797 // Typedef "Arrays" of Properties for built-in types
813 
815 
816 // Typedef "Arrays" of PropertyRefs for built-in types
832 
834 
837 template <typename Handler = typename Gaudi::Details::Property::UpdateHandler>
839  Handler m_handlers;
840 
841 public:
842  using PropertyBase::PropertyBase;
843 
846  m_handlers.setReadHandler( std::move( fun ) );
847  return *this;
848  }
851  m_handlers.setUpdateHandler( std::move( fun ) );
852  return *this;
853  }
854 
856  const std::function<void( PropertyBase& )> readCallBack() const override { return m_handlers.getReadHandler(); }
858  const std::function<void( PropertyBase& )> updateCallBack() const override { return m_handlers.getUpdateHandler(); }
859 
861  void useReadHandler() const { m_handlers.useReadHandler( *this ); }
862 
864  bool useUpdateHandler() override {
865  m_handlers.useUpdateHandler( *this );
866  return true;
867  }
868 };
869 
870 // forward-declaration is sufficient here
871 class GaudiHandleBase;
872 
873 // implementation in header file only where the GaudiHandleBase class
874 // definition is not needed. The rest goes into the .cpp file.
875 // The goal is to decouple the header files, to avoid that the whole
876 // world depends on GaudiHandle.h
878 public:
880 
882  setValue( value );
883  return *this;
884  }
885 
886  GaudiHandleProperty* clone() const override { return new GaudiHandleProperty( *this ); }
887 
888  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
889 
890  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
891 
892  std::string toString() const override;
893 
894  void toStream( std::ostream& out ) const override;
895 
896  StatusCode fromString( const std::string& s ) override;
897 
898  const GaudiHandleBase& value() const {
899  useReadHandler();
900  return *m_pValue;
901  }
902 
903  bool setValue( const GaudiHandleBase& value );
904 
905 private:
909 };
910 
911 // forward-declaration is sufficient here
913 
915 public:
917 
919  setValue( value );
920  return *this;
921  }
922 
923  GaudiHandleArrayProperty* clone() const override { return new GaudiHandleArrayProperty( *this ); }
924 
925  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
926 
927  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
928 
929  std::string toString() const override;
930 
931  void toStream( std::ostream& out ) const override;
932 
933  StatusCode fromString( const std::string& s ) override;
934 
935  const GaudiHandleArrayBase& value() const {
936  useReadHandler();
937  return *m_pValue;
938  }
939 
940  bool setValue( const GaudiHandleArrayBase& value );
941 
942 private:
946 };
947 
948 namespace Gaudi {
949  namespace Utils {
950  // ========================================================================
968  GAUDI_API bool hasProperty( const IProperty* p, const std::string& name );
969  // ========================================================================
987  GAUDI_API bool hasProperty( const IInterface* p, const std::string& name );
988  // ========================================================================
1007  // ========================================================================
1026  // ========================================================================
1050  // ========================================================================
1075  // ========================================================================
1099  template <class TYPE>
1100  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc );
1101  // ========================================================================
1124  template <class TYPE>
1125  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value ) {
1126  return setProperty( component, name, value, std::string() );
1127  }
1128  // ========================================================================
1142  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const std::string& value,
1143  const std::string& doc = "" );
1144  // ========================================================================
1158  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const char* value,
1159  const std::string& doc = "" );
1160  // ========================================================================
1174  template <unsigned N>
1175  StatusCode setProperty( IProperty* component, const std::string& name, const char ( &value )[N],
1176  const std::string& doc = "" ) {
1177  return component ? setProperty( component, name, std::string( value, value + N ), doc ) : StatusCode::FAILURE;
1178  }
1179  // ========================================================================
1210  template <class TYPE>
1211  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc ) {
1212  using Gaudi::Utils::toString;
1213  return component && hasProperty( component, name )
1214  ? Gaudi::Utils::setProperty( component, name, toString( value ), doc )
1216  }
1217  // ========================================================================
1240  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1241  // ========================================================================
1264  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1265  // ========================================================================
1288  template <class TYPE>
1290  const std::string& doc = "" ) {
1291  return setProperty( component, name, &value, doc );
1292  }
1293  // ========================================================================
1314  template <class TYPE>
1315  StatusCode setProperty( IInterface* component, const std::string& name, const TYPE& value,
1316  const std::string& doc = "" ) {
1317  if ( !component ) { return StatusCode::FAILURE; }
1318  auto property = SmartIF<IProperty>{component};
1319  return property ? setProperty( property, name, value, doc ) : StatusCode::FAILURE;
1320  }
1321  // ========================================================================
1334  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const std::string& value,
1335  const std::string& doc = "" );
1336  // ========================================================================
1349  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const char* value,
1350  const std::string& doc = "" );
1351  // ========================================================================
1365  template <unsigned N>
1366  StatusCode setProperty( IInterface* component, const std::string& name, const char ( &value )[N],
1367  const std::string& doc = "" ) {
1368  if ( 0 == component ) { return StatusCode::FAILURE; }
1369  return setProperty( component, name, std::string{value, value + N}, doc );
1370  }
1371  // ========================================================================
1394  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1395  // ========================================================================
1418  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1419  // ========================================================================
1442  template <class TYPE>
1444  const std::string& doc = "" ) {
1445  return setProperty( component, name, &value, doc );
1446  }
1447  // ========================================================================
1448  } // namespace Utils
1449 } // end of namespace Gaudi
1450 // ============================================================================
1451 // The END
1452 // ============================================================================
1453 #endif // GAUDIKERNEL_PROPERTY_H
Gaudi::Property< std::vector< float > & > FloatArrayPropertyRef
Definition: Property.h:829
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:1211
Gaudi::Property< signed char & > SignedCharPropertyRef
Definition: Property.h:781
Details::Property::NullVerifier VerifierType
Definition: Property.h:376
Gaudi::Property< std::vector< signed char > & > SignedCharArrayPropertyRef
Definition: Property.h:819
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:786
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:734
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:803
Gaudi::Property< TYPE > SimpleProperty
Definition: Property.h:754
Gaudi::Property< long long & > LongLongPropertyRef
Definition: Property.h:789
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:804
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:727
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:770
const GaudiHandleArrayBase & value() const
Definition: Property.h:935
Implementation of property with value of concrete type.
Definition: Property.h:370
Gaudi::Property< long & > LongPropertyRef
Definition: Property.h:787
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:830
bool load(PropertyBase &destination) const override
Definition: Property.h:925
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:772
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:856
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:766
Gaudi::Property< std::vector< unsigned long long > & > UnsignedLongLongArrayPropertyRef
Definition: Property.h:828
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:771
Gaudi::Property< float & > FloatPropertyRef
Definition: Property.h:791
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:814
Gaudi::Property< std::vector< unsigned short > & > UnsignedShortArrayPropertyRef
Definition: Property.h:822
Gaudi::Property< std::vector< unsigned char > > UnsignedCharArrayProperty
Definition: Property.h:801
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:765
Gaudi::Property< unsigned long > UnsignedLongProperty
Definition: Property.h:769
bool load(PropertyBase &destination) const override
Definition: Property.h:888
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:795
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:780
const std::string name() const
property name
Definition: Property.h:46
Gaudi::Property< std::vector< bool > & > BooleanArrayPropertyRef
Definition: Property.h:817
Gaudi::Property< std::vector< long double > > LongDoubleArrayProperty
Definition: Property.h:812
Gaudi::Property< std::vector< long long > > LongLongArrayProperty
Definition: Property.h:808
Gaudi::Property< std::vector< double > > DoubleArrayProperty
Definition: Property.h:811
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:802
Gaudi::Property< std::vector< unsigned long > & > UnsignedLongArrayPropertyRef
Definition: Property.h:826
Gaudi::Property< std::vector< unsigned int > > UnsignedIntegerArrayProperty
Definition: Property.h:805
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:838
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:806
typename std::remove_reference< StorageType >::type ValueType
Definition: Property.h:375
Gaudi::Property< std::vector< long > & > LongArrayPropertyRef
Definition: Property.h:825
Gaudi::Property< signed char > SignedCharProperty
Definition: Property.h:762
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:761
int N
Definition: IOTest.py:110
Property & operator-=(const T &other)
Definition: Property.h:646
Gaudi::Property< int & > IntegerPropertyRef
Definition: Property.h:785
GaudiHandleBase * m_pValue
Pointer to the real property.
Definition: Property.h:908
Gaudi::Property< unsigned long & > UnsignedLongPropertyRef
Definition: Property.h:788
const TYPE & lower() const
Return the lower bound value.
Definition: Property.h:259
GaudiHandleProperty * clone() const override
clones the current property
Definition: Property.h:886
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:831
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:767
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:799
virtual PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun)=0
set new callback for reading
Gaudi::Property< bool > BooleanProperty
Definition: Property.h:760
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:850
Gaudi::Property< std::vector< unsigned long long > > UnsignedLongLongArrayProperty
Definition: Property.h:809
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:845
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:773
GaudiHandleArrayProperty * clone() const override
clones the current property
Definition: Property.h:923
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:823
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:927
Property & operator--()
Definition: Property.h:632
Gaudi::Property< std::vector< long long > & > LongLongArrayPropertyRef
Definition: Property.h:827
Gaudi::Property< double & > DoublePropertyRef
Definition: Property.h:792
void useReadHandler(const PropertyBase &p) const
Definition: Property.h:327
Gaudi::Property< std::vector< unsigned char > & > UnsignedCharArrayPropertyRef
Definition: Property.h:820
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:57
Base class of array's of various gaudihandles.
Definition: GaudiHandle.h:342
Gaudi::Property< long double & > LongDoublePropertyRef
Definition: Property.h:793
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:800
bool useUpdateHandler() override
use the call-back function at update, if available
Definition: Property.h:864
Gaudi::Property< std::string > StringProperty
Definition: Property.h:776
void setUpdateHandler(std::function< void(PropertyBase &)> fun)
Definition: Property.h:344
Gaudi::Property< long double > LongDoubleProperty
Definition: Property.h:774
GaudiHandleArrayProperty & operator=(const GaudiHandleArrayBase &value)
Definition: Property.h:918
SwapCall(callback_t &input)
Definition: Property.h:308
GaudiHandleArrayBase * m_pValue
Pointer to the real property.
Definition: Property.h:945
Gaudi::Property< short > ShortProperty
Definition: Property.h:764
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:807
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:757
string s
Definition: gaudirun.py:328
Gaudi::Property< unsigned long long & > UnsignedLongLongPropertyRef
Definition: Property.h:790
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:858
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:833
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:890
Gaudi::Property< long > LongProperty
Definition: Property.h:768
void setUpdateHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:320
Gaudi::Property< std::vector< char > & > CharArrayPropertyRef
Definition: Property.h:818
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:898
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:784
Gaudi::Property< std::vector< float > > FloatArrayProperty
Definition: Property.h:810
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:881
Gaudi::Property< std::vector< short > & > ShortArrayPropertyRef
Definition: Property.h:821
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:763
VerifierType m_verifier
Definition: Property.h:383
Gaudi::Property< short & > ShortPropertyRef
Definition: Property.h:783
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:782
ValueType operator--(int)
Definition: Property.h:637
Gaudi::Property< std::vector< bool > > BooleanArrayProperty
Definition: Property.h:798
Gaudi::Property< std::vector< unsigned int > & > UnsignedIntegerArrayPropertyRef
Definition: Property.h:824
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:779
void useUpdateHandler(PropertyBase &p)
Definition: Property.h:335
void useReadHandler() const
use the call-back function at reading, if available
Definition: Property.h:861