SysConf: Make use of std::string_view

We can allow strings to be used with the SysConf interface in
potentially non-allocating manners.
This commit is contained in:
Lioncash committed 2020-12-29 19:08:25 -05:00
1 parent 3b2e31230f
commit 74224c94a7
2 files changed
+12 -11

No files matched your search

+7 -6
View File
@@ -9,6 +9,7 @@
#include <cstring>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include "Common/Assert.h"
@@ -75,20 +76,20 @@ public:
};
void AddEntry(Entry&& entry);
Entry* GetEntry(const std::string& key);
const Entry* GetEntry(const std::string& key) const;
Entry* GetOrAddEntry(const std::string& key, Entry::Type type);
void RemoveEntry(const std::string& key);
Entry* GetEntry(std::string_view key);
const Entry* GetEntry(std::string_view key) const;
Entry* GetOrAddEntry(std::string_view key, Entry::Type type);
void RemoveEntry(std::string_view key);
// Intended for use with the non array types.
template <typename T>
T GetData(const std::string& key, T default_value) const
T GetData(std::string_view key, T default_value) const
{
const Entry* entry = GetEntry(key);
return entry ? entry->GetData(default_value) : default_value;
}
template <typename T>
void SetData(const std::string& key, Entry::Type type, T value)
void SetData(std::string_view key, Entry::Type type, T value)
{
GetOrAddEntry(key, type)->SetData(value);
}