ATLAS Offline Software
Loading...
Searching...
No Matches
PropertyMgr.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ASGTOOLS_PROPERTYMGR_ICC
6#define ASGTOOLS_PROPERTYMGR_ICC
7
8// System include(s):
9#include <memory>
10
11// Local include(s):
12#include "AsgTools/TProperty.h"
13#include "AsgMessaging/MsgStreamMacros.h"
14
15template< typename T >
16Property* PropertyMgr::declareProperty( const std::string& name, T& loc ) {
17
18 // Create the property object:
19 Property* pprop = createProperty( loc );
20
21 // Remember it:
22 ATH_MSG_DEBUG( "Declaring " << pprop->typeName() << " property: " << name );
23 m_props[ name ] = pprop;
24
25 // Return a pointer to it:
26 return pprop;
27}
28
29template< typename T >
30StatusCode PropertyMgr::setProperty( const std::string& name, const T& rval ) {
31
32 // Look for the property:
33 PropMap_t::const_iterator iprop = m_props.find( name );
34 if( iprop == m_props.end() ) {
35 ATH_MSG_ERROR( "Property not found: " << name );
36 return StatusCode::FAILURE;
37 }
38
39 // Access the property object:
40 Property* pprop = iprop->second;
41 // Create a helper property object:
42 std::unique_ptr< Property > pinprop( createProperty( rval ) );
43 // Try setting the managed property using the helper property object:
44 if( pprop->setFrom( *pinprop ) ) {
45 ATH_MSG_ERROR( "Value assignment failed for " << name );
46 return StatusCode::FAILURE;
47 }
48
49 // We were successful:
50 return StatusCode::SUCCESS;
51}
52
53template< typename T >
54StatusCode PropertyMgr::getProperty( const std::string& name,
55 T& valout ) const {
56
57 // Look for the property:
58 PropMap_t::const_iterator iprop = m_props.find( name );
59 if( iprop == m_props.end() ) {
60 ATH_MSG_ERROR( "Property not found: " << name );
61 return StatusCode::FAILURE;
62 }
63
64 // Access the property object:
65 Property* pprop = iprop->second;
66 // Create a helper property object:
67 std::unique_ptr< Property > pretprop( createProperty( valout ) );
68 // Try retrieving the property using the helper property object:
69 if( pretprop->setFrom( *pprop ) ) {
70 ATH_MSG_ERROR( "Value retrieval failed for " << name );
71 return StatusCode::FAILURE;
72 }
73
74 // We were successful:
75 return StatusCode::SUCCESS;
76}
77
78#endif // ASGTOOLS_PROPERTYMGR_ICC