From eb6e3af14390ecb5704cc082162629b7262b7da2 Mon Sep 17 00:00:00 2001 From: Kerstin Keller Date: Mon, 24 Jun 2024 13:08:17 +0200 Subject: [PATCH] Further renaming. --- ecal/core/src/ecal_descgate.h | 4 +-- .../src/monitoring/ecal_monitoring_impl.h | 8 +++--- ecal/core/src/readwrite/ecal_reader.h | 2 +- ecal/core/src/readwrite/ecal_writer.h | 2 +- ecal/core/src/service/ecal_clientgate.h | 2 +- ecal/core/src/util/ecal_expmap.h | 23 +++++++++------- .../tests/cpp/expmap_test/src/expmap_test.cpp | 26 +++++++++---------- 7 files changed, 36 insertions(+), 31 deletions(-) diff --git a/ecal/core/src/ecal_descgate.h b/ecal/core/src/ecal_descgate.h index 9c96e0bd67..fbc1065324 100644 --- a/ecal/core/src/ecal_descgate.h +++ b/ecal/core/src/ecal_descgate.h @@ -89,7 +89,7 @@ namespace eCAL CDescGate& operator=(CDescGate&&) = delete; protected: - using QualityTopicIdExpMap = eCAL::Util::CExpiredMap; + using QualityTopicIdExpMap = eCAL::Util::CExpirationMap; struct SQualityTopicIdMap { explicit SQualityTopicIdMap(const std::chrono::milliseconds& timeout_) : map(timeout_) {}; @@ -97,7 +97,7 @@ namespace eCAL QualityTopicIdExpMap map; }; - using QualityServiceIdExpMap = eCAL::Util::CExpiredMap; + using QualityServiceIdExpMap = eCAL::Util::CExpirationMap; struct SQualityServiceIdMap { explicit SQualityServiceIdMap(const std::chrono::milliseconds& timeout_) : map(timeout_) {}; diff --git a/ecal/core/src/monitoring/ecal_monitoring_impl.h b/ecal/core/src/monitoring/ecal_monitoring_impl.h index 6c077765a8..703bda8594 100644 --- a/ecal/core/src/monitoring/ecal_monitoring_impl.h +++ b/ecal/core/src/monitoring/ecal_monitoring_impl.h @@ -81,7 +81,7 @@ namespace eCAL bool RegisterTopic(const Registration::Sample& sample_, enum ePubSub pubsub_type_); bool UnregisterTopic(const Registration::Sample& sample_, enum ePubSub pubsub_type_); - using TopicMonMapT = Util::CExpiredMap; + using TopicMonMapT = Util::CExpirationMap; struct STopicMonMap { explicit STopicMonMap(const std::chrono::milliseconds& timeout_) : @@ -92,7 +92,7 @@ namespace eCAL std::unique_ptr map; }; - using ProcessMonMapT = Util::CExpiredMap; + using ProcessMonMapT = Util::CExpirationMap; struct SProcessMonMap { explicit SProcessMonMap(const std::chrono::milliseconds& timeout_) : @@ -103,7 +103,7 @@ namespace eCAL std::unique_ptr map; }; - using ServerMonMapT = Util::CExpiredMap; + using ServerMonMapT = Util::CExpirationMap; struct SServerMonMap { explicit SServerMonMap(const std::chrono::milliseconds& timeout_) : @@ -114,7 +114,7 @@ namespace eCAL std::unique_ptr map; }; - using ClientMonMapT = Util::CExpiredMap; + using ClientMonMapT = Util::CExpirationMap; struct SClientMonMap { explicit SClientMonMap(const std::chrono::milliseconds& timeout_) : diff --git a/ecal/core/src/readwrite/ecal_reader.h b/ecal/core/src/readwrite/ecal_reader.h index f83f3ef82d..fbe0213e22 100644 --- a/ecal/core/src/readwrite/ecal_reader.h +++ b/ecal/core/src/readwrite/ecal_reader.h @@ -143,7 +143,7 @@ namespace eCAL std::atomic m_topic_size; std::atomic m_connected; - using PublicationMapT = Util::CExpiredMap>; + using PublicationMapT = Util::CExpirationMap>; mutable std::mutex m_pub_map_mtx; PublicationMapT m_pub_map; diff --git a/ecal/core/src/readwrite/ecal_writer.h b/ecal/core/src/readwrite/ecal_writer.h index 4842d72585..d7738f8254 100644 --- a/ecal/core/src/readwrite/ecal_writer.h +++ b/ecal/core/src/readwrite/ecal_writer.h @@ -153,7 +153,7 @@ namespace eCAL std::atomic m_connected; - using SSubscriptionMapT = Util::CExpiredMap>; + using SSubscriptionMapT = Util::CExpirationMap>; mutable std::mutex m_sub_map_mtx; SSubscriptionMapT m_sub_map; diff --git a/ecal/core/src/service/ecal_clientgate.h b/ecal/core/src/service/ecal_clientgate.h index f21747b480..d3930051fe 100644 --- a/ecal/core/src/service/ecal_clientgate.h +++ b/ecal/core/src/service/ecal_clientgate.h @@ -64,7 +64,7 @@ namespace eCAL std::shared_timed_mutex m_client_set_sync; ServiceNameServiceImplSetT m_client_set; - using ConnectedMapT = Util::CExpiredMap; + using ConnectedMapT = Util::CExpirationMap; std::shared_timed_mutex m_service_register_map_sync; ConnectedMapT m_service_register_map; }; diff --git a/ecal/core/src/util/ecal_expmap.h b/ecal/core/src/util/ecal_expmap.h index 9706f2bb62..fd71dcfca1 100644 --- a/ecal/core/src/util/ecal_expmap.h +++ b/ecal/core/src/util/ecal_expmap.h @@ -37,7 +37,7 @@ namespace eCAL namespace Util { /** - * @brief A map that stores key-value pairs with an expiration time. + * @brief A map that stores key-value pairs and the time at which they have last been updated. * * @tparam Key The type of the keys. * @tparam T The type of the values. @@ -47,9 +47,9 @@ namespace eCAL * * From the outside / for the user, this class acts as a regular std::map. * However, it provides one additional function (erase_expired) that removes expired elements from this map. - * So it's basically a cache that can invalidate itself, based on the current time provided by the clock. + * Elements are considered to be expired, if they have not been accessed (via `operator[]`) within a given timeout period. * - * Internally, this is realized by storing both a map and a list internally. + * Internally, this is realized by storing both a map and a list. * The map stores the regular key, and then the actual value and additional an iterator into the timestamp list. * The timestamp list stores together a timestamp and the key which was inserted into the list at that given timestamp. * It is always kept in a sorted order. @@ -62,7 +62,7 @@ namespace eCAL class ClockType = std::chrono::steady_clock, class Compare = std::less, class Alloc = std::allocator > > - class CExpiredMap + class CExpirationMap { public: // Type declarations necessary to be compliant to a regular map. @@ -179,8 +179,8 @@ namespace eCAL // Constructor specifies the timeout of the map - CExpiredMap() : _timeout(std::chrono::milliseconds(5000)) {}; - explicit CExpiredMap(typename ClockType::duration t) : _timeout(t) {}; + CExpirationMap() : _timeout(std::chrono::milliseconds(5000)) {}; + explicit CExpirationMap(typename ClockType::duration t) : _timeout(t) {}; /** * @brief set expiration time @@ -233,8 +233,13 @@ namespace eCAL return _internal_map.max_size(); } - // Element access - // Obtain value of the cached function for k + /** + * @brief Accesses the value associated with the given key, resetting its expiration time. + * + * @param key The key to access the value for. + * + * @return The value associated with the key. + */ T& operator[](const Key& k) { // Attempt to find existing record @@ -293,7 +298,7 @@ namespace eCAL * @brief Erase all expired key-value pairs from the map. * * This function erases all expired key-value pairs from the internal map / timestamp list. - * The CExpiredMap class does not call this function internally, it has to be called explicitly by the user. + * The CExpirationMap class does not call this function internally, it has to be called explicitly by the user. */ void erase_expired(std::list* keys_erased_from_expired_map = nullptr) //-V826 { diff --git a/ecal/tests/cpp/expmap_test/src/expmap_test.cpp b/ecal/tests/cpp/expmap_test/src/expmap_test.cpp index e777b20e91..3a7f57aaef 100644 --- a/ecal/tests/cpp/expmap_test/src/expmap_test.cpp +++ b/ecal/tests/cpp/expmap_test/src/expmap_test.cpp @@ -61,7 +61,7 @@ TestingClock::duration TestingClock::current_time{ 0 }; TEST(core_cpp_core, ExpMap_SetGet) { // create the map with 2500 ms expiration - eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); // set "A" expmap["A"] = 1; @@ -119,14 +119,14 @@ TEST(core_cpp_core, ExpMap_SetGet) TEST(core_cpp_core, ExpMap_EraseEmptyMap) { - eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); expmap.erase_expired(); EXPECT_TRUE(expmap.empty()); } TEST(core_cpp_core, ExpMap_Insert) { - eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); auto ret = expmap.insert(std::make_pair("A", 1)); auto key = (*ret.first).first; @@ -146,7 +146,7 @@ TEST(core_cpp_core, ExpMap_Insert) // This tests uses find to find an element TEST(core_cpp_core, ExpMap_Find) { - eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); auto it = expmap.find("A"); EXPECT_EQ(expmap.end(), it); @@ -162,10 +162,10 @@ TEST(core_cpp_core, ExpMap_Find) EXPECT_EQ(0, expmap.size()); } -// This test assures that find can be called on a const CExpiredMap and returns an CExpiredMap::const_iterator +// This test assures that find can be called on a const CExpirationMap and returns an CExpirationMap::const_iterator TEST(core_cpp_core, ExpMap_FindConst) { - eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); auto it = expmap.find("A"); EXPECT_EQ(expmap.end(), it); @@ -175,7 +175,7 @@ TEST(core_cpp_core, ExpMap_FindConst) const auto& const_ref_exmap = expmap; auto const_it = const_ref_exmap.find("A"); // assert that we are actually getting a const_iterator here! - static_assert(std::is_same::const_iterator>::value, "We're not being returned a const_iterator from find."); + static_assert(std::is_same::const_iterator>::value, "We're not being returned a const_iterator from find."); int i = (*const_it).second; EXPECT_EQ(i, 1); @@ -187,7 +187,7 @@ TEST(core_cpp_core, ExpMap_FindConst) TEST(core_cpp_core, ExpMap_Iterate) { // create the map with 2500 ms expiration - eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); expmap["A"] = 1; std::string key; @@ -203,7 +203,7 @@ TEST(core_cpp_core, ExpMap_Iterate) EXPECT_EQ(1, value); } -void ConstRefIterate(const eCAL::Util::CExpiredMap& map) +void ConstRefIterate(const eCAL::Util::CExpirationMap& map) { std::string key; int value; @@ -221,7 +221,7 @@ void ConstRefIterate(const eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); expmap["A"] = 1; ConstRefIterate(expmap); @@ -229,7 +229,7 @@ TEST(core_cpp_core, ExpMap_ConstExpMapIterate) TEST(core_cpp_core, ExpMap_Empty) { - eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); EXPECT_EQ(true, expmap.empty()); expmap["A"] = 1; EXPECT_EQ(false, expmap.empty()); @@ -237,7 +237,7 @@ TEST(core_cpp_core, ExpMap_Empty) TEST(core_cpp_core, ExpMap_Size) { - eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); EXPECT_EQ(0, expmap.size()); expmap["A"] = 1; EXPECT_EQ(1, expmap.size()); @@ -245,7 +245,7 @@ TEST(core_cpp_core, ExpMap_Size) TEST(core_cpp_core, ExpMap_Remove) { - eCAL::Util::CExpiredMap expmap(std::chrono::milliseconds(200)); + eCAL::Util::CExpirationMap expmap(std::chrono::milliseconds(200)); expmap["A"] = 1; EXPECT_EQ(1, expmap.size()); EXPECT_TRUE(expmap.erase("A"));