Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:40

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #pragma once
0012 
0013 // Include Files
0014 #include <Gaudi/Details/PropertyBase.h>
0015 #include <GaudiKernel/GaudiException.h>
0016 #include <GaudiKernel/IInterface.h>
0017 #include <GaudiKernel/INamedInterface.h>
0018 #include <GaudiKernel/ToStream.h>
0019 #include <iostream>
0020 #include <string>
0021 #include <string_view>
0022 #include <vector>
0023 
0024 /** @class IProperty IProperty.h GaudiKernel/IProperty.h
0025 
0026     The IProperty is the basic interface for all components which have
0027     properties that can be set or get.
0028 
0029     @author Paul Maley
0030     @author Pere Mato
0031     @date   29/10/98
0032 */
0033 class GAUDI_API IProperty : virtual public IInterface {
0034 public:
0035   /// InterfaceID
0036   DeclareInterfaceID( IProperty, 3, 0 );
0037 
0038   /// Set the property from a property
0039   StatusCode setProperty( const Gaudi::Details::PropertyBase& p ) { return setProperty( p.name(), p ); }
0040   /// Set the property from a property with a different name
0041   virtual StatusCode setProperty( const std::string& name, const Gaudi::Details::PropertyBase& p ) = 0;
0042   /// Set the property by string
0043   virtual StatusCode setProperty( const std::string& s ) = 0;
0044   /// Set the property by name and value representation
0045   virtual StatusCode setPropertyRepr( const std::string& n, const std::string& r ) = 0;
0046   /// Special case for string literals
0047   StatusCode setProperty( const std::string& name, const char* v ) { return setProperty( name, std::string{ v } ); }
0048   /// Special case for std::string
0049   StatusCode setProperty( const std::string& name, const std::string& v ) {
0050     if ( !hasProperty( name ) ) return StatusCode::FAILURE;
0051     return setPropertyRepr( name, v );
0052   }
0053 
0054   /** set the property form the value
0055    *
0056    *  @code
0057    *
0058    *  std::vector<double> data = ... ;
0059    *  setProperty( "Data" , data ) ;
0060    *
0061    *  std::map<std::string,double> cuts = ... ;
0062    *  setProperty( "Cuts" , cuts ) ;
0063    *
0064    *  std::map<std::string,std::string> dict = ... ;
0065    *  setProperty( "Dictionary" , dict ) ;
0066    *
0067    *  @endcode
0068    *
0069    *  Note: the interface IProperty allows setting of the properties either
0070    *        directly from other properties or from strings only
0071    *
0072    *  This is very convenient in resetting of the default
0073    *  properties in the derived classes.
0074    *
0075    *  @param name      name of the property
0076    *  @param value     value of the property
0077    *  @see Gaudi::Utils::setProperty
0078    *  @author Vanya BELYAEV ibelyaev@physics.syr.edu
0079    *  @date 2007-05-13
0080    */
0081   template <class TYPE, typename = std::enable_if_t<!std::is_base_of_v<Gaudi::Details::PropertyBase, TYPE>>>
0082   StatusCode setProperty( const std::string& name, const TYPE& value ) {
0083     using Gaudi::Utils::toString;
0084     if ( !hasProperty( name ) ) return StatusCode::FAILURE;
0085     return setPropertyRepr( name, toString( value ) );
0086   }
0087   /// Get the property by property
0088   virtual StatusCode getProperty( Gaudi::Details::PropertyBase* p // Pointer to property to be set
0089   ) const = 0;
0090   /// Get the property by name
0091   virtual const Gaudi::Details::PropertyBase& getProperty( std::string_view name // Property name
0092   ) const = 0;
0093   /// Get the property by std::string
0094   virtual StatusCode getProperty( std::string_view n, std::string& v ) const = 0;
0095   /// Get list of properties
0096   virtual const std::vector<Gaudi::Details::PropertyBase*>& getProperties() const = 0;
0097 
0098   /// Return true if we have a property with the given name.
0099   virtual bool hasProperty( std::string_view name ) const = 0;
0100 };