ScummVM API documentation
Common::INIFile Class Reference

#include <ini-file.h>

Classes

struct  KeyValue
 
struct  Section
 

Public Types

typedef List< KeyValueSectionKeyList
 
typedef List< SectionSectionList
 

Public Member Functions

bool isValidName (const String &name) const
 
void clear ()
 
bool loadFromFile (const Path &filename)
 
bool loadFromFileOrDataFork (const Path &filename)
 
bool loadFromSaveFile (const String &filename)
 
bool loadFromStream (SeekableReadStream &stream)
 
bool saveToFile (const Path &filename)
 
bool saveToSaveFile (const String &filename)
 
bool saveToStream (WriteStream &stream)
 
bool hasSection (const String &section) const
 
void addSection (const String &section)
 
void removeSection (const String &section)
 
void renameSection (const String &oldName, const String &newName)
 
void setDefaultSectionName (const String &name)
 
bool hasKey (const String &key, const String &section) const
 
bool getKey (const String &key, const String &section, String &value) const
 
void setKey (const String &key, const String &section, const String &value)
 
void removeKey (const String &key, const String &section)
 
const SectionList getSections () const
 
const SectionKeyList getKeys (const String &section) const
 
void listKeyValues (StringMap &kv)
 
void allowNonEnglishCharacters ()
 
void suppressValuelessLineWarning ()
 
void requireKeyValueDelimiter ()
 

Detailed Description

This class allows for reading and writing INI-style config files.

Lines starting with a '#' are ignored (i.e. treated as comments). Some effort is made to preserve comments, though.

This class makes no attempts to provide fast access to key/value pairs. In particular, it stores all sections and key/value pairs in lists, not in dictionaries/maps. This makes it very easy to read/write the data from/to files, but of course is not appropriate for fast access. The main reason is that this class is indeed geared toward doing precisely that.

Member Typedef Documentation

◆ SectionKeyList

A list of all key/value pairs in this section.

◆ SectionList

A list of all sections in this INI file.

Member Function Documentation

◆ isValidName()

bool Common::INIFile::isValidName ( const String name) const

Check whether the given string is a valid section or key name. For that, it must only consist of letters, numbers, dashes, and underscores. In particular, whitespace and "#", "=", "[", "]" are not valid.

◆ clear()

void Common::INIFile::clear ( )

Reset everything stored in this INI file.

◆ loadFromFile()

bool Common::INIFile::loadFromFile ( const Path filename)

Load configuration from a file.

◆ loadFromFileOrDataFork()

bool Common::INIFile::loadFromFileOrDataFork ( const Path filename)

Load configuration from a file in MacBinary format.

◆ loadFromSaveFile()

bool Common::INIFile::loadFromSaveFile ( const String filename)

Load configuration from a save file.

◆ loadFromStream()

bool Common::INIFile::loadFromStream ( SeekableReadStream stream)

Load configuration from a SeekableReadStream.

◆ saveToFile()

bool Common::INIFile::saveToFile ( const Path filename)

Save the current configuration to a file.

◆ saveToSaveFile()

bool Common::INIFile::saveToSaveFile ( const String filename)

Save the current configuration to a save file.

◆ saveToStream()

bool Common::INIFile::saveToStream ( WriteStream stream)

Save the current configuration to a WriteStream.

◆ hasSection()

bool Common::INIFile::hasSection ( const String section) const

Check whether the INI file has a section with the specified name.

◆ addSection()

void Common::INIFile::addSection ( const String section)

Add a section with the specified name to the INI file.

◆ removeSection()

void Common::INIFile::removeSection ( const String section)

Remove the section from the INI file.

◆ renameSection()

void Common::INIFile::renameSection ( const String oldName,
const String newName 
)

Rename the INI file from oldName to newName.

◆ setDefaultSectionName()

void Common::INIFile::setDefaultSectionName ( const String name)

Set initial section name for section-less INI files.

◆ hasKey()

bool Common::INIFile::hasKey ( const String key,
const String section 
) const

Check whether the section has a key.

◆ getKey()

bool Common::INIFile::getKey ( const String key,
const String section,
String value 
) const

Get the value of a key in a section.

◆ setKey()

void Common::INIFile::setKey ( const String key,
const String section,
const String value 
)

Assign a value to a key in a section.

◆ removeKey()

void Common::INIFile::removeKey ( const String key,
const String section 
)

Remove a key from this section.

◆ getSections()

const SectionList Common::INIFile::getSections ( ) const
inline

Get a list of sections in this INI file.

◆ getKeys()

const SectionKeyList Common::INIFile::getKeys ( const String section) const

Get a list of keys in a section.

◆ listKeyValues()

void Common::INIFile::listKeyValues ( StringMap kv)

Get a list of all key/value pairs in this INI file.

◆ allowNonEnglishCharacters()

void Common::INIFile::allowNonEnglishCharacters ( )

Allow non-English characters in this INI file.

◆ suppressValuelessLineWarning()

void Common::INIFile::suppressValuelessLineWarning ( )

Disable warnings for lines that contain only keys.

◆ requireKeyValueDelimiter()

void Common::INIFile::requireKeyValueDelimiter ( )

Requires that every key/value line have a delimiter character. Otherwise, lines that don't contain a delimiter are interpreted as if the entire line is a key with an empty value. This can cause unexpected junk lines to reach engines. (bug #13920)

It may be better if instead this were the default behavior for clients to disable if needed, but first we would need to identify everything that depends on the current behavior.


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