AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ConfigValueCache< ConfigEnum > Class Template Referenceabstract

#include "ConfigValueCache.h"

Public Types

enum class  Reloadable : bool {
  No = false ,
  Yes = true
}
 

Public Member Functions

 ConfigValueCache (ConfigEnum const configCount)
 
void Initialize (bool reload)
 
template<class T >
void SetConfigValue (ConfigEnum const config, std::string const &configName, T const &defaultValue, Reloadable reloadable=Reloadable::Yes, std::function< bool(T const &value)> &&checker={}, std::string const &validationErrorText="")
 
template<class T >
void OverwriteConfigValue (ConfigEnum const config, T const &value)
 
template<class T >
GetConfigValue (ConfigEnum const config) const
 
std::string_view GetConfigValue (ConfigEnum const config) const
 

Protected Member Functions

virtual void BuildConfigCache ()=0
 

Private Member Functions

void VerifyAllConfigsLoaded ()
 

Private Attributes

std::vector< std::variant< std::monostate, float, bool, uint32, std::string > > _configs
 
bool _reloading
 

Detailed Description

template<typename ConfigEnum>
class ConfigValueCache< ConfigEnum >

Member Enumeration Documentation

◆ Reloadable

template<typename ConfigEnum >
enum class ConfigValueCache::Reloadable : bool
strong
Enumerator
No 
Yes 
34 {
35 No = false,
36 Yes = true
37 };

Constructor & Destructor Documentation

◆ ConfigValueCache()

template<typename ConfigEnum >
ConfigValueCache< ConfigEnum >::ConfigValueCache ( ConfigEnum const  configCount)
inline
40 {
41 _configs.resize(static_cast<uint32>(configCount));
42 _reloading = false;
43 }
std::uint32_t uint32
Definition Define.h:107
bool _reloading
Definition ConfigValueCache.h:142
std::vector< std::variant< std::monostate, float, bool, uint32, std::string > > _configs
Definition ConfigValueCache.h:141

References ConfigValueCache< ConfigEnum >::_configs, and ConfigValueCache< ConfigEnum >::_reloading.

Member Function Documentation

◆ BuildConfigCache()

template<typename ConfigEnum >
virtual void ConfigValueCache< ConfigEnum >::BuildConfigCache ( )
protectedpure virtual

◆ GetConfigValue() [1/2]

template<typename ConfigEnum >
template<class T >
T ConfigValueCache< ConfigEnum >::GetConfigValue ( ConfigEnum const  config) const
inline
98 {
99 uint32 const configIndex = static_cast<uint32>(config);
100 ASSERT(configIndex < _configs.size(), "Config index out of bounds");
101 ASSERT(_configs[configIndex].index() != 0, "Config value must already be set");
102
103 T const* value = std::get_if<T>(&_configs[configIndex]);
104 ASSERT(value, "Wrong config variant type");
105
106 return *value;
107 }
#define ASSERT
Definition Errors.h:68

References ConfigValueCache< ConfigEnum >::_configs, and ASSERT.

Referenced by World::getBoolConfig(), World::getFloatConfig(), World::getIntConfig(), and World::getStringConfig().

◆ GetConfigValue() [2/2]

template<typename ConfigEnum >
std::string_view ConfigValueCache< ConfigEnum >::GetConfigValue ( ConfigEnum const  config) const
inline
111 {
112 uint32 const configIndex = static_cast<uint32>(config);
113 ASSERT(configIndex < _configs.size(), "Config index out of bounds");
114 ASSERT(_configs[configIndex].index() != 0, "Config value must already be set");
115
116 std::string const* stringValue = std::get_if<std::string>(&_configs[configIndex]);
117 ASSERT(stringValue, "Wrong config variant type");
118
119 return std::string_view(*stringValue);
120 }

References ConfigValueCache< ConfigEnum >::_configs, and ASSERT.

◆ Initialize()

template<typename ConfigEnum >
void ConfigValueCache< ConfigEnum >::Initialize ( bool  reload)
inline

◆ OverwriteConfigValue()

template<typename ConfigEnum >
template<class T >
void ConfigValueCache< ConfigEnum >::OverwriteConfigValue ( ConfigEnum const  config,
T const &  value 
)
inline
87 {
88 uint32 const configIndex = static_cast<uint32>(config);
89 ASSERT(configIndex < _configs.size(), "Config index out of bounds");
90 size_t const oldValueTypeIndex = _configs[configIndex].index();
91 ASSERT(oldValueTypeIndex != 0, "Config value must already be set");
92 _configs[configIndex] = value;
93 ASSERT(oldValueTypeIndex == _configs[configIndex].index(), "Config value type changed");
94 }

References ConfigValueCache< ConfigEnum >::_configs, and ASSERT.

Referenced by World::LoadConfigSettings(), World::setBoolConfig(), World::setFloatConfig(), World::setIntConfig(), and World::setStringConfig().

◆ SetConfigValue()

template<typename ConfigEnum >
template<class T >
void ConfigValueCache< ConfigEnum >::SetConfigValue ( ConfigEnum const  config,
std::string const &  configName,
T const &  defaultValue,
Reloadable  reloadable = Reloadable::Yes,
std::function< bool(T const &value)> &&  checker = {},
std::string const &  validationErrorText = "" 
)
inline
54 {}, std::string const& validationErrorText = "")
55 {
56 uint32 const configIndex = static_cast<uint32>(config);
57 ASSERT(configIndex < _configs.size(), "Config index out of bounds");
58 T const& configValue = sConfigMgr->GetOption<T>(configName, defaultValue);
59
60 bool configValueChanged = false;
61 if (_reloading)
62 {
63 if (std::get<T>(_configs[configIndex]) != configValue)
64 configValueChanged = true;
65
66 if (reloadable == Reloadable::No)
67 {
68 if (configValueChanged)
69 LOG_ERROR("server.loading", "Server Config (Name: {}) cannot be changed by reload. A server restart is required to update this config value.", configName);
70 return;
71 }
72 }
73 else
74 ASSERT(_configs[configIndex].index() == 0, "Config overwriting an existing value");
75
76 if (checker && !checker(configValue))
77 {
78 LOG_ERROR("server.loading", "Server Config (Name: {}) failed validation check '{}'. Default value '{}' will be used instead.", configName, validationErrorText, defaultValue);
79 _configs[configIndex] = defaultValue;
80 }
81 else
82 _configs[configIndex] = configValue;
83 }
#define sConfigMgr
Definition Config.h:74
#define LOG_ERROR(filterType__,...)
Definition Log.h:157

◆ VerifyAllConfigsLoaded()

template<typename ConfigEnum >
void ConfigValueCache< ConfigEnum >::VerifyAllConfigsLoaded ( )
inlineprivate
127 {
128 uint32 configIndex = 0;
129 for (auto const& variant : _configs)
130 {
131 if (variant.index() == 0)
132 {
133 LOG_ERROR("server.loading", "Server Config (Index: {}) is defined but not loaded, unable to continue.", configIndex);
134 ASSERT(false);
135 }
136
137 ++configIndex;
138 }
139 }

References ConfigValueCache< ConfigEnum >::_configs, ASSERT, and LOG_ERROR.

Referenced by ConfigValueCache< ConfigEnum >::Initialize().

Member Data Documentation

◆ _configs

template<typename ConfigEnum >
std::vector<std::variant<std::monostate, float, bool, uint32, std::string> > ConfigValueCache< ConfigEnum >::_configs
private

◆ _reloading

template<typename ConfigEnum >
bool ConfigValueCache< ConfigEnum >::_reloading
private

The documentation for this class was generated from the following file: