PConfigurationFile Class Reference

Detailed Description

The PConfigurationFile class provides a friendly interface for handling .ini configuration files.

Definition at line 30 of file PConfigurationFile.h.

#include <PConfigurationFile.h>

Constructor & Destructor Documentation

◆ PConfigurationFile() [1/2]

PConfigurationFile::PConfigurationFile ( )

Constructs an empty configuration file.

See also
Load()
FromString()

◆ PConfigurationFile() [2/2]

PConfigurationFile::PConfigurationFile ( const PConfigurationFile other)

Constructs a shared copy of other.

◆ ~PConfigurationFile()

virtual PConfigurationFile::~PConfigurationFile ( )
virtual

Destroys this object.

Member Function Documentation

◆ DecryptFile()

static PResult PConfigurationFile::DecryptFile ( const PString fileIn,
const PString fileOut 
)
static

◆ EncryptFile()

static PResult PConfigurationFile::EncryptFile ( const PString fileIn,
const PString fileOut 
)
static

◆ FromString()

PResult PConfigurationFile::FromString ( const PString content)

(Re)Initialises the object with given configuration file content.

◆ GetFilename()

PString PConfigurationFile::GetFilename ( ) const

Returns name of the configuration file (can be empty).

◆ GetProperty()

PString PConfigurationFile::GetProperty ( const PString path,
const PString defaultValue = PString::Empty() 
) const

Returns the value of the property at given path.

If there is no such key, then the default default value will be returned.

Path should be dot separated, e.g. "sectionA.key1" for,

[sectionA] key1=value

◆ GetSectionList()

PStringList PConfigurationFile::GetSectionList ( const PString section = PString::Empty()) const

Returns the list of keys under given section in the same order they appear in the file, i.e.

not ordered. So, for a file content,

[section1] key1=value1 key2=value2

This will return a PStringList("key1", "key2"). By default, returns root elements.

◆ HasProperty()

bool PConfigurationFile::HasProperty ( const PString path) const

Returns true if the specified property exists in the configuration file, false otherwise.

◆ IsEncrypted()

static bool PConfigurationFile::IsEncrypted ( const PString filename)
static

Returns true if file specified by filename exists and is encrypted.

Returns false otherwise (including if file does not exist or if it exists but is unreadable)

◆ Load()

PResult PConfigurationFile::Load ( const PString filename)

Loads the specified configuration file and sets the filename.

The current content of this configuration file is replaced. Returns PResult::C_OK if success, another result otherwise.

◆ operator=()

PConfigurationFile& PConfigurationFile::operator= ( const PConfigurationFile other)

Performs a shared copy of other to this object.

◆ Reload()

PResult PConfigurationFile::Reload ( )

Reloads the configuration file if it is associated with a filename.

◆ RemoveProperty()

PResult PConfigurationFile::RemoveProperty ( const PString path)

Removes the property at given path.

Path should be dot separated, e.g. "sectionA.key1" to remove following key, for example,

[sectionA] key1=value

◆ RemoveSection()

PResult PConfigurationFile::RemoveSection ( const PString section)

Removes a section with given name along with all its child keys.

◆ Save()

PResult PConfigurationFile::Save ( const PString filename,
bool  bEncryptFile = false 
)

Saves this configuration file to disk.

bEncryptFile sets whether the saved file will be encrypted Returns PResult::C_OK if success, another result otherwise.

◆ SetProperties()

PResult PConfigurationFile::SetProperties ( const PProperties properties)

Sets all properties contained int the specified PProperties object.

Path should be dot separated, e.g. "sectionA.key1" for,

[sectionA] key1=value

WARNING: path is limited to 2 levels, i.e. path with 3 levels or more (e.g. "path.subpath1.subpath2") will be rejected.

◆ SetProperty() [1/3]

PResult PConfigurationFile::SetProperty ( const PString path,
const PString value 
)

Sets the value of a property at given path.

If there is no such key, then it will be created along with its parent section.

Path should be dot separated, e.g. "sectionA.key1" for,

[sectionA] key1=value

WARNING: path is limited to 2 levels, i.e. path with 3 levels or more (e.g. "path.subpath1.subpath2") will be rejected.

◆ SetProperty() [2/3]

PResult PConfigurationFile::SetProperty ( const PString path,
papillon::int32  value 
)

Sets the value of a property at given path.

If there is no such key, then it will be created along with its parent section.

Path should be dot separated, e.g. "sectionA.key1" for,

[sectionA] key1=value

WARNING: path is limited to 2 levels, i.e. path with 3 levels or more (e.g. "path.subpath1.subpath2") will be rejected.

◆ SetProperty() [3/3]

PResult PConfigurationFile::SetProperty ( const PString path,
double  value 
)

Sets the value of a property at given path.

If there is no such key, then it will be created along with its parent section.

Path should be dot separated, e.g. "sectionA.key1" for,

[sectionA] key1=value

WARNING: path is limited to 2 levels, i.e. path with 3 levels or more (e.g. "path.subpath1.subpath2") will be rejected.

◆ ToProperties()

PProperties PConfigurationFile::ToProperties ( ) const

Creates a PProperties view of this configuration file.

Properties and values are stored as PString. Property name scheme is the following: "section"."name" Example: [os] linux=false windows=true [lang] cpp=true will be converted to: ["os.linux" -> "false", "os.windows" -> "true", "lang.cpp" -> "true"].