RTC Toolkit 4.0.1
Loading...
Searching...
No Matches
serverAliasCache.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_SERVERALIASCACHE_HPP
14#define RTCTK_COMPONENTFRAMEWORK_SERVERALIASCACHE_HPP
15
17
18#include <string>
19#include <tuple>
20#include <vector>
21
23
31public:
35 void Clear() {
36 m_cache.clear();
37 }
38
45 void AddServerAlias(DataPointPath const& path, std::string const& alias) {
46 m_cache.push_back(std::make_tuple(path.ToString(), alias));
47 }
48
56 std::string GetServerAlias(DataPointPath const& path) {
57 // do a linear search through the table and pick the first entry that fits.
58 // if our path starts with a string from the table, then this is the match
59 // e.g. path = /foo/bar/baz and first table entry is /foo/ then this is a match
60 for (auto const& entry : m_cache) {
61 if (auto found = path.ToString().rfind(std::get<0>(entry), 0);
62 found != std::string::npos) {
63 return std::get<1>(entry);
64 }
65 }
66
67 // if nothing is found, return an empty string which corresponds to no server alias
68 return {};
69 }
70
71private:
72 // data structure holding the information
73 std::vector<std::tuple<std::string, std::string>> m_cache;
74};
75
76} // namespace rtctk::componentFramework
77
78#endif // RTCTK_COMPONENTFRAMEWORK_SERVERALIASCACHE_HPP
This class provides a wrapper for a data point path.
Definition: dataPointPath.hpp:73
const std::string & ToString() const noexcept
Get string representing the DataPointPath.
Definition: dataPointPath.hpp:423
A utility class used to lookup the Server Alias for a given Data Point Path.
Definition: serverAliasCache.hpp:30
void AddServerAlias(DataPointPath const &path, std::string const &alias)
Adds a new entry into the Cache.
Definition: serverAliasCache.hpp:45
void Clear()
Clears the Cache.
Definition: serverAliasCache.hpp:35
std::string GetServerAlias(DataPointPath const &path)
Get Server Alias for a specific datapoint.
Definition: serverAliasCache.hpp:56
Header file for DataPointPath.
Definition: commandReplier.cpp:22