diff --git a/DDCore/include/DD4hep/Handle.h b/DDCore/include/DD4hep/Handle.h index 2c24816f2f02e997eac5bac5c0cef8451d1b175f..f46eae0bbac4d85bb1846756e047e6c3ddf8b8ac 100644 --- a/DDCore/include/DD4hep/Handle.h +++ b/DDCore/include/DD4hep/Handle.h @@ -200,34 +200,32 @@ namespace DD4hep { /// Functor to destroy handles and delete the cached object \ingroup DD4HEP_GEOMETRY template <typename T> class DestroyHandle { public: - void operator()(T p) const { - destroyHandle(p); - } + void operator()(T p) const { destroyHandle(p); } }; /// Functor to destroy handles and delete the cached object \ingroup DD4HEP_GEOMETRY template <typename T> class ReleaseHandle { public: - void operator()(T p) const { - releaseHandle(p); - } + void operator()(T p) const { releaseHandle(p); } }; /// map Functor to destroy handles and delete the cached object \ingroup DD4HEP_GEOMETRY template <typename M> class DestroyHandles { public: + /// Container reference M& object; - DestroyHandles(M& m) - : object(m) { - } - ~DestroyHandles() { - object.clear(); - } - void operator()(std::pair<typename M::key_type, typename M::mapped_type> p) const { - DestroyHandle<typename M::mapped_type>()(p.second); - } + /// Copy constructor allowed! + DestroyHandles(const DestroyHandles& c) : object(c.object) {} + /// Initializing constructor + DestroyHandles(M& m) : object(m) { } + /// Defautl destructor + ~DestroyHandles() { } + /// Action operator + void operator()(const std::pair<typename M::key_type, typename M::mapped_type>& p) const + { DestroyHandle<typename M::mapped_type>()(p.second); } }; /// Functional created of map destruction functors - template <typename M> DestroyHandles<M> destroyHandles(M& m) { - return DestroyHandles<M>(m); + template <typename M> void destroyHandles(M& m) { + for_each(m.begin(), m.end(), DestroyHandles<M>(m)); + m.clear(); } /// String conversions: boolean value to string \ingroup DD4HEP_GEOMETRY diff --git a/DDCore/include/DD4hep/Primitives.h b/DDCore/include/DD4hep/Primitives.h index 1dc02eb4c36baf876e2ec252d46e24d54a17ed17..37801a006cbdd4f34e5e2455763b074af347e03f 100644 --- a/DDCore/include/DD4hep/Primitives.h +++ b/DDCore/include/DD4hep/Primitives.h @@ -268,12 +268,8 @@ namespace DD4hep { template <typename M> class DestroyObjects { public: M& object; - DestroyObjects(M& m) - : object(m) { - } - ~DestroyObjects() { - object.clear(); - } + DestroyObjects(M& m) : object(m) { } + ~DestroyObjects() { object.clear(); } void operator()(std::pair<typename M::key_type, typename M::mapped_type> p) const { DestroyObject<typename M::mapped_type>()(p.second); } diff --git a/DDCore/include/XML/XMLElements.h b/DDCore/include/XML/XMLElements.h index 3e2d6ce8a5959c65595606520f595259bedc3a88..d437a33f1239b1d5f65835a4c29a9bd6e2b59758 100644 --- a/DDCore/include/XML/XMLElements.h +++ b/DDCore/include/XML/XMLElements.h @@ -682,9 +682,9 @@ namespace DD4hep { Handle_t m_element; /// Constructor from XmlElement handle - Element(const Handle_t& e) - : m_element(e) { - } + Element(const Handle_t& e) : m_element(e) { } + /// Constructor from XmlElement handle + Element(const Element& e) : m_element(e.m_element) { } /// Constructor from DOM document entity Element(const Document& document, const XmlChar* type); /// Access the hosting document handle of this DOM element @@ -722,7 +722,7 @@ namespace DD4hep { } /// Access the XmlElements parent Handle_t parent() const { - return m_element.parent(); + return m_element.parent(); } /// Access the XmlElements parent Elt_t parentElement() const; diff --git a/DDCore/src/DetectorInterna.cpp b/DDCore/src/DetectorInterna.cpp index 3eb4605915073c12dc6452930e7ddd2498b335a1..9b31f19581de77ac0815527c0f9250b27f92a2da 100644 --- a/DDCore/src/DetectorInterna.cpp +++ b/DDCore/src/DetectorInterna.cpp @@ -85,7 +85,7 @@ DetElementObject::DetElementObject(const std::string& nam, int ident) /// Internal object destructor: release extension object(s) DetElementObject::~DetElementObject() { - for_each(children.begin(), children.end(), destroyHandles(children)); + destroyHandles(children); deletePtr (referenceTrafo); if ( conditions.isValid() ) delete conditions.ptr(); conditions = ConditionsContainer(); diff --git a/DDCore/src/LCDDData.cpp b/DDCore/src/LCDDData.cpp index c3f04fd221367b6b061edf77bae5edaabb2fe774..d7f048e1ffb3eb2a675a3f002951541f7de18b50 100644 --- a/DDCore/src/LCDDData.cpp +++ b/DDCore/src/LCDDData.cpp @@ -51,15 +51,15 @@ void LCDDData::destroyData(bool destroy_mgr) { destroyHandle(m_world); destroyHandle(m_field); destroyHandle(m_header); - for_each(m_readouts.begin(), m_readouts.end(), destroyHandles(m_readouts)); - for_each(m_idDict.begin(), m_idDict.end(), destroyHandles(m_idDict)); - for_each(m_limits.begin(), m_limits.end(), destroyHandles(m_limits)); - for_each(m_regions.begin(), m_regions.end(), destroyHandles(m_regions)); - for_each(m_alignments.begin(), m_alignments.end(), destroyHandles(m_alignments)); - for_each(m_sensitive.begin(), m_sensitive.end(), destroyHandles(m_sensitive)); - for_each(m_display.begin(), m_display.end(), destroyHandles(m_display)); - for_each(m_fields.begin(), m_fields.end(), destroyHandles(m_fields)); - for_each(m_define.begin(), m_define.end(), destroyHandles(m_define)); + destroyHandles(m_readouts); + destroyHandles(m_idDict); + destroyHandles(m_limits); + destroyHandles(m_regions); + destroyHandles(m_alignments); + destroyHandles(m_sensitive); + destroyHandles(m_display); + destroyHandles(m_fields); + destroyHandles(m_define); destroyHandle(m_volManager); m_properties.clear(); diff --git a/DDCore/src/VolumeManagerInterna.cpp b/DDCore/src/VolumeManagerInterna.cpp index 9b2f12c394b9934ec9d7b5f2c2bb845a949b0bd1..e8dc6c4c6887077451141af51fd04cbb97b34598 100644 --- a/DDCore/src/VolumeManagerInterna.cpp +++ b/DDCore/src/VolumeManagerInterna.cpp @@ -42,7 +42,7 @@ VolumeManagerObject::~VolumeManagerObject() { for_each(volumes.begin(), volumes.end(), destroyObjects(volumes)); volumes.clear(); /// Cleanup dependent managers - for_each(managers.begin(), managers.end(), destroyHandles(managers)); + destroyHandles(managers); managers.clear(); subdetectors.clear(); } diff --git a/DDCore/src/XML/XMLElements.cpp b/DDCore/src/XML/XMLElements.cpp index cce5f9b811b7c97c9026d44ec3ce7a09a76cde27..ed518584e3ae2fb8dae8b311083503b745a44ed3 100644 --- a/DDCore/src/XML/XMLElements.cpp +++ b/DDCore/src/XML/XMLElements.cpp @@ -218,14 +218,14 @@ template <typename T> static inline string __to_string(T value, const char* fmt) } /// Do-nothing version. Present for completeness and argument interchangeability -std::string DD4hep::XML::_toString(const char* s) { +string DD4hep::XML::_toString(const char* s) { if ( !s || *s == 0 ) return ""; else if ( !(*s == '$' && *(s+1) == '{') ) return s; return _checkEnviron(s); } /// Do-nothing version. Present for completeness and argument interchangeability -std::string DD4hep::XML::_toString(const std::string& s) { +string DD4hep::XML::_toString(const string& s) { if ( s.length() < 3 || s[0] != '$' ) return s; else if ( !(s[0] == '$' && s[1] == '{') ) return s; return _checkEnviron(s); @@ -348,7 +348,7 @@ void DD4hep::XML::_toDictionary(const XmlChar* name, T value) { #ifndef DD4HEP_USE_TINYXML template void DD4hep::XML::_toDictionary(const XmlChar* name, const char* value); #endif -template void DD4hep::XML::_toDictionary(const XmlChar* name, const std::string& value); +template void DD4hep::XML::_toDictionary(const XmlChar* name, const string& value); template void DD4hep::XML::_toDictionary(const XmlChar* name, unsigned long value); template void DD4hep::XML::_toDictionary(const XmlChar* name, unsigned int value); template void DD4hep::XML::_toDictionary(const XmlChar* name, unsigned short value); @@ -408,40 +408,49 @@ Strng_t DD4hep::XML::operator+(const Strng_t& a, const Strng_t& b) { } Tag_t DD4hep::XML::operator+(const Tag_t& a, const char* b) { - return a.str() + b; + string res = a.str() + b; + return Tag_t(res); } Tag_t DD4hep::XML::operator+(const char* a, const Tag_t& b) { - return a + b.str(); + string res = a + b.str(); + return Tag_t(res); } Tag_t DD4hep::XML::operator+(const Tag_t& a, const Strng_t& b) { - return a.str() + _toString(b); + string res = a.str() + _toString(b); + return Tag_t(res); } Tag_t DD4hep::XML::operator+(const Tag_t& a, const string& b) { - return a.str() + b; + string res = a.str() + b; + return Tag_t(res); } #ifndef DD4HEP_USE_TINYXML Strng_t DD4hep::XML::operator+(const Strng_t& a, const XmlChar* b) { - return _toString(a.ptr()) + _toString(b); + string res = _toString(a.ptr()) + _toString(b); + return Tag_t(res); } Strng_t DD4hep::XML::operator+(const XmlChar* a, const Strng_t& b) { - return _toString(a) + _toString(b.ptr()); + string res = _toString(a) + _toString(b.ptr()); + return Tag_t(res); } Strng_t DD4hep::XML::operator+(const XmlChar* a, const string& b) { - return _toString(a) + b; + string res = _toString(a) + b; + return Tag_t(res); } Strng_t DD4hep::XML::operator+(const string& a, const XmlChar* b) { - return a + _toString(b); + string res = a + _toString(b); + return Tag_t(res); } Tag_t DD4hep::XML::operator+(const Tag_t& a, const XmlChar* b) { - return a.str() + _toString(b); + string res = a.str() + _toString(b); + return Tag_t(res); } Strng_t& Strng_t::operator=(const XmlChar* s) { @@ -949,7 +958,7 @@ static unsigned int adler32(unsigned int adler, const XmlChar* xml_buff, size_t typedef unsigned int (fcn_t)(unsigned int, const XmlChar*, size_t); unsigned int Handle_t::checksum(unsigned int param, fcn_t fcn) const { #ifdef DD4HEP_USE_TINYXML - typedef std::map<std::string, std::string> StringMap; + typedef map<string, string> StringMap; TiXmlNode* n = Xml(m_node).n; if ( n ) { if ( 0 == fcn ) fcn = adler32; @@ -1159,11 +1168,11 @@ size_t Collection_t::size() const { } /// Helper function to throw an exception -void Collection_t::throw_loop_exception(const std::exception& e) const { +void Collection_t::throw_loop_exception(const exception& e) const { if (m_node) { - throw runtime_error(std::string(e.what()) + "\n" + "DD4hep: Error interpreting XML nodes of type <" + tag() + "/>"); + throw runtime_error(string(e.what()) + "\n" + "DD4hep: Error interpreting XML nodes of type <" + tag() + "/>"); } - throw runtime_error(std::string(e.what()) + "\n" + "DD4hep: Error interpreting collections XML nodes."); + throw runtime_error(string(e.what()) + "\n" + "DD4hep: Error interpreting collections XML nodes."); } void Collection_t::operator++() const { diff --git a/DDDB/CMakeLists.txt b/DDDB/CMakeLists.txt index 40b0914fc8287522b3a503d23b84213aea1418d8..9f5cf7477087429affb4a10866b2776932fb20c4 100644 --- a/DDDB/CMakeLists.txt +++ b/DDDB/CMakeLists.txt @@ -19,7 +19,7 @@ dd4hep_package( DDDB USES DDCore DDCond - [BOOST REQUIRED COMPONENTS filesystem] + [BOOST REQUIRED] INCLUDE_DIRS include INSTALL_INCLUDES include/DDDB)