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