Skip to content

Commit

Permalink
Further renaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
KerstinKeller committed Jun 24, 2024
1 parent 5197b05 commit eb6e3af
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
4 changes: 2 additions & 2 deletions ecal/core/src/ecal_descgate.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ namespace eCAL
CDescGate& operator=(CDescGate&&) = delete;

protected:
using QualityTopicIdExpMap = eCAL::Util::CExpiredMap<STopicIdKey, Util::SQualityTopicInfo>;
using QualityTopicIdExpMap = eCAL::Util::CExpirationMap<STopicIdKey, Util::SQualityTopicInfo>;
struct SQualityTopicIdMap
{
explicit SQualityTopicIdMap(const std::chrono::milliseconds& timeout_) : map(timeout_) {};
mutable std::mutex mtx;
QualityTopicIdExpMap map;
};

using QualityServiceIdExpMap = eCAL::Util::CExpiredMap<SServiceIdKey, Util::SQualityServiceInfo>;
using QualityServiceIdExpMap = eCAL::Util::CExpirationMap<SServiceIdKey, Util::SQualityServiceInfo>;
struct SQualityServiceIdMap
{
explicit SQualityServiceIdMap(const std::chrono::milliseconds& timeout_) : map(timeout_) {};
Expand Down
8 changes: 4 additions & 4 deletions ecal/core/src/monitoring/ecal_monitoring_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, Monitoring::STopicMon>;
using TopicMonMapT = Util::CExpirationMap<std::string, Monitoring::STopicMon>;
struct STopicMonMap
{
explicit STopicMonMap(const std::chrono::milliseconds& timeout_) :
Expand All @@ -92,7 +92,7 @@ namespace eCAL
std::unique_ptr<TopicMonMapT> map;
};

using ProcessMonMapT = Util::CExpiredMap<std::string, Monitoring::SProcessMon>;
using ProcessMonMapT = Util::CExpirationMap<std::string, Monitoring::SProcessMon>;
struct SProcessMonMap
{
explicit SProcessMonMap(const std::chrono::milliseconds& timeout_) :
Expand All @@ -103,7 +103,7 @@ namespace eCAL
std::unique_ptr<ProcessMonMapT> map;
};

using ServerMonMapT = Util::CExpiredMap<std::string, Monitoring::SServerMon>;
using ServerMonMapT = Util::CExpirationMap<std::string, Monitoring::SServerMon>;
struct SServerMonMap
{
explicit SServerMonMap(const std::chrono::milliseconds& timeout_) :
Expand All @@ -114,7 +114,7 @@ namespace eCAL
std::unique_ptr<ServerMonMapT> map;
};

using ClientMonMapT = Util::CExpiredMap<std::string, Monitoring::SClientMon>;
using ClientMonMapT = Util::CExpirationMap<std::string, Monitoring::SClientMon>;
struct SClientMonMap
{
explicit SClientMonMap(const std::chrono::milliseconds& timeout_) :
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/readwrite/ecal_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace eCAL
std::atomic<size_t> m_topic_size;

std::atomic<bool> m_connected;
using PublicationMapT = Util::CExpiredMap<SPublicationInfo, std::tuple<SDataTypeInformation, SLayerStates>>;
using PublicationMapT = Util::CExpirationMap<SPublicationInfo, std::tuple<SDataTypeInformation, SLayerStates>>;
mutable std::mutex m_pub_map_mtx;
PublicationMapT m_pub_map;

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/readwrite/ecal_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace eCAL

std::atomic<bool> m_connected;

using SSubscriptionMapT = Util::CExpiredMap<SSubscriptionInfo, std::tuple<SDataTypeInformation, SLayerStates>>;
using SSubscriptionMapT = Util::CExpirationMap<SSubscriptionInfo, std::tuple<SDataTypeInformation, SLayerStates>>;
mutable std::mutex m_sub_map_mtx;
SSubscriptionMapT m_sub_map;

Expand Down
2 changes: 1 addition & 1 deletion ecal/core/src/service/ecal_clientgate.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace eCAL
std::shared_timed_mutex m_client_set_sync;
ServiceNameServiceImplSetT m_client_set;

using ConnectedMapT = Util::CExpiredMap<std::string, SServiceAttr>;
using ConnectedMapT = Util::CExpirationMap<std::string, SServiceAttr>;
std::shared_timed_mutex m_service_register_map_sync;
ConnectedMapT m_service_register_map;
};
Expand Down
23 changes: 14 additions & 9 deletions ecal/core/src/util/ecal_expmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -62,7 +62,7 @@ namespace eCAL
class ClockType = std::chrono::steady_clock,
class Compare = std::less<Key>,
class Alloc = std::allocator<std::pair<const Key, T> > >
class CExpiredMap
class CExpirationMap
{
public:
// Type declarations necessary to be compliant to a regular map.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Key>* keys_erased_from_expired_map = nullptr) //-V826
{
Expand Down
26 changes: 13 additions & 13 deletions ecal/tests/cpp/expmap_test/src/expmap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));

// set "A"
expmap["A"] = 1;
Expand Down Expand Up @@ -119,14 +119,14 @@ TEST(core_cpp_core, ExpMap_SetGet)

TEST(core_cpp_core, ExpMap_EraseEmptyMap)
{
eCAL::Util::CExpiredMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
expmap.erase_expired();
EXPECT_TRUE(expmap.empty());
}

TEST(core_cpp_core, ExpMap_Insert)
{
eCAL::Util::CExpiredMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
auto ret = expmap.insert(std::make_pair("A", 1));

auto key = (*ret.first).first;
Expand All @@ -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<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));

auto it = expmap.find("A");
EXPECT_EQ(expmap.end(), it);
Expand All @@ -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<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));

auto it = expmap.find("A");
EXPECT_EQ(expmap.end(), it);
Expand All @@ -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<decltype(const_it), eCAL::Util::CExpiredMap<std::string, int, TestingClock>::const_iterator>::value, "We're not being returned a const_iterator from find.");
static_assert(std::is_same<decltype(const_it), eCAL::Util::CExpirationMap<std::string, int, TestingClock>::const_iterator>::value, "We're not being returned a const_iterator from find.");
int i = (*const_it).second;
EXPECT_EQ(i, 1);

Expand All @@ -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<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
expmap["A"] = 1;

std::string key;
Expand All @@ -203,7 +203,7 @@ TEST(core_cpp_core, ExpMap_Iterate)
EXPECT_EQ(1, value);
}

void ConstRefIterate(const eCAL::Util::CExpiredMap<std::string, int, TestingClock>& map)
void ConstRefIterate(const eCAL::Util::CExpirationMap<std::string, int, TestingClock>& map)
{
std::string key;
int value;
Expand All @@ -221,31 +221,31 @@ void ConstRefIterate(const eCAL::Util::CExpiredMap<std::string, int, TestingCloc
TEST(core_cpp_core, ExpMap_ConstExpMapIterate)
{
// create the map with 2500 ms expiration
eCAL::Util::CExpiredMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
expmap["A"] = 1;

ConstRefIterate(expmap);
}

TEST(core_cpp_core, ExpMap_Empty)
{
eCAL::Util::CExpiredMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
EXPECT_EQ(true, expmap.empty());
expmap["A"] = 1;
EXPECT_EQ(false, expmap.empty());
}

TEST(core_cpp_core, ExpMap_Size)
{
eCAL::Util::CExpiredMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
EXPECT_EQ(0, expmap.size());
expmap["A"] = 1;
EXPECT_EQ(1, expmap.size());
}

TEST(core_cpp_core, ExpMap_Remove)
{
eCAL::Util::CExpiredMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
eCAL::Util::CExpirationMap<std::string, int, TestingClock> expmap(std::chrono::milliseconds(200));
expmap["A"] = 1;
EXPECT_EQ(1, expmap.size());
EXPECT_TRUE(expmap.erase("A"));
Expand Down

0 comments on commit eb6e3af

Please sign in to comment.