DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ComponentProperties_inl.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DD4HEP_DDG4_COMPONENTPROPERTIES_INL_H
14 #define DD4HEP_DDG4_COMPONENTPROPERTIES_INL_H
15 
16 // Framework include files
17 #include "DD4hep/BasicGrammar.h"
19 
20 // C/C++ include files
21 #include <sstream>
22 #include <vector>
23 #include <list>
24 #include <map>
25 #include <set>
26 #include <stdexcept>
27 
29 namespace DD4hep {
30 
32  template <typename TYPE> void Property::make(TYPE& val) {
33  static PropertyGrammar g(BasicGrammar::instance<TYPE>());
34  m_hdl = &g;
35  m_par = &val;
36  }
37 
39  template <typename TYPE> void Property::set(const TYPE& val) {
40  const PropertyGrammar& g = grammar();
41  if (g.type() == typeid(TYPE))
42  *(TYPE*) m_par = val;
43  else if (!g.fromString(m_par, BasicGrammar::instance< TYPE >().str(&val)))
44  PropertyGrammar::invalidConversion(typeid(TYPE), g.type());
45  }
46 
48  template <typename TYPE> Property& Property::operator=(const TYPE& val) {
49  this->set(val);
50  return *this;
51  }
52 
54  template <typename TYPE> void Property::value(TYPE& val) const {
55  const PropertyGrammar& g = grammar();
56  if (g.type() == typeid(TYPE))
57  val = *(TYPE*) m_par;
58  else if (!BasicGrammar::instance< TYPE >().fromString(&val, this->str()))
59  PropertyGrammar::invalidConversion(g.type(), typeid(TYPE));
60  }
61 
63  template <typename TYPE> TYPE Property::value() const {
64  TYPE temp;
65  this->value(temp);
66  return temp;
67  }
68 
69 } // End namespace DD4hep
70 
71 // Instantiate single property
72 #define DD4HEP_DEFINE_PROPERTY_TYPE(x) \
73  template x Property::value() const; \
74  template void Property::value(x& value) const; \
75  template void Property::set(const x& value); \
76  template Property& Property::operator=(const x& value); \
77  template void Property::make(x& value)
78 
79 // Instantiate single property with support for STL containers
80 #define DD4HEP_DEFINE_PROPERTY_CONT(x) \
81  DD4HEP_DEFINE_PROPERTY_TYPE(x); \
82  DD4HEP_DEFINE_PROPERTY_TYPE(std::vector<x>); \
83  DD4HEP_DEFINE_PROPERTY_TYPE(std::list<x>); \
84  DD4HEP_DEFINE_PROPERTY_TYPE(std::set<x>)
85 
86 #if defined(DD4HEP_HAVE_ALL_PARSERS)
87 // Instantiate single property with support for STL containers + same for unsigned
91 #define DD4HEP_DEFINE_PROPERTY_U_CONT(x) \
92  DD4HEP_DEFINE_PROPERTY_CONT(x); \
93  DD4HEP_DEFINE_PROPERTY_CONT(unsigned x)
94 
95 #else
96 
97 #define DD4HEP_DEFINE_PROPERTY_U_CONT(x) DD4HEP_DEFINE_PROPERTY_CONT(x)
98 
99 #endif // DD4HEP_HAVE_ALL_PARSERS
100 #endif // DD4HEP_DDG4_COMPONENTPROPERTIES_INL_H
void make(TYPE &value)
Setup property.
virtual const std::type_info & type() const
Access to the type information.
The property class to assign options to actions.
virtual bool fromString(void *ptr, const std::string &value) const
Set value from serialized string. On successful data conversion TRUE is returned. ...
Class describing the grammar representation of a given data type.
std::string str() const
Conversion to string value.
static void invalidConversion(const std::type_info &from, const std::type_info &to)
Error callback on invalid conversion.
const PropertyGrammar * m_hdl
Reference to the grammar of this property (extended type description)
Property & operator=(const Property &p)=default
Assignment operator.
const PropertyGrammar & grammar() const
Access grammar object.
static const double g
Definition: DD4hepUnits.h:162
TYPE value() const
Retrieve value.
void * m_par
Pointer to the data location.
void set(const TYPE &value)
Set value of this property.