From 3b0411a5a44d1fea433996e54317319796f6ab8f Mon Sep 17 00:00:00 2001 From: Scott Snyder <scott.snyder@cern.ch> Date: Fri, 30 Jan 2015 05:32:33 +0100 Subject: [PATCH] Add StringPool::clear(). (SGTools-00-24-06) * Tagging SGTools-00-24-06. * SGTools/StringPool.h, src/StringPool.cxx: Add clear(). * test/StringPool_test.cxx, share/StringPool_test.ref: Test it. 2015-01-28 Paolo Calafiura <calaf@calaf-C7Z87-OCE> * Tagging SGTools-00-24-05 * SGTools/DataProxy.h: do not return bool by reference... * SGTools/SGVersionedKey.h: protect SGImplSvc friend decl to remove compiler warning in non-HIVE mode --- Control/SGTools/SGTools/DataProxy.h | 2 +- Control/SGTools/SGTools/SGVersionedKey.h | 2 + Control/SGTools/SGTools/StringPool.h | 14 ++++++- Control/SGTools/share/StringPool_test.ref | 1 + Control/SGTools/src/StringPool.cxx | 46 +++++++++++++++++++---- Control/SGTools/test/StringPool_test.cxx | 4 ++ 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/Control/SGTools/SGTools/DataProxy.h b/Control/SGTools/SGTools/DataProxy.h index abd00db6063..aaf39ba6ee8 100755 --- a/Control/SGTools/SGTools/DataProxy.h +++ b/Control/SGTools/SGTools/DataProxy.h @@ -150,7 +150,7 @@ namespace SG { void resetOnly(const bool& flag) { m_resetFlag = flag; } /// Check reset only: - const bool& isResetOnly() const { return m_resetFlag; } + bool isResetOnly() const { return m_resetFlag; } bool bindHandle(IResetable* ir); void unbindHandle(IResetable* ir); diff --git a/Control/SGTools/SGTools/SGVersionedKey.h b/Control/SGTools/SGTools/SGVersionedKey.h index f79c2f6d0e7..5e7d97eb205 100644 --- a/Control/SGTools/SGTools/SGVersionedKey.h +++ b/Control/SGTools/SGTools/SGVersionedKey.h @@ -28,7 +28,9 @@ namespace SG { **/ class VersionedKey { friend class ::StoreGateSvc; //call copyVK +#ifdef ATHENAHIVE friend class ::SGImplSvc; //call copyVK +#endif public: ///quickly determine whether a string has the right format to be a VK static bool isVersionedKey(const char *); diff --git a/Control/SGTools/SGTools/StringPool.h b/Control/SGTools/SGTools/StringPool.h index 3897312a354..9b71299e9f0 100755 --- a/Control/SGTools/SGTools/StringPool.h +++ b/Control/SGTools/SGTools/StringPool.h @@ -97,10 +97,20 @@ public: /** * @brief Debugging dump. Write to cout. */ - void dump () const; + void dump() const; + + + /** + * @brief Empty the pool and release all allocated memory. + */ + void clear(); private: - StringPoolImpl* m_impl; + /// Helpers to retrieve the impl object, creating it if needed. + const StringPoolImpl* impl() const; + StringPoolImpl* impl(); + + mutable StringPoolImpl* m_impl; // Don't allow copying. StringPool (const StringPool&); diff --git a/Control/SGTools/share/StringPool_test.ref b/Control/SGTools/share/StringPool_test.ref index 94db96eba5c..df2ff9364b6 100755 --- a/Control/SGTools/share/StringPool_test.ref +++ b/Control/SGTools/share/StringPool_test.ref @@ -11,3 +11,4 @@ pool dump 3979421c 4 paks aspdk pok asd fd9252c 1 MNIIQGNLVGTGLKIGIVVGRFNDFITSKLLSGAEDALLRHGVDTNDIDVAWVPGAFEIPFAAKKMAETKKYDAIITLGTVIRGATTSYDYVCNEAAKGIAQAANTTGVPVIFGIVTTENIEQAIERAGTKAGNKGVDCAVSAIEMANLNRSFE 1b269909 5 asd laskjkd lkajsd +pool dump2 diff --git a/Control/SGTools/src/StringPool.cxx b/Control/SGTools/src/StringPool.cxx index 6ebfe4b7dfd..6f3ed27b147 100755 --- a/Control/SGTools/src/StringPool.cxx +++ b/Control/SGTools/src/StringPool.cxx @@ -128,7 +128,7 @@ void StringPoolImpl::dump() const * @brief Constructor. */ StringPool::StringPool() - : m_impl (new StringPoolImpl) + : m_impl (nullptr) { } @@ -138,7 +138,7 @@ StringPool::StringPool() */ StringPool::~StringPool() { - delete m_impl; + clear(); } @@ -156,7 +156,7 @@ StringPool::sgkey_t StringPool::stringToKey (const std::string& str, uint64_t crc = crc64 (str); if (aux) crc = crc64addint (crc, aux); sgkey_t key = (crc & sgkey_t_max); - if (!m_impl->registerKey (key, str, aux)) + if (!impl()->registerKey (key, str, aux)) std::abort(); return key; } @@ -172,7 +172,7 @@ StringPool::sgkey_t StringPool::stringToKey (const std::string& str, const std::string* StringPool::keyToString (sgkey_t key) const { sgaux_t aux; - return m_impl->keyToString (key, aux); + return impl()->keyToString (key, aux); } @@ -187,7 +187,7 @@ const std::string* StringPool::keyToString (sgkey_t key) const const std::string* StringPool::keyToString (sgkey_t key, sgaux_t& aux) const { - return m_impl->keyToString (key, aux); + return impl()->keyToString (key, aux); } @@ -208,7 +208,7 @@ bool StringPool::registerKey (sgkey_t key, { // Make sure the primary mapping is registered first. stringToKey (str, aux); - return m_impl->registerKey (key, str, aux); + return impl()->registerKey (key, str, aux); } @@ -217,7 +217,39 @@ bool StringPool::registerKey (sgkey_t key, */ void StringPool::dump () const { - m_impl->dump(); + impl()->dump(); +} + + +/** + * @brief Empty the pool and release all allocated memory. + */ +void StringPool::clear() +{ + delete m_impl; + m_impl = nullptr; +} + + +/** + * @brief Helper to retrieve the impl object, creating it if needed. + */ +StringPoolImpl* StringPool::impl() +{ + if (!m_impl) + m_impl = new StringPoolImpl; + return m_impl; +} + + +/** + * @brief Helper to retrieve the impl object, creating it if needed. + */ +const StringPoolImpl* StringPool::impl() const +{ + if (!m_impl) + m_impl = new StringPoolImpl; + return m_impl; } diff --git a/Control/SGTools/test/StringPool_test.cxx b/Control/SGTools/test/StringPool_test.cxx index 796666ba91a..b003d0d42a5 100755 --- a/Control/SGTools/test/StringPool_test.cxx +++ b/Control/SGTools/test/StringPool_test.cxx @@ -95,6 +95,10 @@ void test1() assert (sp.registerKey (keys[10], strings[10], aux[10])); assert (!sp.registerKey (keys[10], strings[11], aux[10])); assert (!sp.registerKey (keys[10], strings[10], aux[11])); + + sp.clear(); + std::cout << "pool dump2\n"; + sp.dump(); } -- GitLab