Created
August 20, 2021 17:18
-
-
Save Loki-Astari/b4ef326d9f30e4fcab43a9c11fb75d6d to your computer and use it in GitHub Desktop.
Base Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Not sure I understand the statement. | |
The type `T` is used to somehow load the configuration in some way? | |
class UConfigurableBase | |
{ | |
public: | |
virtual json GetDefaultConfig() = 0; | |
bool Validate(const json& source ); | |
} | |
bool UConfigurable<T>::Validate( const json& source ) | |
{ | |
json patch = json::diff( source, this->GetDefaultConfig() ); | |
for( auto it = patch.begin(); it != patch.end(); ++it ) | |
{ | |
if( it->at("op") == "replace" ) | |
{ | |
if( not (it->at("value").is_null()) { | |
return false; | |
} | |
} | |
else { | |
return false; | |
} | |
} | |
return return true; | |
} | |
template <typename T> | |
class UConfigurable: public UConfigurableBase | |
{ | |
public : | |
UConfigurable() {}; | |
virtual ~UConfigurable() {}; | |
virtual void WriteConfig( const nlohmann::json &config ) = 0; | |
static json GetDefaultConfig() { return fDefaultConfig; } | |
}; | |
void WriteConfigToFile( const json& j, const std::string& path ); | |
json ReadConfigFromFile( const std::string& path ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment