glibmm  2.62.0
About: glibmm is a set of C++ bindings for glib, including cross-platform APIs such as a std::string-like UTF8 string class, string utility methods, such as a text encoding converter API, file access, and threads.
  Fossies Dox: glibmm-2.62.0.tar.xz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

Glib::KeyFile Class Reference

This class lets you parse, edit or create files containing groups of key-value pairs, which we call key files for lack of a better name. More...

#include <keyfile.h>

Public Member Functions

 KeyFile ()
 Creates a new, empty KeyFile object. More...
 
 KeyFile (const KeyFile &)=delete
 
KeyFileoperator= (const KeyFile &)=delete
 
 KeyFile (KeyFile &&other) noexcept
 
KeyFileoperator= (KeyFile &&other) noexcept
 
 ~KeyFile ()
 Destructor. More...
 
 KeyFile (GKeyFile *castitem, bool takes_ownership=false)
 Creates a glibmm KeyFile wrapper for a GKeyFile object. More...
 
bool load_from_file (const std::string &file, KeyFileFlags flags=Glib::KEY_FILE_NONE)
 Loads a key file into an empty KeyFile instance. More...
 
bool load_from_data (const Glib::ustring &data, KeyFileFlags flags=Glib::KEY_FILE_NONE)
 Loads a KeyFile from memory. More...
 
bool load_from_dirs (const std::string &file, const Glib::ArrayHandle< std::string > &search_dirs, Glib::ArrayHandle< std::string > &full_path, KeyFileFlags flags=Glib::KEY_FILE_NONE)
 This function looks for a key file named file in the paths specified in search_dirs, loads the file into key_file and returns the file's full path in full_path. More...
 
bool load_from_dirs (const std::string &file, const Glib::ArrayHandle< std::string > &search_dirs, std::string &full_path, KeyFileFlags flags=Glib::KEY_FILE_NONE)
 This function looks for a key file named file in the paths specified in search_dirs, loads the file into key_file and returns the file's full path in full_path. More...
 
bool load_from_data_dirs (const std::string &file, std::string &full_path, KeyFileFlags flags=Glib::KEY_FILE_NONE)
 Looks for a KeyFile named file in the paths returned from g_get_user_data_dir() and g_get_system_data_dirs() and loads them into the keyfile object, placing the full path to the file in full_path. More...
 
Glib::ustring to_data ()
 Outputs the KeyFile as a string. More...
 
bool save_to_file (const std::string &filename)
 Writes the contents of key_file to filename using g_file_set_contents(). More...
 
Glib::ustring get_start_group () const
 Returns the name of the start group of the file. More...
 
Glib::ArrayHandle< Glib::ustringget_groups () const
 Gets a list of all groups in the KeyFile. More...
 
Glib::ArrayHandle< Glib::ustringget_keys (const Glib::ustring &group_name) const
 Gets a list of all keys from the group group_name. More...
 
bool has_group (const Glib::ustring &group_name) const
 Looks whether the key file has the group group_name. More...
 
bool has_key (const Glib::ustring &group_name, const Glib::ustring &key) const
 Looks whether the key file has the key key in the group group_name. More...
 
Glib::ustring get_value (const Glib::ustring &group_name, const Glib::ustring &key) const
 Returns the value associated with key under group_name. More...
 
Glib::ustring get_string (const Glib::ustring &group_name, const Glib::ustring &key) const
 Return value: a newly allocated string or nullptr. More...
 
Glib::ustring get_locale_for_key (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ustring &locale={}) const
 Returns the actual locale which the result of g_key_file_get_locale_string() or g_key_file_get_locale_string_list() came from. More...
 
Glib::ustring get_locale_string (const Glib::ustring &group_name, const Glib::ustring &key) const
 Gets the value associated with key under group_name translated into the current locale. More...
 
Glib::ustring get_locale_string (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ustring &locale) const
 Return value: a newly allocated string or nullptr. More...
 
bool get_boolean (const Glib::ustring &key) const
 Gets the value in the first group, under key, interpreting it as a boolean. More...
 
bool get_boolean (const Glib::ustring &group_name, const Glib::ustring &key) const
 Return value: the value associated with the key as a boolean. More...
 
int get_integer (const Glib::ustring &key) const
 Gets the value in the first group, under key, interpreting it as an integer. More...
 
int get_integer (const Glib::ustring &group_name, const Glib::ustring &key) const
 Return value: the value associated with the key as an integer. More...
 
gint64 get_int64 (const Glib::ustring &key) const
 Gets the value in the first group, under key, interpreting it as a signed 64-bit integer. More...
 
gint64 get_int64 (const Glib::ustring &group_name, const Glib::ustring &key) const
 Returns the value associated with key under group_name as a signed 64-bit integer. More...
 
guint64 get_uint64 (const Glib::ustring &key) const
 Gets the value in the first group, under key, interpreting it as an unsigned 64-bit integer. More...
 
guint64 get_uint64 (const Glib::ustring &group_name, const Glib::ustring &key) const
 Returns the value associated with key under group_name as an unsigned 64-bit integer. More...
 
double get_double (const Glib::ustring &key) const
 Gets the value in the first group, under key, interpreting it as a double. More...
 
double get_double (const Glib::ustring &group_name, const Glib::ustring &key) const
 Return value: the value associated with the key as a double. More...
 
void set_double (const Glib::ustring &group_name, const Glib::ustring &key, double value)
 Associates a new double value with key under group_name. More...
 
void set_double (const Glib::ustring &key, double value)
 Associates a new double value with key under the start group. More...
 
Glib::ArrayHandle< Glib::ustringget_string_list (const Glib::ustring &group_name, const Glib::ustring &key) const
 Returns the values associated with key under group_name. More...
 
Glib::ArrayHandle< Glib::ustringget_locale_string_list (const Glib::ustring &group_name, const Glib::ustring &key) const
 Returns the values associated with key under group_name translated into the current locale, if available. More...
 
Glib::ArrayHandle< Glib::ustringget_locale_string_list (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ustring &locale) const
 Returns the values associated with key under group_name translated into locale, if available. More...
 
Glib::ArrayHandle< bool > get_boolean_list (const Glib::ustring &group_name, const Glib::ustring &key) const
 Returns the values associated with key under group_name. More...
 
Glib::ArrayHandle< int > get_integer_list (const Glib::ustring &group_name, const Glib::ustring &key) const
 Returns the values associated with key under group_name. More...
 
Glib::ArrayHandle< double > get_double_list (const Glib::ustring &group_name, const Glib::ustring &key) const
 Returns the values associated with key under group_name. More...
 
Glib::ustring get_comment () const
 Get comment from top of file. More...
 
Glib::ustring get_comment (const Glib::ustring &group_name) const
 Get comment from above a group. More...
 
Glib::ustring get_comment (const Glib::ustring &group_name, const Glib::ustring &key) const
 Retrieves a comment above key from group_name. More...
 
void set_list_separator (gchar separator)
 Sets the character which is used to separate values in lists. More...
 
void set_value (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ustring &value)
 Associates a new value with key under group_name. More...
 
void set_string (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ustring &string)
 Associates a new string value with key under group_name. More...
 
void set_locale_string (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ustring &locale, const Glib::ustring &string)
 Associates a string value for key and locale under group_name. More...
 
void set_boolean (const Glib::ustring &group_name, const Glib::ustring &key, bool value)
 Associates a new boolean value with key under group_name. More...
 
void set_integer (const Glib::ustring &group_name, const Glib::ustring &key, int value)
 Associates a new integer value with key under group_name. More...
 
void set_int64 (const Glib::ustring &group_name, const Glib::ustring &key, gint64 value)
 Associates a new integer value with key under group_name. More...
 
void set_uint64 (const Glib::ustring &group_name, const Glib::ustring &key, guint64 value)
 Associates a new integer value with key under group_name. More...
 
void set_string_list (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ArrayHandle< Glib::ustring > &list)
 Sets a list of string values for key under group_name. More...
 
void set_locale_string_list (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ustring &locale, const Glib::ArrayHandle< Glib::ustring > &list)
 Sets a list of string values for the key under group_name and marks them as being for locale. More...
 
void set_boolean_list (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ArrayHandle< bool > &list)
 Sets a list of booleans for the key under group_name. More...
 
void set_integer_list (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ArrayHandle< int > &list)
 Sets a list of integers for the key under group_name. More...
 
void set_double_list (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ArrayHandle< double > &list)
 Sets a list of doubles for the key under group_name. More...
 
void set_comment (const Glib::ustring &comment)
 Places comment at the start of the file, before the first group. More...
 
void set_comment (const Glib::ustring &group_name, const Glib::ustring &comment)
 Places comment above group_name. More...
 
void set_comment (const Glib::ustring &group_name, const Glib::ustring &key, const Glib::ustring &comment)
 Places a comment above key from group_name. More...
 
void remove_comment (const Glib::ustring &group_name, const Glib::ustring &key)
 Removes a comment above key from group_name. More...
 
void remove_key (const Glib::ustring &group_name, const Glib::ustring &key)
 Removes key in group_name from the key file. More...
 
void remove_group (const Glib::ustring &group_name)
 Removes the specified group, group_name, from the key file. More...
 
GKeyFile * gobj ()
 
const GKeyFile * gobj () const
 

Protected Attributes

GKeyFile * gobject_
 
bool owns_gobject_
 

Detailed Description

This class lets you parse, edit or create files containing groups of key-value pairs, which we call key files for lack of a better name.

Several freedesktop.org specifications use key files now, e.g the Desktop Entry Specification and the Icon Theme Specification.

The syntax of key files is described in detail in the Desktop Entry Specification, here is a quick summary: Key files consists of groups of key-value pairs, interspersed with comments.

# this is just an example
# there can be comments before the first group
[First Group]
Name=Key File Example\tthis value shows\nescaping
# localized strings are stored in multiple key-value pairs
Welcome=Hello
Welcome[de]=Hallo
Welcome[fr]=Bonjour
Welcome[it]=Ciao
[Another Group]
Numbers=2;20;-200;0
Booleans=true;false;true;true

Lines beginning with a '#' and blank lines are considered comments.

Groups are started by a header line containing the group name enclosed in '[' and ']', and ended implicitly by the start of the next group or the end of the file. Each key-value pair must be contained in a group.

Key-value pairs generally have the form key=value, with the exception of localized strings, which have the form key[locale]=value. Space before and after the '=' character are ignored. Newline, tab, carriage return and backslash characters in value are escaped as \n, \t, \r, and \\, respectively. To preserve leading spaces in values, these can also be escaped as \s.

Key files can store strings (possibly with localized variants), integers, booleans and lists of these. Lists are separated by a separator character, typically ';' or ','. To use the list separator character in a value in a list, it has to be escaped by prefixing it with a backslash.

This syntax is obviously inspired by the .ini files commonly met on Windows, but there are some important differences:

  • .ini files use the ';' character to begin comments, key files use the '#' character.
  • Key files allow only comments before the first group.
  • Key files are always encoded in UTF-8.
  • Key and Group names are case-sensitive, for example a group called [GROUP] is a different group from [group].

Note that in contrast to the Desktop Entry Specification, groups in key files may contain the same key multiple times; the last entry wins. Key files may also contain multiple groups with the same name; they are merged together. Another difference is that keys and group names in key files are not restricted to ASCII characters.

Since @PACKAGE_NAME@ 2.14:

Definition at line 213 of file keyfile.h.

Constructor & Destructor Documentation

◆ KeyFile() [1/4]

Glib::KeyFile::KeyFile ( )

Creates a new, empty KeyFile object.

Definition at line 31 of file keyfile.cc.

References gobject_, and owns_gobject_.

◆ KeyFile() [2/4]

Glib::KeyFile::KeyFile ( const KeyFile )
delete

◆ KeyFile() [3/4]

Glib::KeyFile::KeyFile ( KeyFile &&  other)
noexcept

Definition at line 43 of file keyfile.cc.

◆ ~KeyFile()

Glib::KeyFile::~KeyFile ( )

Destructor.

Definition at line 65 of file keyfile.cc.

References gobject_, and owns_gobject_.

◆ KeyFile() [4/4]

Glib::KeyFile::KeyFile ( GKeyFile *  castitem,
bool  takes_ownership = false 
)

Creates a glibmm KeyFile wrapper for a GKeyFile object.

Note, when using this that when the wrapper is deleted, it will not automatically delete the GKeyFile unless you set the takes_ownership boolean to true.

Parameters
castitemThe C instance to wrap.
takes_ownershipIf the C instance should be deleted when the wrapper is deleted.

Definition at line 37 of file keyfile.cc.

References gobject_, and owns_gobject_.

Member Function Documentation

◆ get_boolean() [1/2]

bool Glib::KeyFile::get_boolean ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Return value: the value associated with the key as a boolean.

Since @PACKAGE_NAME@ 2.6:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key.
Returns
The value associated with the key as a boolean, or false if the key was not found or could not be parsed.

Definition at line 527 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_boolean() [2/2]

bool Glib::KeyFile::get_boolean ( const Glib::ustring key) const

Gets the value in the first group, under key, interpreting it as a boolean.

Parameters
keyThe name of the key.
Returns
The value of key as a boolean.
Exceptions
Glib::KeyFileError.
Since @PACKAGE_NAME@ 2.6:

Definition at line 183 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_boolean_list()

Glib::ArrayHandle< bool > Glib::KeyFile::get_boolean_list ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Returns the values associated with key under group_name.

Parameters
group_nameThe name of a group
keyThe name of a key
Returns
A list of booleans
Exceptions
Glib::KeyFileError

Definition at line 289 of file keyfile.cc.

References GLIBMM_THROW, gobj(), and Glib::OWNERSHIP_SHALLOW.

◆ get_comment() [1/3]

Glib::ustring Glib::KeyFile::get_comment ( ) const

Get comment from top of file.

Returns
The comment
Exceptions
Glib::KeyFileError

Definition at line 373 of file keyfile.cc.

References GLIBMM_THROW, and gobj().

◆ get_comment() [2/3]

Glib::ustring Glib::KeyFile::get_comment ( const Glib::ustring group_name) const

Get comment from above a group.

Parameters
group_nameThe group
Returns
The comment
Exceptions
Glib::KeyFileError

Definition at line 385 of file keyfile.cc.

References GLIBMM_THROW, and gobj().

◆ get_comment() [3/3]

Glib::ustring Glib::KeyFile::get_comment ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Retrieves a comment above key from group_name.

If key is nullptr then comment will be read from above group_name. If both key and group_name are nullptr, then comment will be read from above the first group in the file. Use the overrides for a nullptr key or group.

Since @PACKAGE_NAME@ 2.6:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key.
Returns
The comment.

Definition at line 577 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_double() [1/2]

double Glib::KeyFile::get_double ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Return value: the value associated with the key as a double.

Since @PACKAGE_NAME@ 2.14:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key.
Returns
The value associated with the key as a double, or 0.0 if the key was not found or could not be parsed.

Definition at line 563 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_double() [2/2]

double Glib::KeyFile::get_double ( const Glib::ustring key) const

Gets the value in the first group, under key, interpreting it as a double.

Parameters
keyThe name of the key
Returns
The value of key as an double
Exceptions
Glib::KeyFileError
Since @PACKAGE_NAME@ 2.14:

Definition at line 235 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_double_list()

Glib::ArrayHandle< double > Glib::KeyFile::get_double_list ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Returns the values associated with key under group_name.

Parameters
group_nameThe name of a group
keyThe name of a key
Returns
A list of doubles
Exceptions
Glib::KeyFileError

Definition at line 319 of file keyfile.cc.

References Glib::ustring::c_str(), GLIBMM_THROW, gobj(), and Glib::OWNERSHIP_SHALLOW.

◆ get_groups()

Glib::ArrayHandle< Glib::ustring > Glib::KeyFile::get_groups ( ) const

Gets a list of all groups in the KeyFile.

Returns
A list containing the names of the groups

Definition at line 146 of file keyfile.cc.

References gobj(), and Glib::OWNERSHIP_DEEP.

◆ get_int64() [1/2]

gint64 Glib::KeyFile::get_int64 ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Returns the value associated with key under group_name as a signed 64-bit integer.

This is similar to g_key_file_get_integer() but can return 64-bit results without truncation.

Since @PACKAGE_NAME@ 2.26:
Parameters
group_nameA non-nullptr group name.
keyA non-nullptr key.
Returns
The value associated with the key as a signed 64-bit integer, or 0 if the key was not found or could not be parsed.
Exceptions
Glib::KeyFileError

Definition at line 545 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_int64() [2/2]

gint64 Glib::KeyFile::get_int64 ( const Glib::ustring key) const

Gets the value in the first group, under key, interpreting it as a signed 64-bit integer.

This is similar to get_integer() but can return 64-bit results without truncation.

Parameters
keyThe name of the key.
Returns
The value of key as a signed 64-bit integer, or 0 if the key was not found or could not be parsed.
Exceptions
Glib::KeyFileError.
Since @PACKAGE_NAME@ 2.28:

Definition at line 207 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_integer() [1/2]

int Glib::KeyFile::get_integer ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Return value: the value associated with the key as an integer.

Since @PACKAGE_NAME@ 2.6:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key.
Returns
The value associated with the key as an integer, or 0 if the key was not found or could not be parsed.

Definition at line 536 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_integer() [2/2]

int Glib::KeyFile::get_integer ( const Glib::ustring key) const

Gets the value in the first group, under key, interpreting it as an integer.

Parameters
keyThe name of the key
Returns
The value of key as an integer
Exceptions
Glib::KeyFileError
Since @PACKAGE_NAME@ 2.6:

Definition at line 195 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_integer_list()

Glib::ArrayHandle< int > Glib::KeyFile::get_integer_list ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Returns the values associated with key under group_name.

Parameters
group_nameThe name of a group
keyThe name of a key
Returns
A list of integers
Exceptions
Glib::KeyFileError

Definition at line 304 of file keyfile.cc.

References GLIBMM_THROW, gobj(), and Glib::OWNERSHIP_SHALLOW.

◆ get_keys()

Glib::ArrayHandle< Glib::ustring > Glib::KeyFile::get_keys ( const Glib::ustring group_name) const

Gets a list of all keys from the group group_name.

Parameters
group_nameThe name of a group
Returns
A list containing the names of the keys in group_name
Exceptions
Glib::KeyFileError

Definition at line 155 of file keyfile.cc.

References gobj(), and Glib::OWNERSHIP_DEEP.

◆ get_locale_for_key()

Glib::ustring Glib::KeyFile::get_locale_for_key ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring locale = {} 
) const

Returns the actual locale which the result of g_key_file_get_locale_string() or g_key_file_get_locale_string_list() came from.

If calling g_key_file_get_locale_string() or g_key_file_get_locale_string_list() with exactly the same key_file, group_name, key and locale, the result of those functions will have originally been tagged with the locale that is the result of this function.

Since @PACKAGE_NAME@ 2.60:
Parameters
group_nameA group name.
keyA key.
localeA locale identifier or nullptr.
Returns
The locale from the file, or nullptr if the key was not found or the entry in the file was was untranslated.

Definition at line 513 of file keyfile.cc.

References Glib::ustring::c_str(), Glib::ustring::empty(), and gobj().

◆ get_locale_string() [1/2]

Glib::ustring Glib::KeyFile::get_locale_string ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Gets the value associated with key under group_name translated into the current locale.

Returns
the value as a Glib::ustring
Exceptions
Glib::KeyFileError

Definition at line 170 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_locale_string() [2/2]

Glib::ustring Glib::KeyFile::get_locale_string ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring locale 
) const

Return value: a newly allocated string or nullptr.

Since @PACKAGE_NAME@ 2.6:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key.
localeA locale identifier or nullptr.
Returns
A newly allocated string or nullptr if the specified key cannot be found.

Definition at line 518 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_locale_string_list() [1/2]

Glib::ArrayHandle<Glib::ustring> Glib::KeyFile::get_locale_string_list ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Returns the values associated with key under group_name translated into the current locale, if available.

Parameters
group_nameThe name of a group
keyThe name of a key
Returns
A list containing the values requested
Exceptions
Glib::KeyFileError

◆ get_locale_string_list() [2/2]

Glib::ArrayHandle< Glib::ustring > Glib::KeyFile::get_locale_string_list ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring locale 
) const

Returns the values associated with key under group_name translated into locale, if available.

Parameters
group_nameThe name of a group
keyThe name of a key
localeThe name of a locale
Returns
A list containing the values requested
Exceptions
Glib::KeyFileError

Definition at line 274 of file keyfile.cc.

References Glib::ustring::c_str(), GLIBMM_THROW, gobj(), and Glib::OWNERSHIP_DEEP.

◆ get_start_group()

Glib::ustring Glib::KeyFile::get_start_group ( ) const

Returns the name of the start group of the file.

Since @PACKAGE_NAME@ 2.6:
Returns
The start group of the key file.

Definition at line 476 of file keyfile.cc.

References gobj().

◆ get_string()

Glib::ustring Glib::KeyFile::get_string ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Return value: a newly allocated string or nullptr.

Since @PACKAGE_NAME@ 2.6:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key.
Returns
A newly allocated string or nullptr if the specified key cannot be found.

Definition at line 504 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_string_list()

Glib::ArrayHandle< Glib::ustring > Glib::KeyFile::get_string_list ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Returns the values associated with key under group_name.

Parameters
group_nameThe name of a group
keyThe name of a key
Returns
A list containing the values requested
Exceptions
Glib::KeyFileError

Definition at line 259 of file keyfile.cc.

References GLIBMM_THROW, gobj(), and Glib::OWNERSHIP_DEEP.

◆ get_uint64() [1/2]

guint64 Glib::KeyFile::get_uint64 ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Returns the value associated with key under group_name as an unsigned 64-bit integer.

This is similar to g_key_file_get_integer() but can return large positive results without truncation.

Since @PACKAGE_NAME@ 2.26:
Parameters
group_nameA non-nullptr group name.
keyA non-nullptr key.
Returns
The value associated with the key as an unsigned 64-bit integer, or 0 if the key was not found or could not be parsed.
Exceptions
Glib::KeyFileError

Definition at line 554 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_uint64() [2/2]

guint64 Glib::KeyFile::get_uint64 ( const Glib::ustring key) const

Gets the value in the first group, under key, interpreting it as an unsigned 64-bit integer.

This is similar to get_integer() but can return large positive results without truncation.

Parameters
keyThe name of the key.
Returns
The value of key as an unsigned 64-bit integer, or 0 if the key was not found or could not be parsed.
Exceptions
Glib::KeyFileError.
Since @PACKAGE_NAME@ 2.28:

Definition at line 221 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ get_value()

Glib::ustring Glib::KeyFile::get_value ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Returns the value associated with key under group_name.

Since @PACKAGE_NAME@ 2.6:
Exceptions
Glib::KeyFileErrorin the event the key cannot be found (with the Glib::KeyFileError::KEY_NOT_FOUND code).
Glib::KeyFileErrorin the event that the group_name cannot be found (with the Glib::KeyFileError::GROUP_NOT_FOUND code).
Parameters
group_nameA group name.
keyA key.
Returns
The value as a string.

Definition at line 495 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ gobj() [1/2]

◆ gobj() [2/2]

const GKeyFile* Glib::KeyFile::gobj ( ) const
inline

Definition at line 924 of file keyfile.h.

References gobject_.

◆ has_group()

bool Glib::KeyFile::has_group ( const Glib::ustring group_name) const

Looks whether the key file has the group group_name.

Since @PACKAGE_NAME@ 2.6:
Parameters
group_nameA group name.
Returns
true if group_name is a part of key_file, false otherwise.

Definition at line 481 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ has_key()

bool Glib::KeyFile::has_key ( const Glib::ustring group_name,
const Glib::ustring key 
) const

Looks whether the key file has the key key in the group group_name.

Since @PACKAGE_NAME@ 2.6:
Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key name.
Returns
true if key is a part of group_name, false otherwise.

Definition at line 486 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ load_from_data()

bool Glib::KeyFile::load_from_data ( const Glib::ustring data,
KeyFileFlags  flags = Glib::KEY_FILE_NONE 
)

Loads a KeyFile from memory.

Parameters
dataThe data to use as a KeyFile
flagsBitwise combination of the flags to use for the KeyFile
Returns
true if the KeyFile was successfully loaded, false otherwise
Exceptions
Glib::KeyFileError

Definition at line 72 of file keyfile.cc.

References Glib::ustring::bytes(), Glib::ustring::c_str(), and gobj().

◆ load_from_data_dirs()

bool Glib::KeyFile::load_from_data_dirs ( const std::string &  file,
std::string &  full_path,
KeyFileFlags  flags = Glib::KEY_FILE_NONE 
)

Looks for a KeyFile named file in the paths returned from g_get_user_data_dir() and g_get_system_data_dirs() and loads them into the keyfile object, placing the full path to the file in full_path.

Parameters
fileThe file to search for
[out]full_pathReturn location for a string containing the full path of the file
flagsBitwise combination of the flags to use for the KeyFile
Returns
true if the KeyFile was successfully loaded, false otherwise
Exceptions
Glib::KeyFileError
Glib::FileError

Definition at line 86 of file keyfile.cc.

References gobj().

◆ load_from_dirs() [1/2]

G_GNUC_BEGIN_IGNORE_DEPRECATIONS bool Glib::KeyFile::load_from_dirs ( const std::string &  file,
const Glib::ArrayHandle< std::string > &  search_dirs,
Glib::ArrayHandle< std::string > &  full_path,
KeyFileFlags  flags = Glib::KEY_FILE_NONE 
)

This function looks for a key file named file in the paths specified in search_dirs, loads the file into key_file and returns the file's full path in full_path.

If the file could not be found in any of the search_dirs, KEY_FILE_ERROR_NOT_FOUND is returned. If the file is found but the OS returns an error when opening or reading the file, a FILE_ERROR is returned. If there is a problem parsing the file, a KEY_FILE_ERROR is returned.

Since @PACKAGE_NAME@ 2.14:
Deprecated:
Use the load_from_dirs() method that takes a std::string& full_path.
Parameters
fileA relative path to a filename to open and parse.
search_dirsnullptr-terminated array of directories to search.
full_pathReturn location for a string containing the full path of the file, or nullptr.
flagsFlags from KeyFileFlags.
Returns
true if a key file could be loaded, false otherwise.
Exceptions
Glib::KeyFileError
Glib::FileError

Definition at line 456 of file keyfile.cc.

References Glib::ArrayHandle< T, Tr >::data(), and gobj().

◆ load_from_dirs() [2/2]

bool Glib::KeyFile::load_from_dirs ( const std::string &  file,
const Glib::ArrayHandle< std::string > &  search_dirs,
std::string &  full_path,
KeyFileFlags  flags = Glib::KEY_FILE_NONE 
)

This function looks for a key file named file in the paths specified in search_dirs, loads the file into key_file and returns the file's full path in full_path.

If the file could not be found in any of the search_dirs, KEY_FILE_ERROR_NOT_FOUND is returned. If the file is found but the OS returns an error when opening or reading the file, a FILE_ERROR is returned. If there is a problem parsing the file, a KEY_FILE_ERROR is returned.

Since @PACKAGE_NAME@ 2.14:
Parameters
fileA relative path to a filename to open and parse.
search_dirsnullptr-terminated array of directories to search.
full_pathReturn location for a string containing the full path of the file, or nullptr.
flagsFlags from KeyFileFlags.
Returns
true if a key file could be loaded, false otherwise.
Exceptions
Glib::KeyFileError
Glib::FileError

Definition at line 106 of file keyfile.cc.

References Glib::ArrayHandle< T, Tr >::data(), and gobj().

◆ load_from_file()

bool Glib::KeyFile::load_from_file ( const std::string &  file,
KeyFileFlags  flags = Glib::KEY_FILE_NONE 
)

Loads a key file into an empty KeyFile instance.

If the file could not be loaded then a FileError or KeyFileError exception is thrown.

Since @PACKAGE_NAME@ 2.6:
Exceptions
Glib::FileError
Glib::KeyFileError
Parameters
fileThe path of a filename to load, in the GLib filename encoding.
flagsFlags from KeyFileFlags.
Returns
true if a key file could be loaded, false otherwise.

Definition at line 445 of file keyfile.cc.

References gobj().

◆ operator=() [1/2]

KeyFile& Glib::KeyFile::operator= ( const KeyFile )
delete

◆ operator=() [2/2]

KeyFile & Glib::KeyFile::operator= ( KeyFile &&  other)
noexcept

Definition at line 51 of file keyfile.cc.

◆ remove_comment()

void Glib::KeyFile::remove_comment ( const Glib::ustring group_name,
const Glib::ustring key 
)

Removes a comment above key from group_name.

If key is nullptr then comment will be removed above group_name. If both key and group_name are nullptr, then comment will be removed above the first group in the file.

Exceptions
Glib::KeyFileError
Parameters
group_nameA group name, or nullptr.
keyA key.

Definition at line 634 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ remove_group()

void Glib::KeyFile::remove_group ( const Glib::ustring group_name)

Removes the specified group, group_name, from the key file.

Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.

Definition at line 650 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ remove_key()

void Glib::KeyFile::remove_key ( const Glib::ustring group_name,
const Glib::ustring key 
)

Removes key in group_name from the key file.

Exceptions
Glib::KeyFileError
Parameters
group_nameA group name.
keyA key name to remove.

Definition at line 642 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ save_to_file()

G_GNUC_END_IGNORE_DEPRECATIONS bool Glib::KeyFile::save_to_file ( const std::string &  filename)

Writes the contents of key_file to filename using g_file_set_contents().

This function can fail for any of the reasons that g_file_set_contents() may fail.

Since @PACKAGE_NAME@ 2.40:
Parameters
filenameThe name of the file to write to.
Returns
true if successful, else false with error set.
Exceptions
Glib::FileError

Definition at line 467 of file keyfile.cc.

References gobj().

◆ set_boolean()

void Glib::KeyFile::set_boolean ( const Glib::ustring group_name,
const Glib::ustring key,
bool  value 
)

Associates a new boolean value with key under group_name.

If key cannot be found then it is created.

Since @PACKAGE_NAME@ 2.6:
Parameters
group_nameA group name.
keyA key.
valuetrue or false.

Definition at line 606 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ set_boolean_list()

void Glib::KeyFile::set_boolean_list ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ArrayHandle< bool > &  list 
)

Sets a list of booleans for the key under group_name.

If either the key or group_name cannot be found they are created.

Parameters
group_nameThe name of a group
keyThe name of a key
listA list holding object of type bool

Definition at line 365 of file keyfile.cc.

References Glib::ustring::c_str(), Glib::ArrayHandle< T, Tr >::data(), gobj(), and Glib::ArrayHandle< T, Tr >::size().

◆ set_comment() [1/3]

void Glib::KeyFile::set_comment ( const Glib::ustring comment)

Places comment at the start of the file, before the first group.

Parameters
commentThe Comment
Exceptions
Glib::KeyFileError

Definition at line 396 of file keyfile.cc.

References GLIBMM_THROW, and gobj().

◆ set_comment() [2/3]

void Glib::KeyFile::set_comment ( const Glib::ustring group_name,
const Glib::ustring comment 
)

Places comment above group_name.

Parameters
group_nameThe Group the comment should be above
commentThe comment
Exceptions
Glib::KeyFileError

Definition at line 405 of file keyfile.cc.

References GLIBMM_THROW, and gobj().

◆ set_comment() [3/3]

void Glib::KeyFile::set_comment ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring comment 
)

Places a comment above key from group_name.

If key is nullptr then comment will be written above group_name.
If both key and group_name are nullptr, then comment will be written above the first group in the file.

Exceptions
Glib::KeyFileError
Parameters
group_nameA group name, or nullptr.
keyA key.
commentA comment.

Definition at line 626 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ set_double() [1/2]

void Glib::KeyFile::set_double ( const Glib::ustring group_name,
const Glib::ustring key,
double  value 
)

Associates a new double value with key under group_name.

If key cannot be found then it is created.

Since @PACKAGE_NAME@ 2.12:
Parameters
group_nameA group name.
keyA key.
valueA double value.

Definition at line 572 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ set_double() [2/2]

void Glib::KeyFile::set_double ( const Glib::ustring key,
double  value 
)

Associates a new double value with key under the start group.

If key cannot be found then it is created.

Since @PACKAGE_NAME@ 2.12:
Parameters
keyA key.
valueAn double value.

Definition at line 248 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ set_double_list()

void Glib::KeyFile::set_double_list ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ArrayHandle< double > &  list 
)

Sets a list of doubles for the key under group_name.

If either the key or group_name cannot be found they are created.

Parameters
group_nameThe name of a group
keyThe name of a key
listA list holding object of type int
Since @PACKAGE_NAME@ 2.14:

Definition at line 357 of file keyfile.cc.

References Glib::ustring::c_str(), Glib::ArrayHandle< T, Tr >::data(), gobj(), and Glib::ArrayHandle< T, Tr >::size().

◆ set_int64()

void Glib::KeyFile::set_int64 ( const Glib::ustring group_name,
const Glib::ustring key,
gint64  value 
)

Associates a new integer value with key under group_name.

If key cannot be found then it is created.

Since @PACKAGE_NAME@ 2.26:
Parameters
group_nameA group name.
keyA key.
valueAn integer value.

Definition at line 616 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ set_integer()

void Glib::KeyFile::set_integer ( const Glib::ustring group_name,
const Glib::ustring key,
int  value 
)

Associates a new integer value with key under group_name.

If key cannot be found then it is created.

Since @PACKAGE_NAME@ 2.6:
Parameters
group_nameA group name.
keyA key.
valueAn integer value.

Definition at line 611 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ set_integer_list()

void Glib::KeyFile::set_integer_list ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ArrayHandle< int > &  list 
)

Sets a list of integers for the key under group_name.

If either the key or group_name cannot be found they are created.

Parameters
group_nameThe name of a group
keyThe name of a key
listA list holding object of type int

Definition at line 349 of file keyfile.cc.

References Glib::ustring::c_str(), Glib::ArrayHandle< T, Tr >::data(), gobj(), and Glib::ArrayHandle< T, Tr >::size().

◆ set_list_separator()

void Glib::KeyFile::set_list_separator ( gchar  separator)

Sets the character which is used to separate values in lists.

Typically ';' or ',' are used as separators. The default list separator is ';'.

Since @PACKAGE_NAME@ 2.6:
Parameters
separatorThe separator.

Definition at line 586 of file keyfile.cc.

References gobj().

◆ set_locale_string()

void Glib::KeyFile::set_locale_string ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring locale,
const Glib::ustring string 
)

Associates a string value for key and locale under group_name.

If the translation for key cannot be found then it is created.

Since @PACKAGE_NAME@ 2.6:
Parameters
group_nameA group name.
keyA key.
localeA locale identifier.
stringA string.

Definition at line 601 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ set_locale_string_list()

void Glib::KeyFile::set_locale_string_list ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring locale,
const Glib::ArrayHandle< Glib::ustring > &  list 
)

Sets a list of string values for the key under group_name and marks them as being for locale.

If the key or group_name cannot be found, they are created.

Parameters
group_nameThe name of a group
keyThe name of a key
localeA locale
listA list holding objects of type Glib::ustring

Definition at line 341 of file keyfile.cc.

References Glib::ustring::c_str(), Glib::ArrayHandle< T, Tr >::data(), gobj(), and Glib::ArrayHandle< T, Tr >::size().

◆ set_string()

void Glib::KeyFile::set_string ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring string 
)

Associates a new string value with key under group_name.


If key cannot be found then it is created.
If group_name cannot be found then it is created. Unlike g_key_file_set_value(), this function handles characters that need escaping, such as newlines.

Since @PACKAGE_NAME@ 2.6:
Parameters
group_nameA group name.
keyA key.
stringA string.

Definition at line 596 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ set_string_list()

void Glib::KeyFile::set_string_list ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ArrayHandle< Glib::ustring > &  list 
)

Sets a list of string values for key under group_name.

If key cannot be found it is created. If group_name cannot be found it is created.

Parameters
group_nameThe name of a group
keyThe name of a key
listA list holding objects of type Glib::ustring

Definition at line 333 of file keyfile.cc.

References Glib::ustring::c_str(), Glib::ArrayHandle< T, Tr >::data(), gobj(), and Glib::ArrayHandle< T, Tr >::size().

◆ set_uint64()

void Glib::KeyFile::set_uint64 ( const Glib::ustring group_name,
const Glib::ustring key,
guint64  value 
)

Associates a new integer value with key under group_name.

If key cannot be found then it is created.

Since @PACKAGE_NAME@ 2.26:
Parameters
group_nameA group name.
keyA key.
valueAn integer value.

Definition at line 621 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ set_value()

void Glib::KeyFile::set_value ( const Glib::ustring group_name,
const Glib::ustring key,
const Glib::ustring value 
)

Associates a new value with key under group_name.


If key cannot be found then it is created. If group_name cannot be found then it is created. To set an UTF-8 string which may contain characters that need escaping (such as newlines or spaces), use g_key_file_set_string().

Since @PACKAGE_NAME@ 2.6:
Parameters
group_nameA group name.
keyA key.
valueA string.

Definition at line 591 of file keyfile.cc.

References Glib::ustring::c_str(), and gobj().

◆ to_data()

Glib::ustring Glib::KeyFile::to_data ( )

Outputs the KeyFile as a string.

Returns
A string object holding the contents of KeyFile
Exceptions
Glib::KeyFileError

Definition at line 134 of file keyfile.cc.

References gobj().

Member Data Documentation

◆ gobject_

GKeyFile* Glib::KeyFile::gobject_
protected

Definition at line 927 of file keyfile.h.

Referenced by gobj(), KeyFile(), and ~KeyFile().

◆ owns_gobject_

bool Glib::KeyFile::owns_gobject_
protected

Definition at line 928 of file keyfile.h.

Referenced by KeyFile(), and ~KeyFile().


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