neoWidgets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
neo::Config Class Referenceabstract

Interface for all configuration classes. More...

#include <Config.h>

Inheritance diagram for neo::Config:
Inheritance graph
[legend]

Public Member Functions

bool Read (const tstring &key, tstring &result) const
 Basic read function.
 
template<typename T >
bool Read (const tstring &key, T &result) const
 Extendable version of Read. More...
 
virtual bool Remove (const tstring &key)
 Remove a single value.
 
virtual bool RemoveEntireConfig ()
 Removes all values in the config, but the config can still used afterwards.
 
void RestoreWindowPosition (const tstring &key, HWND window)
 Convenience function for window position.
 
void SaveWindowPosition (const tstring &key, HWND window)
 Convenience function for window position.
 
bool Write (const tstring &key, const tstring &value)
 Basic write function.
 
template<typename T >
bool Write (const tstring &key, const T &value)
 Extendable version of Write. More...
 

Protected Member Functions

virtual bool _GetStringImp (const tstring &key, tstring &result) const =0
 Every config value is internally saved as a string.
 
virtual bool _SetStringImp (const tstring &key, const tstring &value)=0
 Every config value is internally saved as a string.
 

Static Protected Member Functions

static tstring FromUtf8 (const std::string &text)
 All config should be saved as UTF-8 for portability.
 
static std::string ToUtf8 (const tstring &text)
 All config should be saved as UTF-8 for portability.
 

Detailed Description

Interface for all configuration classes.

Some convenience methods are provided for the most common types. If a new data type should be saved, convert it to string. The convenience methods use this approach as well.

Member Function Documentation

template<typename T >
bool neo::Config::Read ( const tstring &  key,
T &  result 
) const
inline

Extendable version of Read.

This function is templated make it possible to support any type. To do that, declare the following function:

bool configStructRead(Config& conf, const tstring& key, CUSTOMTYPE& value)
{
// read value from conf
}

Then the custom type can be read as if the config natively supported it:

CustomType value;
conf.Read(L"saved value", value);
Note
Some overloads are already provided by the neo, including:
  • all integer, unsigned and float types up to the C++11 standard
  • bool
  • Point
  • Size
  • Rect
  • std::vector
template<typename T >
bool neo::Config::Write ( const tstring &  key,
const T &  value 
)
inline

Extendable version of Write.

This function is templated make it possible to support any type. To do that, declare the following function:

bool configStructWrite(Config& conf, const tstring& key, const CUSTOMTYPE& value)
{
// write value into conf
}

Then the custom type can be written as if the config natively supported it:

CustomType value;
conf.Write(L"saved value", value);
Note
Some overloads are already provided by the neo, including:
  • all integer, unsigned and float types up to the C++11 standard
  • bool
  • Point
  • Size
  • Rect
  • std::vector

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