Yate: Configuration Class Reference

Yate

Public Member Functions | Friends | List of all members
Configuration Class Reference

Configuration file handling. More...

`#include <yatengine.h>`

Inheritance diagram for Configuration:

## Public Member Functions
| Configuration ()
| Configuration (const char *filename, bool warn=true)
Configuration & | operator= (const String &value)
unsigned int | sections () const
unsigned int | count () const
NamedList * | getSection (unsigned int index) const
NamedList * | getSection (const String &sect) const
NamedString * | getKey (const String &sect, const String &key) const
const char * | getValue (const String &sect, const String &key, const char *defvalue=0) const
int | getIntValue (const String &sect, const String &key, int defvalue=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
int | getIntValue (const String &sect, const String &key, const TokenDict *tokens, int defvalue=0) const
int64_t | getInt64Value (const String &sect, const String &key, int64_t defvalue=0, int64_t minvalue=LLONG_MIN, int64_t maxvalue=LLONG_MAX, bool clamp=true) const
double | getDoubleValue (const String &sect, const String &key, double defvalue=0.0) const
bool | getBoolValue (const String &sect, const String &key, bool defvalue=false) const
void | clearSection (const char *sect=0)
NamedList * | createSection (const String &sect)
void | clearKey (const String &sect, const String &key)
void | addValue (const String &sect, const char *key, const char *value=0)
void | setValue (const String &sect, const char *key, const char *value=0)
void | setValue (const String &sect, const char *key, int value)
void | setValue (const String &sect, const char *key, bool value)
bool | load (bool warn=true)
bool | save () const
Public Member Functions inherited from String
| String ()
| String (const char *value, int len=-1)
| String (char value, unsigned int repeat=1)
| String (int32_t value)
| String (uint32_t value)
| String (int64_t value)
| String (uint64_t value)
| String (bool value)
| String (double value)
| String (const String &value)
| String (const String *value)
virtual | ~String ()
virtual void * | getObject (const String &name) const
const char * | c_str () const
const char * | safe () const
const char * | safe (const char *defStr) const
unsigned int | length () const
bool | null () const
int | lenUtf8 (uint32_t maxChar=0x10ffff, bool overlong=false) const
int | fixUtf8 (const char *replace=0, uint32_t maxChar=0x10ffff, bool overlong=false)
unsigned int | encodeFlags (const TokenDict *tokens) const
uint64_t | encodeFlags (const TokenDict64 *tokens) const
String & | decodeFlags (unsigned int flags, const TokenDict *tokens, bool unknownflag=true)
String & | decodeFlags (uint64_t flags, const TokenDict64 *tokens, bool unknownflag=true)
bool | checkBOM () const
bool | stripBOM ()
unsigned int | hash () const
void | clear ()
char | at (int index) const
String | substr (int offs, int len=-1) const
String & | trimBlanks ()
String & | trimSpaces ()
virtual const String & | toString () const
int | toInteger (int defvalue=0, int base=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
int | toInteger (const TokenDict *tokens, int defvalue=0, int base=0) const
int | toInteger (const TokenDictStr *tokens, int defvalue=0, int base=0) const
long int | toLong (long int defvalue=0, int base=0, long int minvalue=LONG_MIN, long int maxvalue=LONG_MAX, bool clamp=true) const
int64_t | toInt64 (int64_t defvalue=0, int base=0, int64_t minvalue=LLONG_MIN, int64_t maxvalue=LLONG_MAX, bool clamp=true) const
int64_t | toInt64Dict (const TokenDict64 *tokens, int64_t defvalue=0, int base=0) const
int64_t | toInt64Dict (const TokenDictStr64 *tokens, int64_t defvalue=0, int base=0) const
uint64_t | toUInt64 (uint64_t defvalue=0, int base=0, uint64_t minvalue=0, uint64_t maxvalue=ULLONG_MAX, bool clamp=true) const
double | toDouble (double defvalue=0.0) const
bool | toBoolean (bool defvalue=false) const
bool | isBoolean () const
String & | toUpper ()
String & | toLower ()
char | operator[] (signed int index) const
char | operator[] (unsigned int index) const
| operator const char * () const
String & | assign (const char *value, int len=-1)
String & | assign (char value, unsigned int repeat=1)
String & | hexify (const void *data, unsigned int len, char sep=0, bool upCase=false)
String & | operator= (const String &value)
String & | operator= (const String *value)
String & | operator= (const char *value)
String & | operator= (char value)
String & | operator= (int32_t value)
String & | operator= (uint32_t value)
String & | operator= (int64_t value)
String & | operator= (uint64_t value)
String & | operator= (bool value)
String & | operator= (double value)
String & | operator+= (const char *value)
String & | operator+= (char value)
String & | operator+= (int32_t value)
String & | operator+= (uint32_t value)
String & | operator+= (int64_t value)
String & | operator+= (uint64_t value)
String & | operator+= (bool value)
String & | operator+= (double value)
bool | operator== (const char *value) const
bool | operator!= (const char *value) const
bool | operator== (const String &value) const
bool | operator!= (const String &value) const
bool | operator&= (const char *value) const
bool | operator|= (const char *value) const
String & | operator<< (const char *value)
String & | operator<< (char value)
String & | operator<< (int32_t value)
String & | operator<< (uint32_t value)
String & | operator<< (int64_t value)
String & | operator<< (uint64_t value)
String & | operator<< (bool value)
String & | operator<< (double value)
String & | operator>> (const char *skip)
String & | operator>> (char &store)
String & | operator>> (UChar &store)
String & | operator>> (int &store)
String & | operator>> (unsigned int &store)
String & | operator>> (bool &store)
String & | append (const char *value, int len)
String & | append (const char *value, const char *separator=0, bool force=false)
String & | append (const ObjList *list, const char *separator=0, bool force=false)
String & | append (const ObjList &list, const char *separator=0, bool force=false)
String & | append (char value, unsigned int len=1)
String & | append (double value, unsigned int decimals=3)
String & | insert (unsigned int pos, const char *value, int len=-1)
String & | insert (unsigned int pos, char value, unsigned int len=1)
String & | printf (const char *format,...)
String & | printf (unsigned int length, const char *format,...)
String & | printfAppend (const char *format,...)
String & | printfAppend (unsigned int length, const char *format,...)
String & | appendFixed (unsigned int fixedLength, const char *str, unsigned int len=-1, char fill=' ', int align=Left)
String & | appendFixed (unsigned int fixedLength, const String &str, char fill=' ', int align=Left)
int | find (char what, unsigned int offs=0) const
int | find (const char *what, unsigned int offs=0) const
int | rfind (char what) const
int | rfind (const char *what) const
bool | startsWith (const char *what, bool wordBreak=false, bool caseInsensitive=false) const
bool | endsWith (const char *what, bool wordBreak=false, bool caseInsensitive=false) const
bool | startSkip (const char *what, bool wordBreak=true, bool caseInsensitive=false)
String & | replaceChars (const char *what, const char *repl, bool inPlace=false, int wLen=-1, int rLen=-1, bool *chg=0)
String & | removeChars (const char *what, int wLen=-1, bool *chg=0)
String & | extractTo (const char *sep, String &store)
String & | extractTo (const char *sep, bool &store)
String & | extractTo (const char *sep, int &store, int base=0)
String & | extractTo (const char *sep, int &store, const TokenDict *tokens, int base=0)
String & | extractTo (const char *sep, double &store)
virtual bool | matches (const String &value) const
bool | matches (const Regexp &rexp)
int | matchOffset (int index=0) const
int | matchLength (int index=0) const
String | matchString (int index=0) const
String | replaceMatches (const String &templ) const
int | matchCount () const
ObjList * | split (ObjList &list, char separator, bool emptyOK=true) const
ObjList * | split (ObjList &list, const Regexp &reg, bool emptyOK=true) const
ObjList * | split (char separator, bool emptyOK=true) const
ObjList * | split (const Regexp &reg, bool emptyOK=true) const
String | msgEscape (char extraEsc=0) const
String | msgUnescape (int *errptr=0, char extraEsc=0) const
String | sqlEscape (char extraEsc=0) const
String & | uriEscapeTo (String &buf, char extraEsc=0, const char *noEsc=0) const
String | uriEscape (char extraEsc=0, const char *noEsc=0) const
String & | uriUnescapeTo (String &buf, bool setPartial=false, int *errptr=0) const
String & | uriUnescapeStr (bool setPartial=false, int *errptr=0)
String | uriUnescape (int *errptr=0, bool setPartial=true) const
Public Member Functions inherited from GenObject
| GenObject ()
virtual | ~GenObject ()
virtual bool | alive () const
virtual void | destruct ()
virtual const String & | traceId () const
NamedCounter * | getObjCounter () const
NamedCounter * | setObjCounter (NamedCounter *counter)

## Friends
class | Engine

## Additional Inherited Members
Public Types inherited from String
enum | Align { Left = 0 , Center , Right }
Static Public Member Functions inherited from String
static const String & | empty ()
static const char * | boolText (bool value)
static int | lenUtf8 (const char *value, uint32_t maxChar=0x10ffff, bool overlong=false)
static bool | checkBOM (const char *str)
static bool | stripBOM (const char *&str)
static bool | stripBOM (char *&str)
static unsigned int | hash (const char *value, unsigned int h=0)
static String | msgEscape (const char *str, char extraEsc=0)
static String | msgUnescape (const char *str, int *errptr=0, char extraEsc=0)
static String | sqlEscape (const char *str, char extraEsc=0)
static String & | uriEscapeTo (String &buf, const char *str, char extraEsc=0, const char *noEsc=0)
static String & | uriEscapeTo (String &buf, const char *str, const char *extraEsc, const char *noEsc=0)
static String | uriEscape (const char *str, char extraEsc=0, const char *noEsc=0)
static String | uriEscape (const char *str, const char *extraEsc, const char *noEsc=0)
static String & | uriUnescapeTo (String &buf, const char *str, bool setPartial=false, int *errptr=0)
static String | uriUnescape (const char *str, int *errptr=0, bool setPartial=true)
static const String * | atom (const String *&str, const char *val)
static unsigned int | c_starts_with (const char *str, const char *what, int lenStr=-1, int lenWhat=-1, bool caseInsensitive=false)
static unsigned int | c_ends_with (const char *str, const char *what, int lenStr=-1, int lenWhat=-1, bool caseInsensitive=false)
static unsigned int | c_skip (const char *&str, const char *what, int lenStr=-1, int lenWhat=-1, bool caseInsensitive=false)
static unsigned int | c_skip_chars (const char *&str, const char *what, int len=-1, bool skipFound=true)
static char * | c_replace_chars (const char *str, const char *what, const char *repl=0, bool inPlace=false, int wLen=-1, int rLen=-1, bool *chg=0)
Static Public Member Functions inherited from GenObject
static void * | getObject (const String &name, const GenObject *obj)
static bool | getObjCounting ()
static void | setObjCounting (bool enable)
static NamedCounter * | getObjCounter (const String &name, bool create=true)
static ObjList & | getObjCounters ()
Protected Member Functions inherited from String
virtual void | changed ()

## Detailed Description

Configuration file handling.

A class for parsing and quickly accessing INI style configuration files

## Constructor & Destructor Documentation

## ◆ Configuration() [1/2]

Configuration | ( |  | ) |

Create an empty configuration

Referenced by operator=().

## ◆ Configuration() [2/2]

Configuration | ( | const char * | filename,
|  | bool | warn = true )
| explicit

Create a configuration from a file

Parameters

  filename | Name of file to initialize from
  warn | True to warn if the configuration could not be loaded

## Member Function Documentation

## ◆ addValue()

void addValue | ( | const String & | sect,
|  | const char * | key,
|  | const char * | value = 0 )

Add the value of a key in a section.

Parameters

  sect | Name of the section, will be created if missing
  key | Name of the key to add in the section
  value | Value to set in the key

References String::String().

## ◆ clearKey()

void clearKey | ( | const String & | sect,
|  | const String & | key )

Deletes a key/value pair

Parameters

  sect | Name of section
  key | Name of the key to delete

References String::String().

## ◆ clearSection()

void clearSection | ( | const char * | sect = 0 | ) |

Deletes an entire section

Parameters

  sect | Name of section to delete, NULL to delete all

## ◆ count()

unsigned int count | ( |  | ) | const
| inline

Get the number of non null sections

Returns
  Count of sections

## ◆ createSection()

NamedList * createSection | ( | const String & | sect | ) |

Makes sure a section with a given name exists, creates if required

Parameters

  sect | Name of section to check or create

Returns
  The section's content or NULL if no such section

References String::String().

## ◆ getBoolValue()

bool getBoolValue | ( | const String & | sect,
|  | const String & | key,
|  | bool | defvalue = false ) const

Retrieve the boolean value of a key in a section.

Parameters

  sect | Name of the section
  key | Name of the key in section
  defvalue | Default value to return if not found

Returns
  The boolean value contained in the key or the default

References String::String().

## ◆ getDoubleValue()

double getDoubleValue | ( | const String & | sect,
|  | const String & | key,
|  | double | defvalue = 0.0 ) const

Retrieve the floating point value of a key in a section.

Parameters

  sect | Name of the section
  key | Name of the key in section
  defvalue | Default value to return if not found

Returns
  The numeric value contained in the key or the default

References String::String().

## ◆ getInt64Value()

int64_t getInt64Value | ( | const String & | sect,
|  | const String & | key,
|  | int64_t | defvalue = 0,
|  | int64_t | minvalue = LLONG_MIN,
|  | int64_t | maxvalue = LLONG_MAX,
|  | bool | clamp = true ) const

Retrieve the 64-bit numeric value of a key in a section.

Parameters

  sect | Name of the section
  key | Name of the key in section
  defvalue | Default value to return if not found
  minvalue | Minimum value allowed for the parameter
  maxvalue | Maximum value allowed for the parameter
  clamp | Control the out of bound values: true to adjust to the nearest bound, false to return the default value

Returns
  The number contained in the key or the default

References String::String().

## ◆ getIntValue() [1/2]

int getIntValue | ( | const String & | sect,
|  | const String & | key,
|  | const TokenDict * | tokens,
|  | int | defvalue = 0 ) const

Retrieve the numeric value of a key in a section trying first a table lookup.

Parameters

  sect | Name of the section
  key | Name of the key in section
  tokens | A pointer to an array of tokens to try to lookup
  defvalue | Default value to return if not found

Returns
  The number contained in the key or the default

References String::String().

## ◆ getIntValue() [2/2]

int getIntValue | ( | const String & | sect,
|  | const String & | key,
|  | int | defvalue = 0,
|  | int | minvalue = INT_MIN,
|  | int | maxvalue = INT_MAX,
|  | bool | clamp = true ) const

Retrieve the numeric value of a key in a section.

Parameters

  sect | Name of the section
  key | Name of the key in section
  defvalue | Default value to return if not found
  minvalue | Minimum value allowed for the parameter
  maxvalue | Maximum value allowed for the parameter
  clamp | Control the out of bound values: true to adjust to the nearest bound, false to return the default value

Returns
  The number contained in the key or the default

References String::String().

## ◆ getKey()

NamedString * getKey | ( | const String & | sect,
|  | const String & | key ) const

Locate a key/value pair in the section.

Parameters

  sect | Name of the section
  key | Name of the key in section

Returns
  A pointer to the key/value pair or NULL.

References String::String().

## ◆ getSection() [1/2]

NamedList * getSection | ( | const String & | sect | ) | const

Retrieve an entire section

Parameters

  sect | Name of the section

Returns
  The section's content or NULL if no such section

References String::String().

## ◆ getSection() [2/2]

NamedList * getSection | ( | unsigned int | index | ) | const

Retrieve an entire section

Parameters

  index | Index of the section

Returns
  The section's content or NULL if no such section

## ◆ getValue()

const char * getValue | ( | const String & | sect,
|  | const String & | key,
|  | const char * | defvalue = 0 ) const

Retrieve the value of a key in a section.

Parameters

  sect | Name of the section
  key | Name of the key in section
  defvalue | Default value to return if not found

Returns
  The string contained in the key or the default

References String::String().

## ◆ load()

bool load | ( | bool | warn = true | ) |

Load the configuration from file

Parameters

  warn | True to also warn if the configuration could not be loaded

Returns
  True if successfull, false for failure

## ◆ operator=()

Configuration & operator= | ( | const String & | value | ) |
| inline

Assignment from string operator

References Configuration(), String::operator=(), and String::String().

## ◆ save()

bool save | ( |  | ) | const

Save the configuration to file

Returns
  True if successfull, false for failure

## ◆ sections()

unsigned int sections | ( |  | ) | const
| inline

Get the number of sections

Returns
  Count of sections

## ◆ setValue() [1/3]

void setValue | ( | const String & | sect,
|  | const char * | key,
|  | bool | value )

Set the boolean value of a key in a section.

Parameters

  sect | Name of the section, will be created if missing
  key | Name of the key in section, will be created if missing
  value | Value to set in the key

References String::String().

## ◆ setValue() [2/3]

void setValue | ( | const String & | sect,
|  | const char * | key,
|  | const char * | value = 0 )

Set the value of a key in a section.

Parameters

  sect | Name of the section, will be created if missing
  key | Name of the key in section, will be created if missing
  value | Value to set in the key

References String::String().

## ◆ setValue() [3/3]

void setValue | ( | const String & | sect,
|  | const char * | key,
|  | int | value )

Set the numeric value of a key in a section.

Parameters

  sect | Name of the section, will be created if missing
  key | Name of the key in section, will be created if missing
  value | Value to set in the key

References String::String().

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

- yatengine.h