Skip to content

Instantly share code, notes, and snippets.

@Loki-Astari
Created August 20, 2021 17:18
Show Gist options
  • Save Loki-Astari/b4ef326d9f30e4fcab43a9c11fb75d6d to your computer and use it in GitHub Desktop.
Save Loki-Astari/b4ef326d9f30e4fcab43a9c11fb75d6d to your computer and use it in GitHub Desktop.
Base Config
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