From fc656fabca5f580865f94e0873335d003129a23b Mon Sep 17 00:00:00 2001 From: Sebastien Ponce <sebastien.ponce@cern.ch> Date: Thu, 6 Feb 2020 08:32:38 +0100 Subject: [PATCH] Cleaned up template function declarations, allowing to drop a lot of macros By only putting the templated code in the right place (i.e. in the header file where functions are declared), I could drop 2 useless headers and a large bunch of macros. --- DDCore/include/DD4hep/OpaqueData.h | 48 ++++++++++- .../include/DD4hep/detail/ConditionsInterna.h | 50 ----------- DDCore/include/DD4hep/detail/OpaqueData_inl.h | 84 ------------------- DDCore/src/AlignmentData.cpp | 4 - DDCore/src/AlignmentsCalculator.cpp | 1 - DDCore/src/AlignmentsInterna.cpp | 1 - DDCore/src/ConditionsData.cpp | 1 - DDCore/src/ConditonsTypes.cpp | 48 ----------- DDCore/src/OpaqueData.cpp | 2 - DDCore/src/OpaqueDataBinder.cpp | 2 +- DDCore/src/XML/XMLParsers.cpp | 1 + examples/DDDB/src/Detector/DeHandles.cpp | 6 -- 12 files changed, 49 insertions(+), 199 deletions(-) delete mode 100644 DDCore/include/DD4hep/detail/OpaqueData_inl.h delete mode 100644 DDCore/src/ConditonsTypes.cpp diff --git a/DDCore/include/DD4hep/OpaqueData.h b/DDCore/include/DD4hep/OpaqueData.h index ed538b79b..2ea2eb462 100644 --- a/DDCore/include/DD4hep/OpaqueData.h +++ b/DDCore/include/DD4hep/OpaqueData.h @@ -13,7 +13,10 @@ #ifndef DD4HEP_OPAQUEDATA_H #define DD4HEP_OPAQUEDATA_H +#include "DD4hep/detail/Grammar.h" + // C/C++ include files +#include <ostream> #include <typeinfo> #include <vector> #include <string> @@ -104,7 +107,6 @@ namespace dd4hep { /// Data buffer type: Must be a bitmap of enum _DataTypes! unsigned int type; - public: /// Standard initializing constructor OpaqueDataBlock(); /// Copy constructor @@ -140,6 +142,50 @@ namespace dd4hep { std::ostream& operator<< (std::ostream& s, const OpaqueDataBlock& data); } /* End namespace dd4hep */ +/// Generic getter. Specify the exact type, not a polymorph type +template <typename T> T& dd4hep::OpaqueData::get() { + if (!grammar || !grammar->equals(typeid(T))) { throw std::bad_cast(); } + return *(T*)pointer; +} + +/// Generic getter (const version). Specify the exact type, not a polymorph type +template <typename T> const T& dd4hep::OpaqueData::get() const { + if (!grammar || !grammar->equals(typeid(T))) { throw std::bad_cast(); } + return *(T*)pointer; +} + +/// Bind data value +template <typename T> T& dd4hep::OpaqueDataBlock::bind() { + this->bind(&BasicGrammar::instance<T>()); + return *(new(this->pointer) T()); +} + +/// Bind data value +template <typename T> T& dd4hep::OpaqueDataBlock::bind(void* ptr, size_t len) { + this->bind(ptr,len,&BasicGrammar::instance<T>()); + return *(new(this->pointer) T()); +} + +/// Bind grammar and assign value +template <typename T> T& dd4hep::OpaqueDataBlock::bind(const std::string& value) { + T& ret = this->bind<T>(); + if ( !value.empty() && !this->fromString(value) ) { + throw std::runtime_error("OpaqueDataBlock::set> Failed to bind type "+ + typeName(typeid(T))+" to condition data block."); + } + return ret; +} + +/// Bind grammar and assign value +template <typename T> T& dd4hep::OpaqueDataBlock::bind(void* ptr, size_t len, const std::string& value) { + T& ret = this->bind<T>(ptr, len); + if ( !value.empty() && !this->fromString(value) ) { + throw std::runtime_error("OpaqueDataBlock::set> Failed to bind type "+ + typeName(typeid(T))+" to condition data block."); + } + return ret; +} + #include "DD4hep/BasicGrammar.h" /// Namespace for the AIDA detector description toolkit diff --git a/DDCore/include/DD4hep/detail/ConditionsInterna.h b/DDCore/include/DD4hep/detail/ConditionsInterna.h index c5764e2cb..fe948b6a5 100644 --- a/DDCore/include/DD4hep/detail/ConditionsInterna.h +++ b/DDCore/include/DD4hep/detail/ConditionsInterna.h @@ -26,7 +26,6 @@ #include "DD4hep/Conditions.h" #include "DD4hep/BasicGrammar.h" #include "DD4hep/NamedObject.h" -#include "DD4hep/detail/OpaqueData_inl.h" // C/C++ include files #include <map> @@ -140,53 +139,4 @@ namespace dd4hep { } /* End namespace dd4hep */ -#define DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ - DD4HEP_DEFINE_OPAQUEDATA_TYPE(x) \ - namespace dd4hep { \ - template x& Condition::bind<x>(const std::string& val); \ - template x& Condition::bind<x>(); \ - template x& Condition::get<x>(); \ - template const x& Condition::get<x>() const; \ - } - -#define DD4HEP_DEFINE_CONDITIONS_TYPE_DUMMY(x) \ - namespace dd4hep{namespace Parsers{int parse(x&, const std::string&){return 1;}}} \ - DD4HEP_DEFINE_CONDITIONS_TYPE(x) - -#define DD4HEP_DEFINE_EXTERNAL_CONDITIONS_TYPE(x) \ - namespace dd4hep { \ - template <> x& Condition::bind<x>(const std::string& val); \ - template <> x& Condition::bind<x>(); \ - template <> x& Condition::get<x>(); \ - template <> const x& Condition::get<x>() const; \ - } - -#if defined(DD4HEP_HAVE_ALL_PARSERS) -#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::deque<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(dd4hep::detail::Primitive<x>::int_map_t) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(dd4hep::detail::Primitive<x>::ulong_map_t) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(dd4hep::detail::Primitive<x>::string_map_t) - -#define DD4HEP_DEFINE_CONDITIONS_U_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_CONT(unsigned x) - -#else - -#define DD4HEP_DEFINE_CONDITIONS_CONT(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(x) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::vector<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::list<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(std::set<x>) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(dd4hep::detail::Primitive<x>::int_map_t) \ - DD4HEP_DEFINE_CONDITIONS_TYPE(dd4hep::detail::Primitive<x>::string_map_t) - -#define DD4HEP_DEFINE_CONDITIONS_U_CONT(x) DD4HEP_DEFINE_CONDITIONS_CONT(x) - -#endif // DD4HEP_HAVE_ALL_PARSERS #endif /* DD4HEP_DDCORE_CONDITIONINTERNA_H */ diff --git a/DDCore/include/DD4hep/detail/OpaqueData_inl.h b/DDCore/include/DD4hep/detail/OpaqueData_inl.h deleted file mode 100644 index 21397a6f6..000000000 --- a/DDCore/include/DD4hep/detail/OpaqueData_inl.h +++ /dev/null @@ -1,84 +0,0 @@ -//========================================================================== -// AIDA Detector description implementation -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see $DD4hepINSTALL/LICENSE. -// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. -// -// Author : M.Frank -// -//========================================================================== -// -// NOTE: -// -// This is an internal include file. It should only be included to -// instantiate code. Otherwise the OpaqueData include file should be -// sufficient for all practical purposes. -// -//========================================================================== -#ifndef DD4HEP_OPAQUEDATA_INL_H -#define DD4HEP_OPAQUEDATA_INL_H - -// Framework include files -#include "DD4hep/Primitives.h" -#include "DD4hep/OpaqueData.h" -#include "DD4hep/BasicGrammar.h" - -/// Namespace for the AIDA detector description toolkit -namespace dd4hep { - - /// Generic getter. Specify the exact type, not a polymorph type - template <typename T> T& OpaqueData::get() { - if (!grammar || !grammar->equals(typeid(T))) { throw std::bad_cast(); } - return *(T*)pointer; - } - - /// Generic getter (const version). Specify the exact type, not a polymorph type - template <typename T> const T& OpaqueData::get() const { - if (!grammar || !grammar->equals(typeid(T))) { throw std::bad_cast(); } - return *(T*)pointer; - } - - /// Bind data value - template <typename T> T& OpaqueDataBlock::bind() { - this->bind(&BasicGrammar::instance<T>()); - return *(new(this->pointer) T()); - } - - /// Bind data value - template <typename T> T& OpaqueDataBlock::bind(void* ptr, size_t len) { - this->bind(ptr,len,&BasicGrammar::instance<T>()); - return *(new(this->pointer) T()); - } - - /// Bind grammar and assign value - template <typename T> T& OpaqueDataBlock::bind(const std::string& value) { - T& ret = this->bind<T>(); - if ( !value.empty() && !this->fromString(value) ) { - throw std::runtime_error("OpaqueDataBlock::set> Failed to bind type "+ - typeName(typeid(T))+" to condition data block."); - } - return ret; - } - - /// Bind grammar and assign value - template <typename T> T& OpaqueDataBlock::bind(void* ptr, size_t len, const std::string& value) { - T& ret = this->bind<T>(ptr, len); - if ( !value.empty() && !this->fromString(value) ) { - throw std::runtime_error("OpaqueDataBlock::set> Failed to bind type "+ - typeName(typeid(T))+" to condition data block."); - } - return ret; - } - -} /* End namespace dd4hep */ - -#define DD4HEP_DEFINE_OPAQUEDATA_TYPE(x) \ - namespace dd4hep { \ - template x& OpaqueDataBlock::bind<x>(); \ - template x& OpaqueDataBlock::bind<x>(const std::string& val); \ - } - -#endif /* DD4HEP_OPAQUEDATA_INL_H */ diff --git a/DDCore/src/AlignmentData.cpp b/DDCore/src/AlignmentData.cpp index 57fa9b165..f1162a523 100644 --- a/DDCore/src/AlignmentData.cpp +++ b/DDCore/src/AlignmentData.cpp @@ -246,7 +246,3 @@ DD4HEP_DEFINE_PARSER_GRAMMAR(Delta,eval_none<Delta>) DD4HEP_DEFINE_PARSER_GRAMMAR(DeltaMap,eval_none<DeltaMap>) DD4HEP_DEFINE_PARSER_GRAMMAR(AlignmentData,eval_none<AlignmentData>) -DD4HEP_DEFINE_CONDITIONS_TYPE(Delta) -DD4HEP_DEFINE_CONDITIONS_TYPE(DeltaMap) -DD4HEP_DEFINE_CONDITIONS_TYPE(AlignmentData) - diff --git a/DDCore/src/AlignmentsCalculator.cpp b/DDCore/src/AlignmentsCalculator.cpp index 90f44e11b..c6ac6762c 100644 --- a/DDCore/src/AlignmentsCalculator.cpp +++ b/DDCore/src/AlignmentsCalculator.cpp @@ -331,4 +331,3 @@ DD4HEP_DEFINE_PARSER_DUMMY(OrderedMap) #include "DD4hep/detail/BasicGrammar_inl.h" #include "DD4hep/detail/ConditionsInterna.h" DD4HEP_DEFINE_PARSER_GRAMMAR(OrderedMap,eval_none<OrderedMap>) -DD4HEP_DEFINE_CONDITIONS_TYPE(OrderedMap) diff --git a/DDCore/src/AlignmentsInterna.cpp b/DDCore/src/AlignmentsInterna.cpp index 6f777e159..fb1b917f8 100644 --- a/DDCore/src/AlignmentsInterna.cpp +++ b/DDCore/src/AlignmentsInterna.cpp @@ -81,5 +81,4 @@ namespace dd4hep { } } DD4HEP_DEFINE_PARSER_GRAMMAR(AlignmentObject,eval_none<AlignmentObject>) -DD4HEP_DEFINE_CONDITIONS_TYPE(AlignmentObject) diff --git a/DDCore/src/ConditionsData.cpp b/DDCore/src/ConditionsData.cpp index 507e90407..6620ba832 100644 --- a/DDCore/src/ConditionsData.cpp +++ b/DDCore/src/ConditionsData.cpp @@ -82,4 +82,3 @@ DD4HEP_DEFINE_PARSER_DUMMY(AbstractMap) #include "DD4hep/detail/BasicGrammar_inl.h" #include "DD4hep/detail/ConditionsInterna.h" DD4HEP_DEFINE_PARSER_GRAMMAR(AbstractMap,eval_none<AbstractMap>) -DD4HEP_DEFINE_CONDITIONS_TYPE(AbstractMap) diff --git a/DDCore/src/ConditonsTypes.cpp b/DDCore/src/ConditonsTypes.cpp deleted file mode 100644 index 9187fe96e..000000000 --- a/DDCore/src/ConditonsTypes.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//========================================================================== -// AIDA Detector description implementation -//-------------------------------------------------------------------------- -// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) -// All rights reserved. -// -// For the licensing terms see $DD4hepINSTALL/LICENSE. -// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. -// -// Author : M.Frank -// -//========================================================================== - -// Framework include files -#include "DD4hep/Primitives.h" -#include "DD4hep/detail/ConditionsInterna.h" -#include "DD4hep/detail/ComponentProperties_inl.h" - -#include "Math/Point3D.h" -#include "Math/Vector3D.h" -#include "Math/Vector4D.h" - -// C/C++ include files -#include <string> -#include <vector> -#include <list> -#include <set> -#include <map> -#include <deque> - -#if defined(DD4HEP_HAVE_ALL_PARSERS) -DD4HEP_DEFINE_CONDITIONS_U_CONT(char) -DD4HEP_DEFINE_CONDITIONS_U_CONT(short) -DD4HEP_DEFINE_CONDITIONS_U_CONT(long long) -#endif // DD4HEP_HAVE_ALL_PARSERS - -DD4HEP_DEFINE_CONDITIONS_U_CONT(int) -DD4HEP_DEFINE_CONDITIONS_U_CONT(long) - -DD4HEP_DEFINE_CONDITIONS_CONT(bool) -DD4HEP_DEFINE_CONDITIONS_CONT(float) -DD4HEP_DEFINE_CONDITIONS_CONT(double) -DD4HEP_DEFINE_CONDITIONS_CONT(std::string) - -// ROOT::Math Object instances -DD4HEP_DEFINE_CONDITIONS_CONT(ROOT::Math::XYZPoint) -DD4HEP_DEFINE_CONDITIONS_CONT(ROOT::Math::XYZVector) -DD4HEP_DEFINE_CONDITIONS_CONT(ROOT::Math::PxPyPzEVector) diff --git a/DDCore/src/OpaqueData.cpp b/DDCore/src/OpaqueData.cpp index 97368d273..fc70b7276 100644 --- a/DDCore/src/OpaqueData.cpp +++ b/DDCore/src/OpaqueData.cpp @@ -16,7 +16,6 @@ #include "DD4hep/Primitives.h" #include "DD4hep/OpaqueData.h" #include "DD4hep/InstanceCount.h" -#include "DD4hep/detail/OpaqueData_inl.h" // C/C++ header files #include <cstring> @@ -207,5 +206,4 @@ DD4HEP_DEFINE_PARSER_DUMMY(OpaqueDataBlock) #include "DD4hep/detail/BasicGrammar_inl.h" #include "DD4hep/detail/ConditionsInterna.h" DD4HEP_DEFINE_PARSER_GRAMMAR(OpaqueDataBlock,eval_none<OpaqueDataBlock>) -DD4HEP_DEFINE_CONDITIONS_TYPE(OpaqueDataBlock) diff --git a/DDCore/src/OpaqueDataBinder.cpp b/DDCore/src/OpaqueDataBinder.cpp index 7d30173f5..e509f146b 100644 --- a/DDCore/src/OpaqueDataBinder.cpp +++ b/DDCore/src/OpaqueDataBinder.cpp @@ -14,7 +14,7 @@ // Framework include files #include "DD4hep/OpaqueDataBinder.h" #include "DD4hep/Conditions.h" -#include "DD4hep/detail/OpaqueData_inl.h" +#include "DD4hep/OpaqueData.h" #include "DD4hep/detail/ConditionsInterna.h" // C/C++ include files diff --git a/DDCore/src/XML/XMLParsers.cpp b/DDCore/src/XML/XMLParsers.cpp index f3228de0f..321c19e29 100644 --- a/DDCore/src/XML/XMLParsers.cpp +++ b/DDCore/src/XML/XMLParsers.cpp @@ -16,6 +16,7 @@ // Framework include files #include "DD4hep/Objects.h" +#include "DD4hep/Conditions.h" #include "DD4hep/Printout.h" #include "DD4hep/OpaqueData.h" #include "DD4hep/OpaqueDataBinder.h" diff --git a/examples/DDDB/src/Detector/DeHandles.cpp b/examples/DDDB/src/Detector/DeHandles.cpp index a0d7dc3fa..ae8f7cf6d 100644 --- a/examples/DDDB/src/Detector/DeHandles.cpp +++ b/examples/DDDB/src/Detector/DeHandles.cpp @@ -60,10 +60,4 @@ DD4HEP_DEFINE_PARSER_GRAMMAR(DeVPObject,eval_none<DeVPObject>) DD4HEP_DEFINE_PARSER_GRAMMAR(DeVPSensorObject,eval_none<DeVPSensorObject>) DD4HEP_DEFINE_PARSER_GRAMMAR(DeVPGenericObject,eval_none<DeVPGenericObject>) -DD4HEP_DEFINE_CONDITIONS_TYPE(DeVPStaticObject) -DD4HEP_DEFINE_CONDITIONS_TYPE(DeVPSensorStaticObject) -DD4HEP_DEFINE_CONDITIONS_TYPE(DeVPGenericStaticObject) -DD4HEP_DEFINE_CONDITIONS_TYPE(DeVPObject) -DD4HEP_DEFINE_CONDITIONS_TYPE(DeVPSensorObject) -DD4HEP_DEFINE_CONDITIONS_TYPE(DeVPGenericObject) #endif -- GitLab