Jopnal Engine  alpha 0.4
Simple Component Based 2D/3D Game Engine
Public Types | Public Member Functions | Static Public Member Functions | List of all members
jop::SettingManager Class Referencefinal

#include <SettingManager.hpp>

Inheritance diagram for jop::SettingManager:
jop::Subsystem

Public Types

typedef std::unordered_multimap< std::string, detail::SettingCallbackBase * > UpdaterMap
 
typedef std::unordered_map< std::string, std::pair< json::Document, bool > > SettingMap
 

Public Member Functions

 SettingManager ()
 Default constructor. More...
 
 ~SettingManager () override
 Destructor. More...
 
void preUpdate (const float deltaTime) override
 Update function. More...
 
- Public Member Functions inherited from jop::Subsystem
 Subsystem (const uint32 ID)
 Constructor. More...
 
virtual ~Subsystem ()=0
 Virtual destructor. More...
 
virtual void postUpdate (const float deltaTime)
 Post-update. More...
 
virtual void draw ()
 Draw. More...
 
Message::Result sendMessage (const Message &message)
 Function to handle messages. More...
 
SubsystemsetActive (const bool active)
 Set this sub system active. More...
 
bool isActive () const
 Check if this sub system is active. More...
 
uint32 getID () const
 Get the ID. More...
 

Static Public Member Functions

static bool settingExists (const std::string &path)
 Check if a certain setting exists. More...
 
template<typename T >
static T get (const std::string &path, const T &defaultValue)
 Get a setting value. More...
 
template<typename T >
static T set (const std::string &path, const T &value)
 Set a setting value. More...
 
static unsigned int registerCallback (const std::string &path, detail::SettingCallbackBase &callback)
 Register a setting change callback. More...
 
static void reload ()
 Reload the settings from file. More...
 
static void save ()
 Save the settings to file. More...
 
static void setDefaultDirectory (const std::string &directory)
 Set a directory with any default setting files. More...
 
static void setOverrideWithDefaults ()
 Override existing settings with the defaults. More...
 

Additional Inherited Members

- Protected Member Functions inherited from jop::Subsystem
virtual Message::Result receiveMessage (const Message &message)
 Receive a message. More...
 

Detailed Description

Definition at line 42 of file SettingManager.hpp.

Member Typedef Documentation

typedef std::unordered_map<std::string, std::pair<json::Document, bool> > jop::SettingManager::SettingMap

Definition at line 47 of file SettingManager.hpp.

typedef std::unordered_multimap<std::string, detail::SettingCallbackBase*> jop::SettingManager::UpdaterMap

Definition at line 46 of file SettingManager.hpp.

Constructor & Destructor Documentation

jop::SettingManager::SettingManager ( )

Default constructor.

Loads all the existing settings from file.

jop::SettingManager::~SettingManager ( )
override

Destructor.

Saves the settings to file.

Member Function Documentation

template<typename T >
static T jop::SettingManager::get ( const std::string &  path,
const T &  defaultValue 
)
static

Get a setting value.

The entry will be created if it doesn't exist.

Example of a correctly formatted setting path: "engine@Path|To|Setting|actualSetting"

The first section "engine", specifies the setting file. The .json extension will be added automatically. The file may be in a nested folder, but it must be specified using a forward slash (/). You may also leave the file part out, in which case the default file will be used ("root.json" by default).

After the file specification, comes the actual setting path. Nodes are separated with "|" after which comes the actual setting name. This example would produce the following setting file:

{
"Path": {
"To": {
"Setting": {
"actualSetting": value
}
}
}
}
Parameters
pathThe setting path
defaultValueThe default value, this will be used if the entry doesn't exist
Returns
The setting value
void jop::SettingManager::preUpdate ( const float  deltaTime)
overridevirtual

Update function.

Whenever any setting changes occur via file modification, the change callbacks will be called by this function in a synchronized manner.

This never does anything if automatic setting updates have been turned off.

Parameters
deltaTimeThe delta time, not used

Reimplemented from jop::Subsystem.

static unsigned int jop::SettingManager::registerCallback ( const std::string &  path,
detail::SettingCallbackBase &  callback 
)
static

Register a setting change callback.

The callback will be invoked when you change a corresponding setting using set() or modify the setting file. The new value has to differ from the old one, or the invocation won't happen.

You are responsible for ensuring that the callback stays alive as long as it's meant to be used. You won't need to explicitly unbind it. The callback will be unbound during its destruction.

Parameters
pathThe setting path to associate the callback with
callbackReference to a callback object
Returns
The number of callbacks that exist for the same setting, includes the one being registered
static void jop::SettingManager::reload ( )
static

Reload the settings from file.

Avoid calling this function. It will replace all current settings with those found in the files, discarding all unsaved changes. It will also invoke all registered change callbacks, even when the value hadn't changed.

See also
set()
registerCallback()
static void jop::SettingManager::save ( )
static

Save the settings to file.

template<typename T >
static T jop::SettingManager::set ( const std::string &  path,
const T &  value 
)
static

Set a setting value.

The entry will be created if it doesn't exist.

The value will be updated only if it differs from the existing one, as is the requirement for invoking any corresponding callbacks.

Parameters
pathThe setting path
valueThe value to set
Returns
The same value as 'value'
static void jop::SettingManager::setDefaultDirectory ( const std::string &  directory)
static

Set a directory with any default setting files.

If set before engine initialization, the directory will be used to look for existing setting files, meant to contain custom default values. Call this if you need an initial configuration different from the engine's default.

Parameters
directoryThe setting file directory, relative to the Resources folder
See also
setOverrideWithDefaults()
static void jop::SettingManager::setOverrideWithDefaults ( )
static

Override existing settings with the defaults.

If setDefaultDirectory() hasn't been called, this function is no-op.

Calling this function after setting the default setting directory will cause any pre-existing settings found in the user folder to be replaced with the defaults. This function is meant for debugging purposes mainly.

static bool jop::SettingManager::settingExists ( const std::string &  path)
static

Check if a certain setting exists.

Parameters
pathThe setting path
Returns
True if the setting exists

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