The Gaudi Framework  v30r2 (9eca68f7)
Property.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_PROPERTY_H
2 #define GAUDIKERNEL_PROPERTY_H
3 // ============================================================================
4 // STD & STL
5 // ============================================================================
6 #include <boost/utility/string_ref.hpp>
7 #include <stdexcept>
8 #include <string>
9 #include <typeinfo>
10 // ============================================================================
11 // Application C++ Class Headers
12 // ============================================================================
13 #include "GaudiKernel/IProperty.h"
14 #include "GaudiKernel/Kernel.h"
15 #include "GaudiKernel/Parsers.h"
17 #include "GaudiKernel/SmartIF.h"
18 #include "GaudiKernel/ToStream.h"
19 
20 namespace Gaudi
21 {
22  namespace Details
23  {
24  // ============================================================================
33  {
34  private:
35  // the default constructor is disabled
36  PropertyBase() = delete;
37 
38  public:
40  const std::string name() const { return m_name.to_string(); }
42  std::string documentation() const { return m_documentation.to_string(); }
44  const std::type_info* type_info() const { return m_typeinfo; }
46  std::string type() const { return m_typeinfo->name(); }
48  virtual bool load( PropertyBase& dest ) const = 0;
50  virtual bool assign( const PropertyBase& source ) = 0;
51 
52  public:
54  virtual std::string toString() const = 0;
56  virtual void toStream( std::ostream& out ) const = 0;
58  virtual StatusCode fromString( const std::string& value ) = 0;
59 
60  public:
62  virtual PropertyBase& declareReadHandler( std::function<void( PropertyBase& )> fun ) = 0;
64  virtual PropertyBase& declareUpdateHandler( std::function<void( PropertyBase& )> fun ) = 0;
65 
67  virtual const std::function<void( PropertyBase& )> readCallBack() const = 0;
69  virtual const std::function<void( PropertyBase& )> updateCallBack() const = 0;
70 
72  virtual bool useUpdateHandler() = 0;
73 
74  template <class HT>
75  inline PropertyBase& declareReadHandler( void ( HT::*MF )( PropertyBase& ), HT* instance )
76  {
77  return declareReadHandler( [=]( PropertyBase& p ) { ( instance->*MF )( p ); } );
78  }
79 
80  template <class HT>
81  inline PropertyBase& declareUpdateHandler( void ( HT::*MF )( PropertyBase& ), HT* instance )
82  {
83  return declareUpdateHandler( [=]( PropertyBase& p ) { ( instance->*MF )( p ); } );
84  }
85 
86  public:
88  virtual ~PropertyBase() = default;
90  void setName( std::string value ) { m_name = to_view( std::move( value ) ); }
92  void setDocumentation( std::string value ) { m_documentation = to_view( std::move( value ) ); }
94  virtual std::ostream& fillStream( std::ostream& ) const;
96  virtual PropertyBase* clone() const = 0;
97 
99  void setOwnerType( const std::type_info& ownerType ) { m_ownerType = &ownerType; }
100 
102  template <class OWNER>
104  {
105  setOwnerType( typeid( OWNER ) );
106  }
107 
109  const std::type_info* ownerType() const { return m_ownerType; }
110 
113  {
114  return m_ownerType ? System::typeinfoName( *m_ownerType ) : std::string( "unknown owner type" );
115  }
116 
117  protected:
120  : m_name( to_view( std::move( name ) ) ), m_documentation( to_view( std::move( doc ) ) ), m_typeinfo( &type )
121  {
122  }
125  : m_name( to_view( std::move( name ) ) ), m_documentation( m_name ), m_typeinfo( &type )
126  {
127  }
129  PropertyBase( const PropertyBase& ) = default;
131  PropertyBase& operator=( const PropertyBase& ) = default;
132 
133  private:
135  static boost::string_ref to_view( std::string str );
137  boost::string_ref m_name;
139  boost::string_ref m_documentation;
143  const std::type_info* m_ownerType = nullptr;
144  };
145 
146  inline std::ostream& operator<<( std::ostream& stream, const PropertyBase& prop )
147  {
148  return prop.fillStream( stream );
149  }
150 
151  namespace Property
152  {
153  // The following code is going to be a bit unpleasant, but as far as its
154  // author can tell, it is as simple as the design constraints and C++'s
155  // implementation constraints will allow. If you disagree, please submit
156  // a patch which simplifies it. Here is the underlying design rationale:
157  //
158  // - For any given type T used in a Property, we want to have an
159  // associated StringConverter<T> struct which explains how to convert a
160  // value of that type into a string (toString) and parse that string
161  // back (fromString).
162  // - There is a default implementation, called DefaultStringConverter<T>,
163  // which is based on the overloadable parse() and toStream() global
164  // methods of Gaudi. Its exact behaviour varies depending on whether T
165  // is default-constructible or only copy-constructible, which requires a
166  // layer of SFINAE indirection.
167  // - Some people want to be able to specialize StringConverter as an
168  // alternative to defining parse/toStream overloads. This interferes
169  // with the SFINAE tricks used by DefaultStringConverter, so we cannot
170  // just call a DefaultStringConverter a StringConverter and must add one
171  // more layer to the StringConverter type hierarchy.
172 
173  // This class factors out commonalities between DefaultStringConverters
174  template <class TYPE>
176  public:
177  inline std::string toString( const TYPE& v )
178  {
180  return toString( v );
181  }
182 
183  // Implementation of fromString depends on whether TYPE is default-
184  // constructible (fastest, easiest) or only copy-constructible (still
185  // doable as long as the caller can provide a valid value of TYPE)
186  virtual TYPE fromString( const TYPE& ref_value, const std::string& s ) = 0;
187 
188  protected:
189  inline void fromStringImpl( TYPE& buffer, const std::string& s )
190  {
191  using Gaudi::Parsers::parse;
192  if ( !parse( buffer, s ).isSuccess() ) {
193  throw std::invalid_argument( "cannot parse '" + s + "' to " + System::typeinfoName( typeid( TYPE ) ) );
194  }
195  }
196  };
197  // Specialization of toString for strings (identity function)
198  template <>
200  {
201  return v;
202  }
203 
204  // This class provides a default implementation of StringConverter based
205  // on the overloadable parse() and toStream() global Gaudi methods.
206  //
207  // It leverages the fact that TYPE is default-constructible if it can, and
208  // falls back fo a requirement of copy-constructibility if it must. So
209  // here is the "default" implementation for copy-constructible types...
210  //
211  template <typename TYPE, typename Enable = void>
213  inline TYPE fromString( const TYPE& ref_value, const std::string& s ) final override
214  {
215  TYPE buffer = ref_value;
216  this->fromStringImpl( buffer, s );
217  return buffer;
218  }
219  };
220  // ...and here is the preferred impl for default-constructible types:
221  template <class TYPE>
222  struct DefaultStringConverter<TYPE, std::enable_if_t<std::is_default_constructible<TYPE>::value>>
224  inline TYPE fromString( const TYPE& /* ref_value */, const std::string& s ) final override
225  {
226  TYPE buffer{};
227  this->fromStringImpl( buffer, s );
228  return buffer;
229  }
230  };
231 
232  // Specializable StringConverter struct with a default implementation
233  template <typename TYPE>
234  struct StringConverter : DefaultStringConverter<TYPE> {
235  };
236 
237  struct NullVerifier {
238  template <class TYPE>
239  void operator()( const TYPE& ) const
240  {
241  }
242  };
243  template <class TYPE>
245  void operator()( const TYPE& value ) const
246  {
248  // throw the exception if the limit is defined and value is outside
249  if ( ( m_hasLowerBound && ( value < m_lowerBound ) ) || ( m_hasUpperBound && ( m_upperBound < value ) ) )
250  throw std::out_of_range( "value " + toString( value ) + " outside range" );
251  }
252 
254  bool hasLower() const { return m_hasLowerBound; }
256  bool hasUpper() const { return m_hasUpperBound; }
258  const TYPE& lower() const { return m_lowerBound; }
260  const TYPE& upper() const { return m_upperBound; }
261 
263  void setLower( const TYPE& value )
264  {
265  m_hasLowerBound = true;
266  m_lowerBound = value;
267  }
269  void setUpper( const TYPE& value )
270  {
271  m_hasUpperBound = true;
272  m_upperBound = value;
273  }
275  void clearLower()
276  {
277  m_hasLowerBound = false;
278  m_lowerBound = TYPE();
279  }
281  void clearUpper()
282  {
283  m_hasUpperBound = false;
284  m_upperBound = TYPE();
285  }
286 
288  void setBounds( const TYPE& lower, const TYPE& upper )
289  {
290  setLower( lower );
291  setUpper( upper );
292  }
293 
295  void clearBounds()
296  {
297  clearLower();
298  clearUpper();
299  }
300 
301  private:
303  bool m_hasLowerBound{false};
304  bool m_hasUpperBound{false};
305  TYPE m_lowerBound{};
306  TYPE m_upperBound{};
307  };
308 
310  struct SwapCall {
312  callback_t tmp, &orig;
313  SwapCall( callback_t& input ) : orig( input ) { tmp.swap( orig ); }
314  ~SwapCall() { orig.swap( tmp ); }
315  void operator()( PropertyBase& p ) const { tmp( p ); }
316  };
317 
318  struct NoHandler {
319  void useReadHandler( const PropertyBase& ) const {}
321  {
322  throw std::logic_error( "setReadHandler not implemented for this class" );
323  }
325  void useUpdateHandler( const PropertyBase& ) const {}
327  {
328  throw std::logic_error( "setUpdateHandler not implemented for this class" );
329  }
331  };
334  void useReadHandler( const PropertyBase& p ) const
335  {
336  if ( m_readCallBack ) {
337  SwapCall{m_readCallBack}( const_cast<PropertyBase&>( p ) );
338  }
339  }
340  void setReadHandler( std::function<void( PropertyBase& )> fun ) { m_readCallBack = std::move( fun ); }
341  std::function<void( PropertyBase& )> getReadHandler() const { return m_readCallBack; }
342  };
346  {
347  if ( m_updateCallBack ) {
348  try {
349  SwapCall{m_updateCallBack}( p );
350  } catch ( const std::exception& x ) {
351  throw std::invalid_argument( "failure in update handler of '" + p.name() + "': " + x.what() );
352  }
353  }
354  }
355  void setUpdateHandler( std::function<void( PropertyBase& )> fun ) { m_updateCallBack = std::move( fun ); }
356  std::function<void( PropertyBase& )> getUpdateHandler() const { return m_updateCallBack; }
357  };
359  using ReadHandler::useReadHandler;
360  using ReadHandler::setReadHandler;
361  using ReadHandler::getReadHandler;
362  using UpdateHandler::useUpdateHandler;
363  using UpdateHandler::setUpdateHandler;
364  using UpdateHandler::getUpdateHandler;
365  };
366  }
367 
368  } // namespace Details
369 
370  // ============================================================================
378  // ============================================================================
379  template <class TYPE, class VERIFIER = Details::Property::NullVerifier,
380  class HANDLERS = Details::Property::UpdateHandler>
382  {
383  public:
384  // ==========================================================================
386  using StorageType = TYPE;
388  using VerifierType = VERIFIER;
389  using HandlersType = HANDLERS;
390 
391  private:
398  template <class T>
400  template <class T>
401  using not_copying = std::enable_if_t<!is_this_type<T>::value>;
403  public:
404  // ==========================================================================
406  template <class T = StorageType>
407  inline Property( std::string name, T&& value, std::string doc = "" )
408  : Details::PropertyBase( typeid( ValueType ), std::move( name ), std::move( doc ) )
409  , m_value( std::forward<T>( value ) )
410  {
411  m_verifier( m_value );
412  }
415  template <typename OWNER, typename T = ValueType,
416  typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>,
417  typename = std::enable_if_t<std::is_default_constructible<T>::value>>
418  inline Property( OWNER* owner, std::string name ) : Property( std::move( name ), ValueType{}, "" )
419  {
420  owner->declareProperty( *this );
421  setOwnerType<OWNER>();
422  }
423 
426  template <class OWNER, class T = StorageType, typename = std::enable_if_t<std::is_base_of<IProperty, OWNER>::value>>
427  inline Property( OWNER* owner, std::string name, T&& value, std::string doc = "" )
428  : Property( std::move( name ), std::forward<T>( value ), std::move( doc ) )
429  {
430  owner->declareProperty( *this );
431  setOwnerType<OWNER>();
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  {
440  }
441 
444  template <typename T = StorageType, typename = std::enable_if_t<!std::is_reference<T>::value>>
445  Property() : Details::PropertyBase( typeid( ValueType ), "", "" ), m_value()
446  {
447  }
448 
451 
454  {
455  m_handlers.setReadHandler( std::move( fun ) );
456  return *this;
457  }
460  {
461  m_handlers.setUpdateHandler( std::move( fun ) );
462  return *this;
463  }
464 
467  {
468  return m_handlers.getReadHandler();
469  }
472  {
473  return m_handlers.getUpdateHandler();
474  }
475 
477  bool useUpdateHandler() override
478  {
479  m_handlers.useUpdateHandler( *this );
480  return true;
481  }
482 
484  operator const ValueType&() const
485  {
486  m_handlers.useReadHandler( *this );
487  return m_value;
488  }
489  // /// Automatic conversion to value (reference).
490  // operator ValueType& () {
491  // useReadHandler();
492  // return m_value;
493  // }
494 
496  template <class T>
497  inline bool operator==( const T& other ) const
498  {
499  return m_value == other;
500  }
501 
503  template <class T>
504  inline bool operator!=( const T& other ) const
505  {
506  return m_value != other;
507  }
508 
510  template <class T>
511  inline bool operator<( const T& other ) const
512  {
513  return m_value < other;
514  }
515 
517  template <class T>
518  decltype( std::declval<ValueType>() + std::declval<T>() ) operator+( const T& other ) const
519  {
520  return m_value + other;
521  }
522 
524  template <class T = ValueType>
525  Property& operator=( T&& v )
526  {
527  m_verifier( v );
528  m_value = std::forward<T>( v );
529  m_handlers.useUpdateHandler( *this );
530  return *this;
531  }
532 
534  const VerifierType& verifier() const { return m_verifier; }
536  VerifierType& verifier() { return m_verifier; }
537 
540  const ValueType& value() const { return *this; }
541  ValueType& value() { return const_cast<ValueType&>( (const ValueType&)*this ); }
542  bool setValue( const ValueType& v )
543  {
544  *this = v;
545  return true;
546  }
547  bool set( const ValueType& v )
548  {
549  *this = v;
550  return true;
551  }
552  Details::PropertyBase* clone() const override { return new Property( *this ); }
554 
558  template <class T = const ValueType>
559  inline decltype( std::declval<T>().size() ) size() const
560  {
561  return value().size();
562  }
563  template <class T = const ValueType>
564  inline decltype( std::declval<T>().length() ) length() const
565  {
566  return value().length();
567  }
568  template <class T = const ValueType>
569  inline decltype( std::declval<T>().empty() ) empty() const
570  {
571  return value().empty();
572  }
573  template <class T = ValueType>
574  inline decltype( std::declval<T>().clear() ) clear()
575  {
576  value().clear();
577  }
578  template <class T = const ValueType>
579  inline decltype( std::declval<T>().begin() ) begin() const
580  {
581  return value().begin();
582  }
583  template <class T = const ValueType>
584  inline decltype( std::declval<T>().end() ) end() const
585  {
586  return value().end();
587  }
588  template <class T = ValueType>
589  inline decltype( std::declval<T>().begin() ) begin()
590  {
591  return value().begin();
592  }
593  template <class T = ValueType>
594  inline decltype( std::declval<T>().end() ) end()
595  {
596  return value().end();
597  }
598  template <class ARG>
599  inline decltype( auto ) operator[]( const ARG& arg ) const
600  {
601  return value()[arg];
602  }
603  template <class ARG>
604  inline decltype( auto ) operator[]( const ARG& arg )
605  {
606  return value()[arg];
607  }
608  template <class T = const ValueType>
609  inline decltype( std::declval<T>().find( typename T::key_type{} ) ) find( const typename T::key_type& key ) const
610  {
611  return value().find( key );
612  }
613  template <class T = ValueType>
614  inline decltype( std::declval<T>().find( typename T::key_type{} ) ) find( const typename T::key_type& key )
615  {
616  return value().find( key );
617  }
618  template <class ARG, class T = ValueType>
619  inline decltype( std::declval<T>().erase( ARG{} ) ) erase( ARG arg )
620  {
621  return value().erase( arg );
622  }
623  template <class = ValueType>
625  {
626  ++value();
627  return *this;
628  }
629  template <class = ValueType>
630  inline ValueType operator++( int )
631  {
632  return m_value++;
633  }
634  template <class = ValueType>
636  {
637  --value();
638  return *this;
639  }
640  template <class = ValueType>
641  inline ValueType operator--( int )
642  {
643  return m_value--;
644  }
645  template <class T = ValueType>
646  inline Property& operator+=( const T& other )
647  {
648  m_value += other;
649  return *this;
650  }
651  template <class T = ValueType>
652  inline Property& operator-=( const T& other )
653  {
654  m_value -= other;
655  return *this;
656  }
658  template <class T = const ValueType>
659  inline decltype( std::declval<T>().key() ) key() const
660  {
661  return value().key();
662  }
663  template <class T = const ValueType>
664  inline decltype( std::declval<T>().objKey() ) objKey() const
665  {
666  return value().objKey();
667  }
668  template <class T = const ValueType>
669  inline decltype( std::declval<T>().fullKey() ) fullKey() const
670  {
671  return value().fullKey();
672  }
673  template <class T = ValueType>
674  inline decltype( std::declval<T>().initialize() ) initialize()
675  {
676  return value().initialize();
677  }
678  template <class T = ValueType>
679  inline decltype( std::declval<T>().makeHandles() ) makeHandles() const
680  {
681  return value().makeHandles();
682  }
683  template <class ARG, class T = ValueType>
684  inline decltype( std::declval<T>().makeHandles( std::declval<ARG>() ) ) makeHandles( const ARG& arg ) const
685  {
686  return value().makeHandles( arg );
687  }
689  // ==========================================================================
690  public:
692  bool assign( const Details::PropertyBase& source ) override
693  {
694  // Check if the property of is of "the same" type, except for strings
695  const Property* p =
696  ( std::is_same<ValueType, std::string>::value ) ? nullptr : dynamic_cast<const Property*>( &source );
697  if ( p ) {
698  *this = p->value();
699  } else {
700  this->fromString( source.toString() ).ignore();
701  }
702  return true;
703  }
705  bool load( Details::PropertyBase& dest ) const override
706  {
707  // delegate to the 'opposite' method
708  return dest.assign( *this );
709  }
711  StatusCode fromString( const std::string& source ) override
712  {
713  using Converter = Details::Property::StringConverter<ValueType>;
714  *this = Converter().fromString( m_value, source );
715  return StatusCode::SUCCESS;
716  }
718  std::string toString() const override
719  {
720  using Converter = Details::Property::StringConverter<ValueType>;
721  return Converter().toString( *this );
722  }
724  void toStream( std::ostream& out ) const override
725  {
726  m_handlers.useReadHandler( *this );
727  using Utils::toStream;
728  toStream( m_value, out );
729  }
730  };
731 
733  template <class T, class TP, class V, class H>
734  bool operator==( const T& v, const Property<TP, V, H>& p )
735  {
736  return p == v;
737  }
738 
740  template <class T, class TP, class V, class H>
741  bool operator!=( const T& v, const Property<TP, V, H>& p )
742  {
743  return p != v;
744  }
745 
747  template <class T, class TP, class V, class H>
748  decltype( std::declval<TP>() + std::declval<T>() ) operator+( const T& v, const Property<TP, V, H>& p )
749  {
750  return v + p.value();
751  }
752 
753  template <class TYPE, class HANDLERS = Details::Property::UpdateHandler>
755 
756  template <class TYPE>
759 
760 } // namespace Gaudi
761 
762 template <class TYPE>
764 
765 template <class TYPE>
767 
768 // Typedef Properties for built-in types
784 
786 
787 // Typedef PropertyRefs for built-in types
803 
805 
806 // Typedef "Arrays" of Properties for built-in types
822 
824 
825 // Typedef "Arrays" of PropertyRefs for built-in types
841 
843 
846 template <typename Handler = typename Gaudi::Details::Property::UpdateHandler>
848 {
849  Handler m_handlers;
850 
851 public:
853 
855  PropertyBase& declareReadHandler( std::function<void( PropertyBase& )> fun ) override
856  {
857  m_handlers.setReadHandler( std::move( fun ) );
858  return *this;
859  }
861  PropertyBase& declareUpdateHandler( std::function<void( PropertyBase& )> fun ) override
862  {
863  m_handlers.setUpdateHandler( std::move( fun ) );
864  return *this;
865  }
866 
868  const std::function<void( PropertyBase& )> readCallBack() const override { return m_handlers.getReadHandler(); }
870  const std::function<void( PropertyBase& )> updateCallBack() const override { return m_handlers.getUpdateHandler(); }
871 
873  void useReadHandler() const { m_handlers.useReadHandler( *this ); }
874 
876  bool useUpdateHandler() override
877  {
878  m_handlers.useUpdateHandler( *this );
879  return true;
880  }
881 };
882 
883 // forward-declaration is sufficient here
884 class GaudiHandleBase;
885 
886 // implementation in header file only where the GaudiHandleBase class
887 // definition is not needed. The rest goes into the .cpp file.
888 // The goal is to decouple the header files, to avoid that the whole
889 // world depends on GaudiHandle.h
891 {
892 public:
894 
896  {
897  setValue( value );
898  return *this;
899  }
900 
901  GaudiHandleProperty* clone() const override { return new GaudiHandleProperty( *this ); }
902 
903  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
904 
905  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
906 
907  std::string toString() const override;
908 
909  void toStream( std::ostream& out ) const override;
910 
911  StatusCode fromString( const std::string& s ) override;
912 
913  const GaudiHandleBase& value() const
914  {
915  useReadHandler();
916  return *m_pValue;
917  }
918 
919  bool setValue( const GaudiHandleBase& value );
920 
921 private:
925 };
926 
927 // forward-declaration is sufficient here
929 
931 {
932 public:
934 
936  {
937  setValue( value );
938  return *this;
939  }
940 
941  GaudiHandleArrayProperty* clone() const override { return new GaudiHandleArrayProperty( *this ); }
942 
943  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
944 
945  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
946 
947  std::string toString() const override;
948 
949  void toStream( std::ostream& out ) const override;
950 
951  StatusCode fromString( const std::string& s ) override;
952 
954  {
955  useReadHandler();
956  return *m_pValue;
957  }
958 
959  bool setValue( const GaudiHandleArrayBase& value );
960 
961 private:
965 };
966 
967 namespace Gaudi
968 {
969  namespace Utils
970  {
971  // ========================================================================
989  GAUDI_API bool hasProperty( const IProperty* p, const std::string& name );
990  // ========================================================================
1008  GAUDI_API bool hasProperty( const IInterface* p, const std::string& name );
1009  // ========================================================================
1028  // ========================================================================
1047  // ========================================================================
1071  // ========================================================================
1096  // ========================================================================
1120  template <class TYPE>
1121  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc );
1122  // ========================================================================
1145  template <class TYPE>
1146  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value )
1147  {
1148  return setProperty( component, name, value, std::string() );
1149  }
1150  // ========================================================================
1164  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const std::string& value,
1165  const std::string& doc = "" );
1166  // ========================================================================
1180  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const char* value,
1181  const std::string& doc = "" );
1182  // ========================================================================
1196  template <unsigned N>
1197  StatusCode setProperty( IProperty* component, const std::string& name, const char ( &value )[N],
1198  const std::string& doc = "" )
1199  {
1200  return component ? setProperty( component, name, std::string( value, value + N ), doc ) : StatusCode::FAILURE;
1201  }
1202  // ========================================================================
1233  template <class TYPE>
1234  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc )
1235  {
1236  using Gaudi::Utils::toString;
1237  return component && hasProperty( component, name )
1238  ? Gaudi::Utils::setProperty( component, name, toString( value ), doc )
1240  }
1241  // ========================================================================
1263  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name,
1264  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1265  // ========================================================================
1287  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name,
1288  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1289  // ========================================================================
1312  template <class TYPE>
1313  StatusCode setProperty( IProperty* component, const std::string& name, const Gaudi::Property<TYPE>& value,
1314  const std::string& doc = "" )
1315  {
1316  return setProperty( component, name, &value, doc );
1317  }
1318  // ========================================================================
1339  template <class TYPE>
1340  StatusCode setProperty( IInterface* component, const std::string& name, const TYPE& value,
1341  const std::string& doc = "" )
1342  {
1343  if ( !component ) {
1344  return StatusCode::FAILURE;
1345  }
1346  auto property = SmartIF<IProperty>{component};
1347  return property ? setProperty( property, name, value, doc ) : StatusCode::FAILURE;
1348  }
1349  // ========================================================================
1362  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const std::string& value,
1363  const std::string& doc = "" );
1364  // ========================================================================
1377  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const char* value,
1378  const std::string& doc = "" );
1379  // ========================================================================
1393  template <unsigned N>
1394  StatusCode setProperty( IInterface* component, const std::string& name, const char ( &value )[N],
1395  const std::string& doc = "" )
1396  {
1397  if ( 0 == component ) {
1398  return StatusCode::FAILURE;
1399  }
1400  return setProperty( component, name, std::string{value, value + N}, doc );
1401  }
1402  // ========================================================================
1424  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name,
1425  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1426  // ========================================================================
1448  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name,
1449  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1450  // ========================================================================
1473  template <class TYPE>
1474  StatusCode setProperty( IInterface* component, const std::string& name, const Gaudi::Property<TYPE>& value,
1475  const std::string& doc = "" )
1476  {
1477  return setProperty( component, name, &value, doc );
1478  }
1479  // ========================================================================
1480  } // end of namespace Gaudi::Utils
1481 } // end of namespace Gaudi
1482 // ============================================================================
1483 // The END
1484 // ============================================================================
1485 #endif // GAUDIKERNEL_PROPERTY_H
1486 // ============================================================================
Gaudi::Property< std::vector< float > & > FloatArrayPropertyRef
Definition: Property.h:838
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:1234
Gaudi::Property< signed char & > SignedCharPropertyRef
Definition: Property.h:790
Details::Property::NullVerifier VerifierType
Definition: Property.h:388
Gaudi::Property< std::vector< signed char > & > SignedCharArrayPropertyRef
Definition: Property.h:828
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Property(OWNER *owner, std::string name)
Autodeclaring constructor with property name, value and documentation.
Definition: Property.h:418
std::function< void(PropertyBase &)> m_readCallBack
Definition: Property.h:333
Gaudi::Property< unsigned int & > UnsignedIntegerPropertyRef
Definition: Property.h:795
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:213
T empty(T...args)
bool operator!=(const T &v, const Property< TP, V, H > &p)
delegate (value != property) to property operator!=
Definition: Property.h:741
GaudiHandleProperty * clone() const override
clones the current property
Definition: Property.h:901
bool setValue(const ValueType &v)
Definition: Property.h:542
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:303
std::function< void(PropertyBase &)> getReadHandler() const
Definition: Property.h:324
void useUpdateHandler(const PropertyBase &) const
Definition: Property.h:325
Gaudi::Property< std::vector< unsigned short > > UnsignedShortArrayProperty
Definition: Property.h:812
Gaudi::Property< TYPE > SimpleProperty
Definition: Property.h:763
Gaudi::Property< long long & > LongLongPropertyRef
Definition: Property.h:798
PropertyBase & declareReadHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Definition: Property.h:75
Gaudi::Property< std::vector< int > > IntegerArrayProperty
Definition: Property.h:813
std::ostream & operator<<(std::ostream &stream, const PropertyBase &prop)
Definition: Property.h:146
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
Definition: Property.h:734
bool useUpdateHandler() override
manual trigger for callback for update
Definition: Property.h:477
void setDocumentation(std::string value)
set the documentation string
Definition: Property.h:92
Gaudi::Property< long long > LongLongProperty
Definition: Property.h:779
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:868
Implementation of property with value of concrete type.
Definition: Property.h:381
Gaudi::Property< long & > LongPropertyRef
Definition: Property.h:796
std::function< void(PropertyBase &)> m_updateCallBack
Definition: Property.h:344
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:332
Gaudi::Property< std::vector< double > & > DoubleArrayPropertyRef
Definition: Property.h:839
virtual bool assign(const PropertyBase &source)=0
import the property value form the source
T swap(T...args)
The declaration of major parsing functions used e.g for (re)implementation of new extended properties...
bool load(PropertyBase &destination) const override
Definition: Property.h:903
const std::string name() const
property name
Definition: Property.h:40
Property & operator=(T &&v)
Assignment from value.
Definition: Property.h:525
Gaudi::Property< float > FloatProperty
Definition: Property.h:781
Gaudi::Property< int > IntegerProperty
Definition: Property.h:775
Gaudi::Property< std::vector< unsigned long long > & > UnsignedLongLongArrayPropertyRef
Definition: Property.h:837
void setOwnerType()
set the type of the owner class (used for documentation)
Definition: Property.h:103
void clearUpper()
Clear upper bound value.
Definition: Property.h:281
const TYPE & upper() const
Return the upper bound value.
Definition: Property.h:260
GaudiHandleArrayProperty * clone() const override
clones the current property
Definition: Property.h:941
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:356
Gaudi::Property< unsigned long long > UnsignedLongLongProperty
Definition: Property.h:780
Gaudi::Property< float & > FloatPropertyRef
Definition: Property.h:800
vector< std::string > StorageType
Hosted type.
Definition: Property.h:386
Gaudi::Details::PropertyBase * property(const std::string &name) const
std::string ownerTypeName() const
get the string for the type of the owner class (used for documentation)
Definition: Property.h:112
STL namespace.
std::string toString() const override
value -> string
Definition: Property.h:718
Gaudi::Property< std::vector< std::string > > StringArrayProperty
Definition: Property.h:823
Gaudi::Property< std::vector< unsigned short > & > UnsignedShortArrayPropertyRef
Definition: Property.h:831
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
Gaudi::Property< std::vector< unsigned char > > UnsignedCharArrayProperty
Definition: Property.h:810
void setLower(const TYPE &value)
Set lower bound value.
Definition: Property.h:263
HandlersType m_handlers
Definition: Property.h:395
Gaudi::Property< unsigned short > UnsignedShortProperty
Definition: Property.h:774
const std::function< void(Details::PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: Property.h:471
T end(T...args)
Gaudi::Property< unsigned long > UnsignedLongProperty
Definition: Property.h:778
Gaudi::Property< std::string & > StringPropertyRef
Definition: Property.h:804
StorageType m_value
Storage.
Definition: Property.h:393
Gaudi::Property< char & > CharPropertyRef
Definition: Property.h:789
Gaudi::Property< std::vector< bool > & > BooleanArrayPropertyRef
Definition: Property.h:826
Gaudi::Property< std::vector< long double > > LongDoubleArrayProperty
Definition: Property.h:821
Gaudi::Property< std::vector< long long > > LongLongArrayProperty
Definition: Property.h:817
Gaudi::Property< std::vector< double > > DoubleArrayProperty
Definition: Property.h:820
bool operator<(const T &other) const
"less" comparison
Definition: Property.h:511
void setOwnerType(const std::type_info &ownerType)
set the type of the owner class (used for documentation)
Definition: Property.h:99
virtual std::string toString() const =0
value -> string
Gaudi::Property< std::vector< short > > ShortArrayProperty
Definition: Property.h:811
Gaudi::Details::PropertyBase Property
backward compatibility hack for old Property base class
Definition: PropertyFwd.h:28
Gaudi::Property< std::vector< unsigned long > & > UnsignedLongArrayPropertyRef
Definition: Property.h:835
Gaudi::Property< std::vector< unsigned int > > UnsignedIntegerArrayProperty
Definition: Property.h:814
PropertyBase(const std::type_info &type, std::string name="", std::string doc="")
constructor from the property name and the type
Definition: Property.h:119
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:459
Property()
Construct an anonymous property with default constructed value.
Definition: Property.h:445
Helper class to simplify the migration old properties deriving directly from PropertyBase.
Definition: Property.h:847
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
Property & operator+=(const T &other)
Definition: Property.h:646
Gaudi::Property< std::vector< long > > LongArrayProperty
Definition: Property.h:815
typename std::remove_reference< StorageType >::type ValueType
Definition: Property.h:387
Gaudi::Property< std::vector< long > & > LongArrayPropertyRef
Definition: Property.h:834
void operator()(PropertyBase &p) const
Definition: Property.h:315
void operator()(const TYPE &value) const
Definition: Property.h:245
Gaudi::Property< signed char > SignedCharProperty
Definition: Property.h:771
Gaudi::Property< char > CharProperty
Definition: Property.h:770
int N
Definition: IOTest.py:101
Property & operator-=(const T &other)
Definition: Property.h:652
const VerifierType & verifier() const
Accessor to verifier.
Definition: Property.h:534
Gaudi::Property< int & > IntegerPropertyRef
Definition: Property.h:794
GaudiHandleBase * m_pValue
Pointer to the real property.
Definition: Property.h:924
Gaudi::Property< unsigned long & > UnsignedLongPropertyRef
Definition: Property.h:797
const std::type_info * ownerType() const
get the type of the owner class (used for documentation)
Definition: Property.h:109
boost::string_ref m_name
property name
Definition: Property.h:137
Property & operator++()
Definition: Property.h:624
T what(T...args)
PropertyBase(std::string name, const std::type_info &type)
constructor from the property name and the type
Definition: Property.h:124
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
void setBounds(const TYPE &lower, const TYPE &upper)
Set both bounds (lower and upper) at the same time.
Definition: Property.h:288
Gaudi::Property< std::vector< long double > & > LongDoubleArrayPropertyRef
Definition: Property.h:840
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
Property(std::string name, T &&value, std::string doc="")
the constructor with property name, value and documentation.
Definition: Property.h:407
Definition of the basic interface.
Definition: IInterface.h:277
const std::type_info * m_typeinfo
property type
Definition: Property.h:141
Gaudi::Property< unsigned int > UnsignedIntegerProperty
Definition: Property.h:776
const TYPE & lower() const
Return the lower bound value.
Definition: Property.h:258
T erase(T...args)
Gaudi::Property< std::vector< char > > CharArrayProperty
Definition: Property.h:808
virtual PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun)=0
set new callback for reading
const GaudiHandleBase & value() const
Definition: Property.h:913
Gaudi::Property< bool > BooleanProperty
Definition: Property.h:769
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:861
Gaudi::Property< std::vector< unsigned long long > > UnsignedLongLongArrayProperty
Definition: Property.h:818
VerifierType & verifier()
Accessor to verifier.
Definition: Property.h:536
PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun) override
set new callback for reading
Definition: Property.h:855
const GaudiHandleArrayBase & value() const
Definition: Property.h:953
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
Definition: Property.cpp:52
PropertyBase & declareUpdateHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Definition: Property.h:81
void fromStringImpl(TYPE &buffer, const std::string &s)
Definition: Property.h:189
std::ostream & toStream(const DataObjID &d, std::ostream &os)
Definition: DataObjID.cpp:92
T clear(T...args)
bool hasLower() const
Return if it has a lower bound.
Definition: Property.h:254
Gaudi::Property< double > DoubleProperty
Definition: Property.h:782
Converter base class.
Definition: Converter.h:24
STL class.
void setName(std::string value)
set the new value for the property name
Definition: Property.h:90
Gaudi::Property< std::vector< int > & > IntegerArrayPropertyRef
Definition: Property.h:832
T move(T...args)
bool assign(const PropertyBase &source) override
Definition: Property.h:945
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
Property & operator--()
Definition: Property.h:635
void operator()(const TYPE &) const
Definition: Property.h:239
Gaudi::Property< std::vector< long long > & > LongLongArrayPropertyRef
Definition: Property.h:836
std::enable_if_t<!is_this_type< T >::value > not_copying
Definition: Property.h:401
Gaudi::Property< double & > DoublePropertyRef
Definition: Property.h:801
std::function< void(PropertyBase &)> getUpdateHandler() const
Definition: Property.h:330
bool operator==(const T &other) const
equality comparison
Definition: Property.h:497
Gaudi::Property< std::vector< unsigned char > & > UnsignedCharArrayPropertyRef
Definition: Property.h:829
void useReadHandler(const PropertyBase &p) const
Definition: Property.h:334
bool hasUpper() const
Return if it has a lower bound.
Definition: Property.h:256
T find(T...args)
bool load(Details::PropertyBase &dest) const override
set value to another property
Definition: Property.h:705
T size(T...args)
StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:52
Base class of array&#39;s of various gaudihandles.
Definition: GaudiHandle.h:354
std::function< void(PropertyBase &)> getUpdateHandler() const
Definition: Property.h:356
Gaudi::Property< long double & > LongDoublePropertyRef
Definition: Property.h:802
ValueType & value()
Definition: Property.h:541
STL class.
void useReadHandler() const
use the call-back function at reading, if available
Definition: Property.h:873
Gaudi::Property< std::vector< signed char > > SignedCharArrayProperty
Definition: Property.h:809
bool useUpdateHandler() override
use the call-back function at update, if available
Definition: Property.h:876
Gaudi::Property< std::string > StringProperty
Definition: Property.h:785
T begin(T...args)
STL class.
void setUpdateHandler(std::function< void(PropertyBase &)> fun)
Definition: Property.h:355
Gaudi::Property< long double > LongDoubleProperty
Definition: Property.h:783
GaudiHandleArrayProperty & operator=(const GaudiHandleArrayBase &value)
Definition: Property.h:935
SwapCall(callback_t &input)
Definition: Property.h:313
GaudiHandleArrayBase * m_pValue
Pointer to the real property.
Definition: Property.h:964
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
Gaudi::Property< short > ShortProperty
Definition: Property.h:773
std::string type() const
property type
Definition: Property.h:46
std::string documentation() const
property documentation
Definition: Property.h:42
Gaudi::Property< std::vector< unsigned long > > UnsignedLongArrayProperty
Definition: Property.h:816
Details::PropertyBase * clone() const override
clones the current property
Definition: Property.h:552
Gaudi::Property< TYPE & > SimplePropertyRef
Definition: Property.h:766
string s
Definition: gaudirun.py:253
Gaudi::Property< unsigned long long & > UnsignedLongLongPropertyRef
Definition: Property.h:799
void clearBounds()
Clear both bounds (lower and upper) at the same time.
Definition: Property.h:295
void setReadHandler(std::function< void(PropertyBase &)> fun)
Definition: Property.h:340
GAUDI_API const Gaudi::Details::PropertyBase * getProperty(const std::vector< const Gaudi::Details::PropertyBase * > *p, const std::string &name)
get the property by name from the list of the properties
Definition: Property.cpp:320
StatusCode setProperty(IInterface *component, const std::string &name, const Gaudi::Property< TYPE > &value, const std::string &doc="")
simple function to set the property of the given object from another property
Definition: Property.h:1474
std::function< void(PropertyBase &)> getReadHandler() const
Definition: Property.h:341
Gaudi::Property< std::vector< std::string > & > StringArrayPropertyRef
Definition: Property.h:842
bool assign(const Details::PropertyBase &source) override
get the value from another property
Definition: Property.h:692
bool assign(const PropertyBase &source) override
Definition: Property.h:905
bool operator!=(const T &other) const
inequality comparison
Definition: Property.h:504
Gaudi::Property< long > LongProperty
Definition: Property.h:777
void setUpdateHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:326
Gaudi::Property< std::vector< char > & > CharArrayPropertyRef
Definition: Property.h:827
const ValueType & value() const
Backward compatibility (.
Definition: Property.h:540
void clearLower()
Clear lower bound value.
Definition: Property.h:275
Base class to handles to be used in lieu of naked pointers to various Gaudi components.
Definition: GaudiHandle.h:94
AttribStringParser::Iterator begin(const AttribStringParser &parser)
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:793
Gaudi::Property< std::vector< float > > FloatArrayProperty
Definition: Property.h:819
ValueType operator++(int)
Definition: Property.h:630
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:310
boost::string_ref m_documentation
property doc string
Definition: Property.h:139
bool load(PropertyBase &destination) const override
Definition: Property.h:943
#define GAUDI_API
Definition: Kernel.h:110
GaudiHandleProperty & operator=(const GaudiHandleBase &value)
Definition: Property.h:895
Gaudi::Property< std::vector< short > & > ShortArrayPropertyRef
Definition: Property.h:830
STL class.
Property(OWNER *owner, std::string name, T &&value, std::string doc="")
Autodeclaring constructor with property name, value and documentation.
Definition: Property.h:427
const std::function< void(PropertyBase &)> updateCallBack() const override
get a reference to the updateCallBack
Definition: Property.h:870
Details::PropertyBase & declareReadHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for reading
Definition: Property.h:453
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::Property< unsigned char > UnsignedCharProperty
Definition: Property.h:772
VerifierType m_verifier
Definition: Property.h:394
const std::function< void(Details::PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:466
Gaudi::Property< short & > ShortPropertyRef
Definition: Property.h:792
std::string toString(const Type &)
void setUpper(const TYPE &value)
Set upper bound value.
Definition: Property.h:269
void setReadHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:320
Details::Property::UpdateHandler HandlersType
Definition: Property.h:389
Gaudi::Property< unsigned char & > UnsignedCharPropertyRef
Definition: Property.h:791
ValueType operator--(int)
Definition: Property.h:641
decltype(std::declval< TP >()+std::declval< T >()) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:748
void useReadHandler(const PropertyBase &) const
Definition: Property.h:319
Gaudi::Property< std::vector< bool > > BooleanArrayProperty
Definition: Property.h:807
const std::type_info * type_info() const
property type-info
Definition: Property.h:44
Gaudi::Property< std::vector< unsigned int > & > UnsignedIntegerArrayPropertyRef
Definition: Property.h:833
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:711
void toStream(std::ostream &out) const override
value -> stream
Definition: Property.h:724
Gaudi::Property< bool & > BooleanPropertyRef
Definition: Property.h:788
void useUpdateHandler(PropertyBase &p)
Definition: Property.h:345