The Gaudi Framework  v30r3 (a5ef0a68)
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( auto ) 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( auto ) size() const
560  {
561  return value().size();
562  }
563  template <class T = const ValueType>
564  inline decltype( auto ) length() const
565  {
566  return value().length();
567  }
568  template <class T = const ValueType>
569  inline decltype( auto ) empty() const
570  {
571  return value().empty();
572  }
573  template <class T = ValueType>
574  inline decltype( auto ) clear()
575  {
576  value().clear();
577  }
578  template <class T = const ValueType>
579  inline decltype( auto ) begin() const
580  {
581  return value().begin();
582  }
583  template <class T = const ValueType>
584  inline decltype( auto ) end() const
585  {
586  return value().end();
587  }
588  template <class T = ValueType>
589  inline decltype( auto ) begin()
590  {
591  return value().begin();
592  }
593  template <class T = ValueType>
594  inline decltype( auto ) 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( auto ) find( const typename T::key_type& key ) const
610  {
611  return value().find( key );
612  }
613  template <class T = ValueType>
614  inline decltype( auto ) find( const typename T::key_type& key )
615  {
616  return value().find( key );
617  }
618  template <class ARG, class T = ValueType>
619  inline decltype( auto ) 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( auto ) key() const
660  {
661  return value().key();
662  }
663  template <class T = const ValueType>
664  inline decltype( auto ) objKey() const
665  {
666  return value().objKey();
667  }
668  template <class T = const ValueType>
669  inline decltype( auto ) fullKey() const
670  {
671  return value().fullKey();
672  }
673  template <class T = ValueType>
674  inline decltype( auto ) initialize()
675  {
676  return value().initialize();
677  }
678  template <class T = ValueType>
679  inline decltype( auto ) makeHandles() const
680  {
681  return value().makeHandles();
682  }
683  template <class ARG, class T = ValueType>
684  inline decltype( auto ) makeHandles( const ARG& arg ) const
685  {
686  return value().makeHandles( arg );
687  }
689  // ==========================================================================
690 
691  // Delegate operator() to the value
692  template <class... Args>
693  inline decltype( std::declval<ValueType>()( std::declval<Args&&>()... ) ) operator()( Args&&... args ) const
694  noexcept( noexcept( std::declval<ValueType>()( std::declval<Args&&>()... ) ) )
695  {
696  return value()( std::forward<Args>( args )... );
697  }
698 
699  public:
701  bool assign( const Details::PropertyBase& source ) override
702  {
703  // Check if the property of is of "the same" type, except for strings
704  const Property* p =
705  ( std::is_same<ValueType, std::string>::value ) ? nullptr : dynamic_cast<const Property*>( &source );
706  if ( p ) {
707  *this = p->value();
708  } else {
709  this->fromString( source.toString() ).ignore();
710  }
711  return true;
712  }
714  bool load( Details::PropertyBase& dest ) const override
715  {
716  // delegate to the 'opposite' method
717  return dest.assign( *this );
718  }
720  StatusCode fromString( const std::string& source ) override
721  {
722  using Converter = Details::Property::StringConverter<ValueType>;
723  *this = Converter().fromString( m_value, source );
724  return StatusCode::SUCCESS;
725  }
727  std::string toString() const override
728  {
729  using Converter = Details::Property::StringConverter<ValueType>;
730  return Converter().toString( *this );
731  }
733  void toStream( std::ostream& out ) const override
734  {
735  m_handlers.useReadHandler( *this );
736  using Utils::toStream;
737  toStream( m_value, out );
738  }
739  };
740 
742  template <class T, class TP, class V, class H>
743  bool operator==( const T& v, const Property<TP, V, H>& p )
744  {
745  return p == v;
746  }
747 
749  template <class T, class TP, class V, class H>
750  bool operator!=( const T& v, const Property<TP, V, H>& p )
751  {
752  return p != v;
753  }
754 
756  template <class T, class TP, class V, class H>
757  decltype( auto ) operator+( const T& v, const Property<TP, V, H>& p )
758  {
759  return v + p.value();
760  }
761 
762  template <class TYPE, class HANDLERS = Details::Property::UpdateHandler>
764 
765  template <class TYPE>
768 
769 } // namespace Gaudi
770 
771 template <class TYPE>
773 
774 template <class TYPE>
776 
777 // Typedef Properties for built-in types
793 
795 
796 // Typedef PropertyRefs for built-in types
812 
814 
815 // Typedef "Arrays" of Properties for built-in types
831 
833 
834 // Typedef "Arrays" of PropertyRefs for built-in types
850 
852 
855 template <typename Handler = typename Gaudi::Details::Property::UpdateHandler>
857 {
858  Handler m_handlers;
859 
860 public:
862 
864  PropertyBase& declareReadHandler( std::function<void( PropertyBase& )> fun ) override
865  {
866  m_handlers.setReadHandler( std::move( fun ) );
867  return *this;
868  }
870  PropertyBase& declareUpdateHandler( std::function<void( PropertyBase& )> fun ) override
871  {
872  m_handlers.setUpdateHandler( std::move( fun ) );
873  return *this;
874  }
875 
877  const std::function<void( PropertyBase& )> readCallBack() const override { return m_handlers.getReadHandler(); }
879  const std::function<void( PropertyBase& )> updateCallBack() const override { return m_handlers.getUpdateHandler(); }
880 
882  void useReadHandler() const { m_handlers.useReadHandler( *this ); }
883 
885  bool useUpdateHandler() override
886  {
887  m_handlers.useUpdateHandler( *this );
888  return true;
889  }
890 };
891 
892 // forward-declaration is sufficient here
893 class GaudiHandleBase;
894 
895 // implementation in header file only where the GaudiHandleBase class
896 // definition is not needed. The rest goes into the .cpp file.
897 // The goal is to decouple the header files, to avoid that the whole
898 // world depends on GaudiHandle.h
900 {
901 public:
903 
905  {
906  setValue( value );
907  return *this;
908  }
909 
910  GaudiHandleProperty* clone() const override { return new GaudiHandleProperty( *this ); }
911 
912  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
913 
914  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
915 
916  std::string toString() const override;
917 
918  void toStream( std::ostream& out ) const override;
919 
920  StatusCode fromString( const std::string& s ) override;
921 
922  const GaudiHandleBase& value() const
923  {
924  useReadHandler();
925  return *m_pValue;
926  }
927 
928  bool setValue( const GaudiHandleBase& value );
929 
930 private:
934 };
935 
936 // forward-declaration is sufficient here
938 
940 {
941 public:
943 
945  {
946  setValue( value );
947  return *this;
948  }
949 
950  GaudiHandleArrayProperty* clone() const override { return new GaudiHandleArrayProperty( *this ); }
951 
952  bool load( PropertyBase& destination ) const override { return destination.assign( *this ); }
953 
954  bool assign( const PropertyBase& source ) override { return fromString( source.toString() ).isSuccess(); }
955 
956  std::string toString() const override;
957 
958  void toStream( std::ostream& out ) const override;
959 
960  StatusCode fromString( const std::string& s ) override;
961 
963  {
964  useReadHandler();
965  return *m_pValue;
966  }
967 
968  bool setValue( const GaudiHandleArrayBase& value );
969 
970 private:
974 };
975 
976 namespace Gaudi
977 {
978  namespace Utils
979  {
980  // ========================================================================
998  GAUDI_API bool hasProperty( const IProperty* p, const std::string& name );
999  // ========================================================================
1017  GAUDI_API bool hasProperty( const IInterface* p, const std::string& name );
1018  // ========================================================================
1037  // ========================================================================
1056  // ========================================================================
1080  // ========================================================================
1105  // ========================================================================
1129  template <class TYPE>
1130  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc );
1131  // ========================================================================
1154  template <class TYPE>
1155  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value )
1156  {
1157  return setProperty( component, name, value, std::string() );
1158  }
1159  // ========================================================================
1173  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const std::string& value,
1174  const std::string& doc = "" );
1175  // ========================================================================
1189  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name, const char* value,
1190  const std::string& doc = "" );
1191  // ========================================================================
1205  template <unsigned N>
1206  StatusCode setProperty( IProperty* component, const std::string& name, const char ( &value )[N],
1207  const std::string& doc = "" )
1208  {
1209  return component ? setProperty( component, name, std::string( value, value + N ), doc ) : StatusCode::FAILURE;
1210  }
1211  // ========================================================================
1242  template <class TYPE>
1243  StatusCode setProperty( IProperty* component, const std::string& name, const TYPE& value, const std::string& doc )
1244  {
1245  using Gaudi::Utils::toString;
1246  return component && hasProperty( component, name )
1247  ? Gaudi::Utils::setProperty( component, name, toString( value ), doc )
1249  }
1250  // ========================================================================
1272  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name,
1273  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1274  // ========================================================================
1296  GAUDI_API StatusCode setProperty( IProperty* component, const std::string& name,
1297  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1298  // ========================================================================
1321  template <class TYPE>
1322  StatusCode setProperty( IProperty* component, const std::string& name, const Gaudi::Property<TYPE>& value,
1323  const std::string& doc = "" )
1324  {
1325  return setProperty( component, name, &value, doc );
1326  }
1327  // ========================================================================
1348  template <class TYPE>
1349  StatusCode setProperty( IInterface* component, const std::string& name, const TYPE& value,
1350  const std::string& doc = "" )
1351  {
1352  if ( !component ) {
1353  return StatusCode::FAILURE;
1354  }
1355  auto property = SmartIF<IProperty>{component};
1356  return property ? setProperty( property, name, value, doc ) : StatusCode::FAILURE;
1357  }
1358  // ========================================================================
1371  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const std::string& value,
1372  const std::string& doc = "" );
1373  // ========================================================================
1386  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name, const char* value,
1387  const std::string& doc = "" );
1388  // ========================================================================
1402  template <unsigned N>
1403  StatusCode setProperty( IInterface* component, const std::string& name, const char ( &value )[N],
1404  const std::string& doc = "" )
1405  {
1406  if ( 0 == component ) {
1407  return StatusCode::FAILURE;
1408  }
1409  return setProperty( component, name, std::string{value, value + N}, doc );
1410  }
1411  // ========================================================================
1433  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name,
1434  const Gaudi::Details::PropertyBase* property, const std::string& doc = "" );
1435  // ========================================================================
1457  GAUDI_API StatusCode setProperty( IInterface* component, const std::string& name,
1458  const Gaudi::Details::PropertyBase& property, const std::string& doc = "" );
1459  // ========================================================================
1482  template <class TYPE>
1483  StatusCode setProperty( IInterface* component, const std::string& name, const Gaudi::Property<TYPE>& value,
1484  const std::string& doc = "" )
1485  {
1486  return setProperty( component, name, &value, doc );
1487  }
1488  // ========================================================================
1489  } // end of namespace Gaudi::Utils
1490 } // end of namespace Gaudi
1491 // ============================================================================
1492 // The END
1493 // ============================================================================
1494 #endif // GAUDIKERNEL_PROPERTY_H
1495 // ============================================================================
Gaudi::Property< std::vector< float > & > FloatArrayPropertyRef
Definition: Property.h:847
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:1243
Gaudi::Property< signed char & > SignedCharPropertyRef
Definition: Property.h:799
Details::Property::NullVerifier VerifierType
Definition: Property.h:388
Gaudi::Property< std::vector< signed char > & > SignedCharArrayPropertyRef
Definition: Property.h:837
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:804
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:750
GaudiHandleProperty * clone() const override
clones the current property
Definition: Property.h:910
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:821
Gaudi::Property< TYPE > SimpleProperty
Definition: Property.h:772
Gaudi::Property< long long & > LongLongPropertyRef
Definition: Property.h:807
PropertyBase & declareReadHandler(void(HT::*MF)(PropertyBase &), HT *instance)
Definition: Property.h:75
Gaudi::Property< std::vector< int > > IntegerArrayProperty
Definition: Property.h:822
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:743
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:788
const std::function< void(PropertyBase &)> readCallBack() const override
get a reference to the readCallBack
Definition: Property.h:877
Implementation of property with value of concrete type.
Definition: Property.h:381
Gaudi::Property< long & > LongPropertyRef
Definition: Property.h:805
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:848
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:912
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:790
Gaudi::Property< int > IntegerProperty
Definition: Property.h:784
Gaudi::Property< std::vector< unsigned long long > & > UnsignedLongLongArrayPropertyRef
Definition: Property.h:846
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:950
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:789
Gaudi::Property< float & > FloatPropertyRef
Definition: Property.h:809
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:727
Gaudi::Property< std::vector< std::string > > StringArrayProperty
Definition: Property.h:832
Gaudi::Property< std::vector< unsigned short > & > UnsignedShortArrayPropertyRef
Definition: Property.h:840
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:819
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:783
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:787
Gaudi::Property< std::string & > StringPropertyRef
Definition: Property.h:813
StorageType m_value
Storage.
Definition: Property.h:393
Gaudi::Property< char & > CharPropertyRef
Definition: Property.h:798
Gaudi::Property< std::vector< bool > & > BooleanArrayPropertyRef
Definition: Property.h:835
Gaudi::Property< std::vector< long double > > LongDoubleArrayProperty
Definition: Property.h:830
Gaudi::Property< std::vector< long long > > LongLongArrayProperty
Definition: Property.h:826
Gaudi::Property< std::vector< double > > DoubleArrayProperty
Definition: Property.h:829
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:820
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:844
Gaudi::Property< std::vector< unsigned int > > UnsignedIntegerArrayProperty
Definition: Property.h:823
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:856
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:824
typename std::remove_reference< StorageType >::type ValueType
Definition: Property.h:387
Gaudi::Property< std::vector< long > & > LongArrayPropertyRef
Definition: Property.h:843
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:780
Gaudi::Property< char > CharProperty
Definition: Property.h:779
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:803
GaudiHandleBase * m_pValue
Pointer to the real property.
Definition: Property.h:933
Gaudi::Property< unsigned long & > UnsignedLongPropertyRef
Definition: Property.h:806
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:849
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:785
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:817
virtual PropertyBase & declareReadHandler(std::function< void(PropertyBase &)> fun)=0
set new callback for reading
const GaudiHandleBase & value() const
Definition: Property.h:922
Gaudi::Property< bool > BooleanProperty
Definition: Property.h:778
PropertyBase & declareUpdateHandler(std::function< void(PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:870
Gaudi::Property< std::vector< unsigned long long > > UnsignedLongLongArrayProperty
Definition: Property.h:827
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:864
const GaudiHandleArrayBase & value() const
Definition: Property.h:962
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:791
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:841
T move(T...args)
bool assign(const PropertyBase &source) override
Definition: Property.h:954
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:845
std::enable_if_t<!is_this_type< T >::value > not_copying
Definition: Property.h:401
Gaudi::Property< double & > DoublePropertyRef
Definition: Property.h:810
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:838
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:714
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:811
ValueType & value()
Definition: Property.h:541
STL class.
void useReadHandler() const
use the call-back function at reading, if available
Definition: Property.h:882
Gaudi::Property< std::vector< signed char > > SignedCharArrayProperty
Definition: Property.h:818
bool useUpdateHandler() override
use the call-back function at update, if available
Definition: Property.h:885
Gaudi::Property< std::string > StringProperty
Definition: Property.h:794
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:792
GaudiHandleArrayProperty & operator=(const GaudiHandleArrayBase &value)
Definition: Property.h:944
SwapCall(callback_t &input)
Definition: Property.h:313
GaudiHandleArrayBase * m_pValue
Pointer to the real property.
Definition: Property.h:973
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
Gaudi::Property< short > ShortProperty
Definition: Property.h:782
decltype(auto) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:757
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:825
Details::PropertyBase * clone() const override
clones the current property
Definition: Property.h:552
Gaudi::Property< TYPE & > SimplePropertyRef
Definition: Property.h:775
string s
Definition: gaudirun.py:253
Gaudi::Property< unsigned long long & > UnsignedLongLongPropertyRef
Definition: Property.h:808
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:1483
std::function< void(PropertyBase &)> getReadHandler() const
Definition: Property.h:341
Gaudi::Property< std::vector< std::string > & > StringArrayPropertyRef
Definition: Property.h:851
bool assign(const Details::PropertyBase &source) override
get the value from another property
Definition: Property.h:701
bool assign(const PropertyBase &source) override
Definition: Property.h:914
bool operator!=(const T &other) const
inequality comparison
Definition: Property.h:504
Gaudi::Property< long > LongProperty
Definition: Property.h:786
void setUpdateHandler(std::function< void(PropertyBase &)>)
Definition: Property.h:326
Gaudi::Property< std::vector< char > & > CharArrayPropertyRef
Definition: Property.h:836
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:802
Gaudi::Property< std::vector< float > > FloatArrayProperty
Definition: Property.h:828
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:952
#define GAUDI_API
Definition: Kernel.h:104
GaudiHandleProperty & operator=(const GaudiHandleBase &value)
Definition: Property.h:904
Gaudi::Property< std::vector< short > & > ShortArrayPropertyRef
Definition: Property.h:839
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:879
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:781
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:801
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:800
ValueType operator--(int)
Definition: Property.h:641
void useReadHandler(const PropertyBase &) const
Definition: Property.h:319
Gaudi::Property< std::vector< bool > > BooleanArrayProperty
Definition: Property.h:816
const std::type_info * type_info() const
property type-info
Definition: Property.h:44
Gaudi::Property< std::vector< unsigned int > & > UnsignedIntegerArrayPropertyRef
Definition: Property.h:842
StatusCode fromString(const std::string &source) override
string -> value
Definition: Property.h:720
void toStream(std::ostream &out) const override
value -> stream
Definition: Property.h:733
Gaudi::Property< bool & > BooleanPropertyRef
Definition: Property.h:797
void useUpdateHandler(PropertyBase &p)
Definition: Property.h:345