libcrn  3.9.5
A document image processing library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
crn::ConfigurationFile Class Reference

Configuration file management utility class. More...

#include <CRNConfigurationFile.h>

Public Member Functions

 ConfigurationFile (const String &application_name, const StringUTF8 &file_name="", ConfigurationType ctype=ConfigurationType::APP)
 Constructor. More...
 
 ConfigurationFile (const ConfigurationFile &)=delete
 
 ConfigurationFile (ConfigurationFile &&)=default
 
ConfigurationFileoperator= (const ConfigurationFile &)=delete
 
ConfigurationFileoperator= (ConfigurationFile &&)=default
 
Path Load ()
 Loads the file. More...
 
Path Save ()
 Saves the file to the user's personal space. More...
 
SObject & operator[] (const String &key)
 Gets a value. More...
 
SObject GetData (const String &key)
 Gets a value. More...
 
SCObject GetData (const String &key) const
 Gets a value. More...
 
Path GetPath (const String &key) const
 Gets a path. More...
 
String GetString (const String &key) const
 Gets a string. More...
 
StringUTF8 GetStringUTF8 (const String &key) const
 Gets a UTF8 string. More...
 
Prop3 GetProp3 (const String &key) const
 Gets a Prop3. More...
 
int GetInt (const String &key) const
 Gets an int. More...
 
double GetDouble (const String &key) const
 Gets a double. More...
 
template<typename T >
void SetData (const String &key, T value)
 Sets a key/value pair. More...
 
Path GetUserDirectory () const
 Returns the path to the user configuration directory. More...
 

Detailed Description

Configuration file management utility class.

Configuration file management utility class

Author
Yann LEYDIER
Version
0.1
Date
Dec 2010

Definition at line 43 of file CRNConfigurationFile.h.

Constructor & Destructor Documentation

ConfigurationFile::ConfigurationFile ( const String application_name,
const StringUTF8 file_name = "",
ConfigurationType  ctype = ConfigurationType::APP 
)

Constructor.

Constructor

Parameters
[in]application_namethe name of the application
[in]file_namethe name of the configuration file. If empty, the application name is used

Definition at line 43 of file CRNConfigurationFile.cpp.

crn::ConfigurationFile::ConfigurationFile ( const ConfigurationFile )
delete
crn::ConfigurationFile::ConfigurationFile ( ConfigurationFile &&  )
default

Member Function Documentation

SObject ConfigurationFile::GetData ( const String key)

Gets a value.

Gets a value

Parameters
[in]keythe key of the value to get
Returns
a pointer to the value or nullptr if not found

Definition at line 136 of file CRNConfigurationFile.cpp.

SCObject ConfigurationFile::GetData ( const String key) const

Gets a value.

Gets a value

Parameters
[in]keythe key of the value to get
Returns
a pointer to the value or nullptr if not found

Definition at line 149 of file CRNConfigurationFile.cpp.

double ConfigurationFile::GetDouble ( const String key) const

Gets a double.

Gets a double

Exceptions
ExceptionInvalidArgumentkey does not point to a double
Parameters
[in]keythe key of the value to get
Returns
a double or ExceptionUninitialized if not found or value is of wrong type

Definition at line 237 of file CRNConfigurationFile.cpp.

int ConfigurationFile::GetInt ( const String key) const

Gets an int.

Gets an int

Exceptions
ExceptionInvalidArgumentkey does not point to an int
Parameters
[in]keythe key of the value to get
Returns
an int or ExceptionUninitialized if not found or value is of wrong type

Definition at line 224 of file CRNConfigurationFile.cpp.

Path ConfigurationFile::GetPath ( const String key) const

Gets a path.

Gets a path

Exceptions
ExceptionInvalidArgumentkey does not point to a Path
Parameters
[in]keythe key of the value to get
Returns
a path or ExceptionUninitialized if not found or value is of wrong type

Definition at line 163 of file CRNConfigurationFile.cpp.

Prop3 ConfigurationFile::GetProp3 ( const String key) const

Gets a Prop3.

Gets a Prop3

Exceptions
ExceptionInvalidArgumentkey does not point to a Prop3
Parameters
[in]keythe key of the value to get
Returns
a Prop3 or ExceptionUninitialized if not found or value is of wrong type

Definition at line 211 of file CRNConfigurationFile.cpp.

String ConfigurationFile::GetString ( const String key) const

Gets a string.

Gets a string

Exceptions
ExceptionInvalidArgumentkey does not point to a String
Parameters
[in]keythe key of the value to get
Returns
a string or ExceptionUninitialized if not found or value is of wrong type

Definition at line 185 of file CRNConfigurationFile.cpp.

StringUTF8 ConfigurationFile::GetStringUTF8 ( const String key) const

Gets a UTF8 string.

Gets a utf8 string

Exceptions
ExceptionInvalidArgumentkey does not point to a StringUTF8
Parameters
[in]keythe key of the value to get
Returns
a utf8 string or ExceptionUninitialized if not found or value is of wrong type

Definition at line 198 of file CRNConfigurationFile.cpp.

Path ConfigurationFile::GetUserDirectory ( ) const

Returns the path to the user configuration directory.

Returns the path to the user configuration directory

Returns
APPDATA%<appname> on Windows, $HOME/.config/<appname> else

Definition at line 248 of file CRNConfigurationFile.cpp.

Path ConfigurationFile::Load ( )

Loads the file.

Loads the file from the following places

  • current directory
  • personal config directory (unix: $HOME/.config, win: APPDATA%)
  • system config directory (unix: /etc, win: COMMONPROGRAMFILES%\crn)
    Returns
    the full path to the loaded file or an empty string if no file was found

Definition at line 58 of file CRNConfigurationFile.cpp.

ConfigurationFile& crn::ConfigurationFile::operator= ( const ConfigurationFile )
delete
ConfigurationFile& crn::ConfigurationFile::operator= ( ConfigurationFile &&  )
default
SObject & ConfigurationFile::operator[] ( const String key)

Gets a value.

Gets a value. If the key does not exist, creates a key/value pair.

Parameters
[in]keythe key of the value to get
Returns
a reference to the pointer to the value

Definition at line 127 of file CRNConfigurationFile.cpp.

Path ConfigurationFile::Save ( )

Saves the file to the user's personal space.

Saves the file to the user's personal space (unix: $HOME/.config, win: APPDATA%)

Returns
the full path to the written file or an empty string if no file could not be saved

Definition at line 104 of file CRNConfigurationFile.cpp.

template<typename T >
void crn::ConfigurationFile::SetData ( const String key,
value 
)
inline

Sets a key/value pair.

Exceptions
ExceptionProtocolvalue is not serializable

Definition at line 79 of file CRNConfigurationFile.h.


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