mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2026-04-27 20:41:55 +00:00
Use a custom hash class to enable hetereogenous lookup
This commit is contained in:
parent
5e03b5ff0e
commit
594cdde05a
2 changed files with 11 additions and 10 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
// Use a custom hash class to enable hetereogenous lookup
|
||||||
struct string_hash {
|
struct string_hash {
|
||||||
using is_transparent = void;
|
using is_transparent = void;
|
||||||
[[nodiscard]] size_t operator()(const char *txt) const {
|
[[nodiscard]] size_t operator()(const char *txt) const {
|
||||||
|
|
@ -33,12 +34,12 @@ namespace recomp {
|
||||||
|
|
||||||
extern ConfigStore config_store;
|
extern ConfigStore config_store;
|
||||||
|
|
||||||
void set_config_store_value(std::string key, config_store_value value);
|
void set_config_store_value(std::string_view key, config_store_value value);
|
||||||
void set_config_store_default_value(std::string key, config_store_value value);
|
void set_config_store_default_value(std::string_view key, config_store_value value);
|
||||||
void set_config_store_value_and_default(std::string key, config_store_value value, config_store_value default_value);
|
void set_config_store_value_and_default(std::string_view key, config_store_value value, config_store_value default_value);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T get_config_store_default_value(std::string key) {
|
T get_config_store_default_value(std::string_view key) {
|
||||||
std::lock_guard lock{ config_store.default_store_mutex };
|
std::lock_guard lock{ config_store.default_store_mutex };
|
||||||
auto it = config_store.default_map.find(key);
|
auto it = config_store.default_map.find(key);
|
||||||
if (it != config_store.default_map.end()) {
|
if (it != config_store.default_map.end()) {
|
||||||
|
|
@ -54,7 +55,7 @@ namespace recomp {
|
||||||
|
|
||||||
// Get a value from the config store, if it doesn't exist then return the default value
|
// Get a value from the config store, if it doesn't exist then return the default value
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T get_config_store_value(std::string key) {
|
T get_config_store_value(std::string_view key) {
|
||||||
std::lock_guard lock{ config_store.store_mutex };
|
std::lock_guard lock{ config_store.store_mutex };
|
||||||
auto it = config_store.map.find(key);
|
auto it = config_store.map.find(key);
|
||||||
if (it != config_store.map.end()) {
|
if (it != config_store.map.end()) {
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@ namespace recomp {
|
||||||
|
|
||||||
ConfigStore config_store = {{}, {}};
|
ConfigStore config_store = {{}, {}};
|
||||||
|
|
||||||
void set_config_store_value(std::string key, config_store_value value) {
|
void set_config_store_value(std::string_view key, config_store_value value) {
|
||||||
std::lock_guard lock{ config_store.store_mutex };
|
std::lock_guard lock{ config_store.store_mutex };
|
||||||
config_store.map[key] = value;
|
config_store.map[std::string{key}] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_config_store_default_value(std::string key, config_store_value value) {
|
void set_config_store_default_value(std::string_view key, config_store_value value) {
|
||||||
std::lock_guard lock{ config_store.default_store_mutex };
|
std::lock_guard lock{ config_store.default_store_mutex };
|
||||||
config_store.default_map[key] = value;
|
config_store.default_map[std::string{key}] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_config_store_value_and_default(std::string key, config_store_value value, config_store_value default_value) {
|
void set_config_store_value_and_default(std::string_view key, config_store_value value, config_store_value default_value) {
|
||||||
set_config_store_value(key, value);
|
set_config_store_value(key, value);
|
||||||
set_config_store_default_value(key, default_value);
|
set_config_store_default_value(key, default_value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue