Ocean
Ocean::IO::FileConfig Class Reference

This class implements an application or module configuration toolkit using files as input or output. More...

Inheritance diagram for Ocean::IO::FileConfig:

Data Structures

class  ConfigScanner
 This scanner is able to scan the specific config file type. More...
 
class  FileValue
 Definition of a file value object. More...
 

Public Member Functions

 FileConfig ()
 Creates a new config object. More...
 
 FileConfig (const std::string &filename, const bool read=true)
 Creates a new config object by a given configuration file. More...
 
const std::string & filename () const
 Returns the config file. More...
 
bool setFilename (const std::string &filename, const bool read=true)
 Sets the filename of the new config objects. More...
 
bool read () override
 Reads / loads all values of this configuration. More...
 
bool write () override
 Writes / saves all values of this configuration. More...
 
unsigned int values () const override
 Returns the number of sub values. More...
 
unsigned int values (const std::string &name) const override
 Returns the number of sub values with a given name. More...
 
bool exist (const std::string &name) const override
 Returns whether this value holds at least one specified sub value. More...
 
FileValuevalue (const unsigned int index, std::string &name) override
 Returns a sub value specified by it's index. More...
 
bool value (const unsigned int index, std::string &name, Value **value) override
 Returns a sub value specified by it's index. More...
 
FileValuevalue (const std::string &name, const unsigned int index) override
 Returns a sub value specified by it's name and it's index if more than one value exists with the same name. More...
 
bool value (const std::string &name, const unsigned int index, Value **value) override
 Returns a sub value specified by it's name and it's index if more than one value exists with the same name. More...
 
FileValueadd (const std::string &name) override
 Adds a new sub value specified by it's name. More...
 
FileValueoperator[] (const std::string &name) override
 Returns a sub value specified by it's name. More...
 
bool isEmpty () const
 Returns whether this file configuration container does not hold any values. More...
 
- Public Member Functions inherited from Ocean::Config
virtual ~Config ()
 Destructs a configuration toolkit. More...
 
Timestamp writeTimestamp () const
 Returns the timestamp of the last write execution. More...
 

Static Public Member Functions

static bool write (const FileValues &values, std::ostream &stream)
 Writes objects to a given output stream explicitly. More...
 

Protected Types

typedef std::multimap< std::string, FileValueFileValues
 Definition of a map mapping value names to value objects. More...
 

Protected Member Functions

bool readSubValues (FileValues &values, Scanner &scanner, bool stopWithBrackets)
 Reads sub values. More...
 
- Protected Member Functions inherited from Ocean::Config
 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 bool write (const FileValues &values, std::ostream &stream, unsigned int offset)
 Writes values to a stream with a given tab offset. More...
 
static bool writeTabs (std::ostream &stream, unsigned int offset)
 Writes a given number of tabs. More...
 
static FileValuenullValue ()
 Returns the default value holding no data. More...
 
- Static Protected Member Functions inherited from Ocean::Config
static ValuenullValue ()
 Returns the default value holding no data. More...
 

Protected Attributes

FileValues values_
 Roots objects. More...
 
std::string filename_
 Filename of this config object. More...
 
- Protected Attributes inherited from Ocean::Config
Timestamp writeTimestamp_
 Holds the timestamp of the most recent write execution. More...
 

Additional Inherited Members

- Public Types inherited from Ocean::Config
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...
 

Detailed Description

This class implements an application or module configuration toolkit using files as input or output.

Member Typedef Documentation

◆ FileValues

typedef std::multimap<std::string, FileValue> Ocean::IO::FileConfig::FileValues
protected

Definition of a map mapping value names to value objects.

Constructor & Destructor Documentation

◆ FileConfig() [1/2]

Ocean::IO::FileConfig::FileConfig ( )

Creates a new config object.

◆ FileConfig() [2/2]

Ocean::IO::FileConfig::FileConfig ( const std::string &  filename,
const bool  read = true 
)
explicit

Creates a new config object by a given configuration file.

Parameters
filenameConfiguration file
readTrue, to load the file directly

Member Function Documentation

◆ add()

FileValue& Ocean::IO::FileConfig::add ( const std::string &  name)
overridevirtual

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

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

Reimplemented from Ocean::Config.

◆ exist()

bool Ocean::IO::FileConfig::exist ( const std::string &  name) const
overridevirtual

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

See also
Config::exist().

Reimplemented from Ocean::Config.

◆ filename()

const std::string & Ocean::IO::FileConfig::filename ( ) const
inline

Returns the config file.

Returns
Config file

◆ isEmpty()

bool Ocean::IO::FileConfig::isEmpty ( ) const
inline

Returns whether this file configuration container does not hold any values.

Returns
True, if so

◆ nullValue()

static FileValue& Ocean::IO::FileConfig::nullValue ( )
staticprotected

Returns the default value holding no data.

Returns
The default value holding no data.

◆ operator[]()

FileValue& Ocean::IO::FileConfig::operator[] ( const std::string &  name)
overridevirtual

Returns a sub value specified by it's name.

See also
Config::operator[]().

Reimplemented from Ocean::Config.

◆ read()

bool Ocean::IO::FileConfig::read ( )
overridevirtual

Reads / loads all values of this configuration.

See also
Config::read().

Reimplemented from Ocean::Config.

◆ readSubValues()

bool Ocean::IO::FileConfig::readSubValues ( FileValues values,
Scanner scanner,
bool  stopWithBrackets 
)
protected

Reads sub values.

Parameters
valuesSub values to fill
scannerThe scanner used for token scanning
stopWithBracketsDetermines whether to stop at a closing bracket
Returns
True, if succeeded

◆ setFilename()

bool Ocean::IO::FileConfig::setFilename ( const std::string &  filename,
const bool  read = true 
)

Sets the filename of the new config objects.

All old config objects will be released before.

Parameters
filenameto set
readTrue, to load the file directly
Returns
True, if the file could be loaded

◆ value() [1/4]

FileValue& Ocean::IO::FileConfig::value ( const std::string &  name,
const unsigned int  index 
)
overridevirtual

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

See also
Config::value().

Reimplemented from Ocean::Config.

◆ value() [2/4]

bool Ocean::IO::FileConfig::value ( const std::string &  name,
const unsigned int  index,
Value **  value 
)
overridevirtual

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

See also
Config::value().

Reimplemented from Ocean::Config.

◆ value() [3/4]

FileValue& Ocean::IO::FileConfig::value ( const unsigned int  index,
std::string &  name 
)
overridevirtual

Returns a sub value specified by it's index.

See also
Config::value().

Reimplemented from Ocean::Config.

◆ value() [4/4]

bool Ocean::IO::FileConfig::value ( const unsigned int  index,
std::string &  name,
Value **  value 
)
overridevirtual

Returns a sub value specified by it's index.

See also
Config::value().

Reimplemented from Ocean::Config.

◆ values() [1/2]

unsigned int Ocean::IO::FileConfig::values ( ) const
overridevirtual

Returns the number of sub values.

See also
Config::values().

Reimplemented from Ocean::Config.

◆ values() [2/2]

unsigned int Ocean::IO::FileConfig::values ( const std::string &  name) const
overridevirtual

Returns the number of sub values with a given name.

See also
Config::values().

Reimplemented from Ocean::Config.

◆ write() [1/3]

bool Ocean::IO::FileConfig::write ( )
overridevirtual

Writes / saves all values of this configuration.

See also
Config::write().

Reimplemented from Ocean::Config.

◆ write() [2/3]

static bool Ocean::IO::FileConfig::write ( const FileValues values,
std::ostream &  stream 
)
static

Writes objects to a given output stream explicitly.

Parameters
valuesThe values to write
streamTarget stream
Returns
True, if succeeded

◆ write() [3/3]

static bool Ocean::IO::FileConfig::write ( const FileValues values,
std::ostream &  stream,
unsigned int  offset 
)
staticprotected

Writes values to a stream with a given tab offset.

Parameters
valuesThe values to write
streamTarget stream
offsetTab offset
Returns
True, if succeeded

◆ writeTabs()

static bool Ocean::IO::FileConfig::writeTabs ( std::ostream &  stream,
unsigned int  offset 
)
staticprotected

Writes a given number of tabs.

Parameters
streamTarget stream
offsetTab offset
Returns
True, if succeeded

Field Documentation

◆ filename_

std::string Ocean::IO::FileConfig::filename_
protected

Filename of this config object.

◆ values_

FileValues Ocean::IO::FileConfig::values_
protected

Roots objects.


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