diff --git a/DDCore/include/DD4hep/OpaqueData.h b/DDCore/include/DD4hep/OpaqueData.h index 194fb61da26272a776d94a20a04645bf48d8353a..49c3af5379d47eb8053c3e6c8574de27358a76e3 100644 --- a/DDCore/include/DD4hep/OpaqueData.h +++ b/DDCore/include/DD4hep/OpaqueData.h @@ -122,6 +122,8 @@ namespace dd4hep { void* bind(const BasicGrammar* grammar); /// Bind data value in place void* bind(void* ptr, size_t len, const BasicGrammar* grammar); + /// Bind external data value to the pointer + void bindExtern(void* ptr, const BasicGrammar* grammar); /// Construct conditions object and bind the data template <typename T, typename... Args> T& construct(Args... args); /// Bind data value @@ -132,6 +134,8 @@ namespace dd4hep { template <typename T> T& bind(const std::string& value); /// Bind data value template <typename T> T& bind(void* ptr, size_t len, const std::string& value); + /// Bind external data value to the pointer + template <typename T> void bindExtern(T* ptr); }; /// Generic getter. Specify the exact type, not a polymorph type @@ -183,5 +187,10 @@ namespace dd4hep { } return ret; } + /// Bind external data value to the pointer + template <typename T> void OpaqueDataBlock::bindExtern(T* ptr) { + bindExtern(ptr, &BasicGrammar::instance<T>()); + } + } /* End namespace dd4hep */ #endif /* DD4HEP_OPAQUEDATA_H */ diff --git a/DDCore/src/OpaqueData.cpp b/DDCore/src/OpaqueData.cpp index 79b4ac291a14cbf9d8a9de8338e548a1ab2d0520..04f19d6dfce8703ba9fe534a7b669c8a59621cf9 100644 --- a/DDCore/src/OpaqueData.cpp +++ b/DDCore/src/OpaqueData.cpp @@ -143,6 +143,18 @@ void* OpaqueDataBlock::bind(const BasicGrammar* g) { return 0; } +/// Bind external data value to the pointer +void OpaqueDataBlock::bindExtern(void* ptr, const BasicGrammar* gr) { + if ( grammar != 0 && type != EXTERN_DATA ) { + // We cannot ingore secondary requests for data bindings. + // This leads to memory leaks in the caller! + except("OpaqueData","You may not bind opaque data multiple times!"); + } + pointer = ptr; + grammar = gr; + type = EXTERN_DATA; +} + /// Set data value void* OpaqueDataBlock::bind(void* ptr, size_t size, const BasicGrammar* g) { if ( (type&EXTERN_DATA) == EXTERN_DATA ) {