Ocean
Ocean::Config Class Reference

This class implements an application or module configuration toolkit. More...

Inheritance diagram for Ocean::Config:

Data Structures

class  Value
 This class implements a configuration value. More...
 

Public Types

enum  ValueType {
  TYPE_INVALID , TYPE_UNDEFINED , TYPE_BOOL , TYPE_INT ,
  TYPE_NUMBER , TYPE_STRING , TYPE_MULTI_BOOL , TYPE_MULTI_INT ,
  TYPE_MULTI_NUMBER , TYPE_MULTI_STRING , TYPE_GROUP
}
 Definition of different value types. More...
 

Public Member Functions

virtual ~Config ()
 Destructs a configuration toolkit. More...
 
virtual bool read ()
 Reads / loads all values of this configuration. More...
 
virtual bool write ()
 Writes / saves all values of this configuration. More...
 
Timestamp writeTimestamp () const
 Returns the timestamp of the last write execution. More...
 
virtual unsigned int values () const
 Returns the number of sub values. More...
 
virtual unsigned int values (const std::string &name) const
 Returns the number of sub values with a given name. More...
 
virtual bool exist (const std::string &name) const
 Returns whether this value holds at least one specified sub value. More...
 
virtual Valuevalue (const unsigned int index, std::string &name)
 Returns a sub value specified by it's index. More...
 
virtual bool value (const unsigned int index, std::string &name, Value **value)
 Returns a sub value specified by it's index. More...
 
virtual bool value (const std::string &name, const unsigned int index, Value **value)
 Returns a sub value specified by it's name and it's index if more than one value exists with the same name. More...
 
virtual Valuevalue (const std::string &name, const unsigned int index=0)
 Returns a sub value specified by it's name and it's index if more than one value exists with the same name. More...
 
virtual Valueadd (const std::string &name)
 Adds a new sub value specified by it's name. More...
 
virtual Valueoperator[] (const std::string &name)
 Returns the first sub value specified by it's name or creates a new one if not existing. More...
 

Protected Member Functions

 Config ()
 Creates a new configuration toolkit. More...
 
 Config (const Config &config)=delete
 Disabled copy constructor. More...
 
Configoperator= (const Config &config)=delete
 Disabled copy operator. More...
 

Static Protected Member Functions

static ValuenullValue ()
 Returns the default value holding no data. More...
 

Protected Attributes

Timestamp writeTimestamp_
 Holds the timestamp of the most recent write execution. More...
 

Detailed Description

This class implements an application or module configuration toolkit.

Each configuration toolkit holds a value tree.
Different single value types are supported like e.g. boolean, integer or strings.
Furthermore, groups can be specified holding an arbitrary number of sub values.
Values names does not need to be unique. Therefore, a group can hold several sub values with the same name.
Also, values with the same name can have different value types.
However, this is an abstract configuration object and therefore should be used as platform independent interface only.
Use e.g. file configuration or a registry configuration object instead. The entire object is not thread-safe.

Member Enumeration Documentation

◆ ValueType

Definition of different value types.

Enumerator
TYPE_INVALID 

Invalid value type.

TYPE_UNDEFINED 

Undefined value type.

TYPE_BOOL 

Boolean value type.

TYPE_INT 

Integer value type.

TYPE_NUMBER 

Number value type.

TYPE_STRING 

String value type.

TYPE_MULTI_BOOL 

Multi boolean value type.

TYPE_MULTI_INT 

Multi integer value type.

TYPE_MULTI_NUMBER 

Multi number value type.

TYPE_MULTI_STRING 

Multi string value type.

TYPE_GROUP 

Group value type.

Constructor & Destructor Documentation

◆ ~Config()

virtual Ocean::Config::~Config ( )
virtual

Destructs a configuration toolkit.

◆ Config() [1/2]

Ocean::Config::Config ( )
protected

Creates a new configuration toolkit.

◆ Config() [2/2]

Ocean::Config::Config ( const Config config)
protecteddelete

Disabled copy constructor.

Parameters
configObject which would be copied

Member Function Documentation

◆ add()

virtual Value& Ocean::Config::add ( const std::string &  name)
virtual

Adds a new sub value specified by it's name.

Parameters
nameThe name of the sub value to create
Returns
New sub value

Reimplemented in Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ exist()

virtual bool Ocean::Config::exist ( const std::string &  name) const
virtual

Returns whether this value holds at least one specified sub value.

Parameters
nameThe name of the sub value to check
Returns
True, if so

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ nullValue()

static Value& Ocean::Config::nullValue ( )
staticprotected

Returns the default value holding no data.

Note
This function is not virtual by intention. Derived classes are supposed to override it and have it return their derived value type.
Returns
The default value holding no data.

◆ operator=()

Config& Ocean::Config::operator= ( const Config config)
protecteddelete

Disabled copy operator.

Parameters
configObject which would be copied
Returns
Reference to this object

◆ operator[]()

virtual Value& Ocean::Config::operator[] ( const std::string &  name)
virtual

Returns the first sub value specified by it's name or creates a new one if not existing.

Parameters
nameThe name of the sub value to return
Returns
Specified sub value

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ read()

virtual bool Ocean::Config::read ( )
virtual

Reads / loads all values of this configuration.

Returns
True, if succeeded

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ value() [1/4]

virtual bool Ocean::Config::value ( const std::string &  name,
const unsigned int  index,
Value **  value 
)
virtual

Returns a sub value specified by it's name and it's index if more than one value exists with the same name.

Parameters
nameThe name of the value to return
indexThe index within those sub values with the specified name
valueResulting sub value
Returns
True, if the value exists

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ value() [2/4]

virtual Value& Ocean::Config::value ( const std::string &  name,
const unsigned int  index = 0 
)
virtual

Returns a sub value specified by it's name and it's index if more than one value exists with the same name.

Parameters
nameThe name of the value to return
indexThe index within those sub values with the specified name
Returns
Sub value

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ value() [3/4]

virtual Value& Ocean::Config::value ( const unsigned int  index,
std::string &  name 
)
virtual

Returns a sub value specified by it's index.

Parameters
indexThe index of the sub value to return
nameResulting name of the returning value
Returns
Sub value

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ value() [4/4]

virtual bool Ocean::Config::value ( const unsigned int  index,
std::string &  name,
Value **  value 
)
virtual

Returns a sub value specified by it's index.

Parameters
indexThe index of the sub value to return
nameResulting name of the returning value
valueResulting sub value
Returns
True, if the value exists

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ values() [1/2]

virtual unsigned int Ocean::Config::values ( ) const
virtual

Returns the number of sub values.

Returns
Sub value number

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ values() [2/2]

virtual unsigned int Ocean::Config::values ( const std::string &  name) const
virtual

Returns the number of sub values with a given name.

Parameters
nameThe name of the sub values to return
Returns
Sub value number

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ write()

virtual bool Ocean::Config::write ( )
virtual

Writes / saves all values of this configuration.

Returns
True, if succeeded

Reimplemented in Ocean::Platform::Win::RegistryConfig, Ocean::IO::XMLConfig, Ocean::IO::JSONConfig, and Ocean::IO::FileConfig.

◆ writeTimestamp()

Timestamp Ocean::Config::writeTimestamp ( ) const
inline

Returns the timestamp of the last write execution.

Returns
Most recent write timestamp

Field Documentation

◆ writeTimestamp_

Timestamp Ocean::Config::writeTimestamp_
protected

Holds the timestamp of the most recent write execution.


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