xtd 0.2.0
Loading...
Searching...
No Matches
xtd::configuration::file_settings Class Reference
Inheritance diagram for xtd::configuration::file_settings:
xtd::object xtd::iequatable< file_settings > xtd::interface xtd::equality_operators< type_t, equatable_t >

Definition

Represents an object for storing and retrieving configuration information using text files in INI format.

Header
#include <xtd/configuration/file_settings>
Namespace
xtd
Library
xtd.core
Remarks
An INI file is a configuration file that consists of a text-based content with a structure and syntax comprising key–value pairs for properties, and sections that organize the properties.
Examples
The following code example demonstrates the use of xtd::configuration::file_settings class.
#include <xtd/configuration/file_settings>
#include <xtd/console>
using namespace xtd;
using namespace xtd::configuration;
auto write_file_settings() {
auto file = file_settings {"example.ini"};
file.top_file_comment("Settings file used by file_settings example.\nCopyright (c) 2024 Gammasoft. All rights reserved.");
file.write("auto_close", true);
file.write("caption", "file_settings example");
file.write("Thread \"Process\"", "timeout", 100_ms);
file.save();
}
auto reset_file_settings() {
auto file = file_settings {"example.ini"};
file.reset();
}
auto read_file_settings() {
auto file = file_settings {"example.ini"};
console::write_line("----------------------------------------");
console::write_line("\"exemple.ini\" file content :");
console::write_line(file.to_string());
console::write_line("----------------------------------------");
console::write_line("read keys :");
console::write_line("auto_close = {}", file.read("auto_close", false));
console::write_line("caption = {}", file.read("caption", "example"));
console::write_line("Thread \"Process\"", "time_out = {}", file.read("timeout", 50_ms));
console::write_line("----------------------------------------");
}
auto main() -> int {
write_file_settings();
// Uncomment the following line to see what happens if the "example.ini" file doesn't exist.
//reset_file_settings();
read_file_settings();
}
// This code produces the following output :
//
// ----------------------------------------
// "exemple.ini" file content :
// # Settings file used by file_settings example.
// # Copyright (c) 2024 Gammasoft. All rights reserved.
//
// auto_close = true
// caption = file_settings example
//
// [Thread "Process"]
// timeout = 00:00:00.1000000
//
// ----------------------------------------
// read keys :
// auto_close = true
// caption = file_settings example
// Thread "Process"
// ----------------------------------------
Represents an object for storing and retrieving configuration information using text files in INI for...
Definition file_settings.h:32
xtd::string top_file_comment() const noexcept
Gets top file comment text.
void reset()
Reset current settings.
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Contains the types that provide the programming model for handling configuration data.
Definition file_settings.h:17
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Examples
file_settings.cpp.

Protected Member Functions

virtual xtd::string convert_comment_to_text (const xtd::string &text) const noexcept
 
virtual xtd::string convert_text_to_comment (const xtd::string &text) const noexcept
 

Public Aliass

using string_dictionary = xtd::collections::generic::sorted_dictionary< xtd::string, xtd::string >
 Represents a xtd::collections::generic::sorted_dictionary with the key and the value strongly typed to be strings.
 
using string_collection = xtd::collections::specialized::string_collection
 Represents a collection of strings.
 

Public Constructors

 file_settings () noexcept=default
 Initialize an xtd::configuration::file_settings without loading a file.
 
 file_settings (const xtd::string &file_path)
 Initialize an xtd::configuration::file_settings with file path to load and save.
 
 file_settings (std::iostream &stream)
 Initialize an xtd::configuration::file_settings with a stream to load and save.
 

Public Properties

bool auto_save () const noexcept
 Gets whether save should be called on the xtd::configuration::file_settings destructor.
 
void auto_save (bool value) noexcept
 Sets whether save should be called on the xtd::configuration::file_settings destructor.
 
xtd::string bottom_file_comment () const noexcept
 Gets bottom file comment text.
 
file_settingsbottom_file_comment (const xtd::string &value) noexcept
 Sets bottom file comment text.
 
const xtd::stringfile_path () const noexcept
 Gets the file path of the current instance.
 
string_dictionary key_values () const noexcept
 Gets all key-value pairs from global section.
 
string_dictionary key_values (const xtd::string &section) const noexcept
 Gets all key-value pairs from a specified section.
 
string_collection keys () const noexcept
 Gets all keys from global section.
 
string_collection keys (const xtd::string &section) const noexcept
 Gets all keys from a specified section.
 
string_collection sections () const noexcept
 Gets all sections.
 
std::optional< std::reference_wrapper< std::iostream > > stream () const noexcept
 Gets the stream of the current instance.
 
xtd::string top_file_comment () const noexcept
 Gets top file comment text.
 
file_settingstop_file_comment (const xtd::string &value) noexcept
 Sets top file comment text.
 

Public Methods

bool equals (const file_settings &obj) const noexcept override
 Indicates whether the current object is equal to another object of the same type.
 
virtual void from_string (const xtd::string &text)
 Sets the current settings with parsing the xtd::string in INI format.
 
void load (const xtd::string &file_path)
 Loads settings from specified file.
 
void load (std::istream &stream)
 Loads settings from specified stream.
 
xtd::string read (const xtd::string &key, const xtd::string &default_value) noexcept
 Reads a value for specified key in the global section. If not found default value is used.
 
template<typename type_t >
type_t read (const xtd::string &key, const type_t &default_value)
 Reads a value for specified key in the global section. If not found default value is used.
 
xtd::string read (const xtd::string &section, const xtd::string &key, const xtd::string &default_value) noexcept
 Reads a value for specified key in the specified section. If not found default value is used.
 
template<typename type_t >
type_t read (const xtd::string &section, const xtd::string &key, const type_t &default_value)
 Reads a value for specified key in the specified section. If not found default value is used.
 
void remove (const xtd::string &key) noexcept
 Removes the specified key from the global section.
 
void remove (const xtd::string &section, const xtd::string &key) noexcept
 Removes the specified key from the specified section.
 
void remove_all_keys () noexcept
 Removes all keys from the global section.
 
void remove_all_keys (const xtd::string &section) noexcept
 Removes all key from the specified section.
 
void reset ()
 Reset current settings.
 
void save ()
 Save current settings.
 
void save_as (const xtd::string &file_path)
 Save current settings in the specified file path.
 
void save_as (std::ostream &stream)
 Save current settings in the specified stream.
 
xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current setting in INI format.
 
void write (const xtd::string &key, const xtd::string &value) noexcept
 Writes a specified value for specified key in the global section.
 
template<typename type_t >
void write (const xtd::string &key, type_t &&value)
 Writes a specified value for specified key in the global section.
 
void write (const xtd::string &section, const xtd::string &key, const xtd::string &value) noexcept
 Writes a specified value for specified key in the specified section.
 
template<typename type_t >
void write (const xtd::string &section, const xtd::string &key, type_t &&value)
 Writes a specified value for specified key in the specified section.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 

Public Operators

const string_dictionaryoperator[] (const xtd::string &section) const noexcept
 Gets key-value pairs of the specified section.
 
string_dictionaryoperator[] (const xtd::string &section) noexcept
 Gets key-value pairs of the specified section.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::iequatable< file_settings >
virtual bool equals (const file_settings &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Member Typedef Documentation

◆ string_dictionary

◆ string_collection

Constructor & Destructor Documentation

◆ file_settings() [1/3]

xtd::configuration::file_settings::file_settings ( )
defaultnoexcept

Initialize an xtd::configuration::file_settings without loading a file.

Remarks
The xtd::configuration::file_settings::save method has no effect.
This is equivalent to using the xtd::configuration::file_settings constructor with an empty string as the file path.

◆ file_settings() [2/3]

xtd::configuration::file_settings::file_settings ( const xtd::string file_path)
explicit

Initialize an xtd::configuration::file_settings with file path to load and save.

Parameters
file_paththe file path to load and save.
Remarks
If the xtd::configuration::file_settings::auto_save is true the xtd::configuration::file_settings::save is called on the xtd::configuration::file_settings destructor; otherwise not, The xtd::configuration::file_settings::save method must be called manually.
xtd::configuration::file_settings::auto_save is false by default.
If the file path is empty, this is equivalent to using the xtd::configuration::file_settings constructor with no parameters.

◆ file_settings() [3/3]

xtd::configuration::file_settings::file_settings ( std::iostream &  stream)
explicit

Initialize an xtd::configuration::file_settings with a stream to load and save.

Parameters
streamthe stream to load and save.
Remarks
If the xtd::configuration::file_settings::auto_save is true the xtd::configuration::file_settings::save is called on the xtd::configuration::file_settings destructor; otherwise not, The xtd::configuration::file_settings::save method must be called manually.
xtd::configuration::file_settings::auto_save is false by default.
If the stream is empty, this is equivalent to using the xtd::configuration::file_settings constructor with no parameters.

Member Function Documentation

◆ auto_save() [1/2]

bool xtd::configuration::file_settings::auto_save ( ) const
noexcept

Gets whether save should be called on the xtd::configuration::file_settings destructor.

Returns
true if xtd::configuration::file_settings::save is called on the xtd::configuration::file_settings destructor; otherwise, false.
Remarks
The default is false.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::auto_save property, xtd::configuration::file_settings::write methods.
auto file = file_settings {"my_app.ini"};
file.auto_save(true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
bool auto_save() const noexcept
Gets whether save should be called on the xtd::configuration::file_settings destructor.
my_app.ini:
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ auto_save() [2/2]

void xtd::configuration::file_settings::auto_save ( bool  value)
noexcept

Sets whether save should be called on the xtd::configuration::file_settings destructor.

Parameters
valuetrue if xtd::configuration::file_settings::save is called on the xtd::configuration::file_settings destructor; otherwise, false.
Remarks
The default is false.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::auto_save property, xtd::configuration::file_settings::write methods.
auto file = file_settings {"my_app.ini"};
file.auto_save(true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
my_app.ini:
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ bottom_file_comment() [1/2]

xtd::string xtd::configuration::file_settings::bottom_file_comment ( ) const
noexcept

Gets bottom file comment text.

Returns
Bottom file comment text.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::bottom_file_comment property, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save_as methods.
auto file = file_settings {};
file.bottom_file_comment("Modifications must be made with care, as they may result in incorrect behavior.");
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save_as("my_app.ini")
xtd::string bottom_file_comment() const noexcept
Gets bottom file comment text.
my_app.ini:
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png
# Modifications must be made with care, as they may result in incorrect behavior.

◆ bottom_file_comment() [2/2]

file_settings & xtd::configuration::file_settings::bottom_file_comment ( const xtd::string value)
noexcept

Sets bottom file comment text.

Parameters
valueBottom file comment text.
Returns
This current instance.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::bottom_file_comment property, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save_as methods.
auto file = file_settings {};
file.bottom_file_comment("Modifications must be made with care, as they may result in incorrect behavior.");
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save_as("my_app.ini");
my_app.ini:
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png
# Modifications must be made with care, as they may result in incorrect behavior.

◆ file_path()

const xtd::string & xtd::configuration::file_settings::file_path ( ) const
noexcept

Gets the file path of the current instance.

Returns
The file path of the current instance.
Remarks
If no file the property can be return xtd::string::empty_string.
Warning
Don't manipulate the file yourself, otherwise the expected result may be undefined.

◆ key_values() [1/2]

string_dictionary xtd::configuration::file_settings::key_values ( ) const
noexcept

Gets all key-value pairs from global section.

Returns
The key-value pairs map.
Remarks
This method is equivalent to call xtd::configuration::file_settings::key_values (const xtd::string& section) with xtd::string::empty_string paramreter.

◆ key_values() [2/2]

string_dictionary xtd::configuration::file_settings::key_values ( const xtd::string section) const
noexcept

Gets all key-value pairs from a specified section.

Parameters
sectionThe section to get key-value pairs.
Returns
The key-value pairs map from the specified section.
Remarks
Use xtd::string::empty_string paramreter to get key-value pairs of the global section.

◆ keys() [1/2]

string_collection xtd::configuration::file_settings::keys ( ) const
noexcept

Gets all keys from global section.

Returns
The keys colection.
Remarks
This method is equivalent to call xtd::configuration::file_settings::keys (const xtd::string& section) with xtd::string::empty_string paramreter.

◆ keys() [2/2]

string_collection xtd::configuration::file_settings::keys ( const xtd::string section) const
noexcept

Gets all keys from a specified section.

Parameters
sectionThe section to get keys.
Returns
The keys collection from the specified section.
Remarks
Use xtd::string::empty_string paramreter to get keys of the global section.

◆ sections()

string_collection xtd::configuration::file_settings::sections ( ) const
noexcept

Gets all sections.

Returns
The sections colection.

◆ stream()

std::optional< std::reference_wrapper< std::iostream > > xtd::configuration::file_settings::stream ( ) const
noexcept

Gets the stream of the current instance.

Returns
The stream of the current instance.
Warning
Don't manipulate the stream yourself, otherwise the expected result may be undefined.

◆ top_file_comment() [1/2]

xtd::string xtd::configuration::file_settings::top_file_comment ( ) const
noexcept

Gets top file comment text.

Returns
Top file comment textr.
Remarks
Generally used to read descriptions of the xtd::configuration::file_settings : authors, copyright, version, etc.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::top_file_comment property, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save_as methods.
auto file = file_settings {};
file.top_file_comment("Contains settings for my_app application.\nCopyright, (c) 2024 MyCompany. All rights reserved.");
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save_as("my_app.ini");
my_app.ini:
# Contains settings for my_app application.
# Copyright, (c) 2024 MyCompany. All rights reserved.
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png
Examples
file_settings.cpp.

◆ top_file_comment() [2/2]

file_settings & xtd::configuration::file_settings::top_file_comment ( const xtd::string value)
noexcept

Sets top file comment text.

Parameters
valueTop file comment textr.
Returns
This current instance.
Remarks
Generally used to write descriptions of the xtd::configuration::file_settings : authors, copyright, version, etc.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::top_file_comment property, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save_as methods.
auto file = file_settings {};
file.top_file_comment("Contains settings for my_app application.\nCopyright, (c) 2024 MyCompany. All rights reserved.");
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save_as("my_app.ini");
my_app.ini:
# Contains settings for my_app application.
# Copyright, (c) 2024 MyCompany. All rights reserved.
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ equals() [1/3]

bool xtd::configuration::file_settings::equals ( const file_settings obj) const
overridenoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

◆ from_string()

virtual void xtd::configuration::file_settings::from_string ( const xtd::string text)
virtual

Sets the current settings with parsing the xtd::string in INI format.

Parameters
textA text to set the current setting.
Notes to inheritors
To create your own file_settings with another format, you just need to override the xtd::configuration::file_settings::from_string and xtd::configuration::file_settings::to_string methods.

◆ load() [1/2]

void xtd::configuration::file_settings::load ( const xtd::string file_path)

Loads settings from specified file.

Parameters
file_pathThe file path to load settings.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::load, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save_as methods.
auto file = file_settings {};
file.load("my_app.ini");
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save_as("my_app.ini");
void load(const xtd::string &file_path)
Loads settings from specified file.
my_app.ini:
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ load() [2/2]

void xtd::configuration::file_settings::load ( std::istream &  stream)

Loads settings from specified stream.

Parameters
streamThe stream to load settings.

◆ read() [1/4]

xtd::string xtd::configuration::file_settings::read ( const xtd::string key,
const xtd::string default_value 
)
noexcept

Reads a value for specified key in the global section. If not found default value is used.

Parameters
keyThe key used to read a value.
default_valueA string used if value not found.
Returns
A string that represent the value associate to the key.
Remarks
Use xtd::string::empty_string for section paramreter to read keys of the global section.
This method is equivalent to call xtd::configuration::file_settings::read (const xtd::string& section, const xtd::string& key, const xtd::string& default_value) with xtd::string::empty_string paramreter as section parameter.

◆ read() [2/4]

template<typename type_t >
type_t xtd::configuration::file_settings::read ( const xtd::string key,
const type_t &  default_value 
)
inline

Reads a value for specified key in the global section. If not found default value is used.

Parameters
keyThe key used to read a value.
default_valueA string used if value not found.
Returns
A string that represent the value associate to the key.
Remarks
Use xtd::string::empty_string for section paramreter to read keys of the global section.
This method is equivalent to call xtd::configuration::file_settings::read (const xtd::string& section, const xtd::string& key, const xtd::string& default_value) with xtd::string::empty_string paramreter as section parameter.

◆ read() [3/4]

xtd::string xtd::configuration::file_settings::read ( const xtd::string section,
const xtd::string key,
const xtd::string default_value 
)
noexcept

Reads a value for specified key in the specified section. If not found default value is used.

Parameters
sectionThe section where the key is read.
keyThe key used to read a value.
default_valueA string used if value not found.
Returns
A string that represent the value associate to the key.
Remarks
Use xtd::string::empty_string for section paramreter to read keys of the global section.

◆ read() [4/4]

template<typename type_t >
type_t xtd::configuration::file_settings::read ( const xtd::string section,
const xtd::string key,
const type_t &  default_value 
)
inline

Reads a value for specified key in the specified section. If not found default value is used.

Parameters
sectionThe section where the key is read.
keyThe key used to read a value.
default_valueA string used if value not found.
Returns
A string that represent the value associate to the key.
Remarks
Use xtd::string::empty_string for section paramreter to read keys of the global section.

◆ remove() [1/2]

void xtd::configuration::file_settings::remove ( const xtd::string key)
noexcept

Removes the specified key from the global section.

Parameters
keyThe key to remove from the global section.
Remarks
To write permanently use the xtd::configuration::file_settings::save method.
This method is equivalent to call xtd::configuration::file_settings::remove (const xtd::string& section) with xtd::string::empty_string paramreter.

Removes the specified key from the specified section.

Parameters
sectionThe section where the key is removed.
keyThe key to remove from the specified section.
Remarks
To write permanently use the xtd::configuration::file_settings::save method.
Use xtd::string::empty_string paramreter to remove key of the global section.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write, xtd::configuration::file_settings::remove and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write(quit_application_on_main_form_closed", true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.remove("quit_application_on_main_form_closed");
file.save();
my_app.ini:
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ remove() [2/2]

void xtd::configuration::file_settings::remove ( const xtd::string section,
const xtd::string key 
)
noexcept

Removes the specified key from the specified section.

Parameters
sectionThe section where the key is removed.
keyThe key to remove from the specified section.
Remarks
To write permanently use the xtd::configuration::file_settings::save method.
Use xtd::string::empty_string paramreter to remove key of the global section.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write, xtd::configuration::file_settings::remove and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write("main", "quit_application_on_main_form_closed", true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.remove("main", "quit_application_on_main_form_closed");
file.save();
my_app.ini:
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ remove_all_keys() [1/2]

void xtd::configuration::file_settings::remove_all_keys ( )
noexcept

Removes all keys from the global section.

Remarks
To write permanently use the xtd::configuration::file_settings::save method.
This method is equivalent to call xtd::configuration::file_settings::remove_all_keys (const xtd::string& section) with xtd::string::empty_string paramreter.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write, xtd::configuration::file_settings::remove_all_keys and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write("main", "quit_application_on_main_form_closed", true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.remove_all_keys();
file.save();
my_app.ini:
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ remove_all_keys() [2/2]

void xtd::configuration::file_settings::remove_all_keys ( const xtd::string section)
noexcept

Removes all key from the specified section.

Parameters
sectionThe section where all keys are removed.
Remarks
To write permanently use the xtd::configuration::file_settings::save method.
Use xtd::string::empty_string paramreter to remove all keys of the global section.
Use xtd::string::empty_string paramreter to remove key of the global section.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write, xtd::configuration::file_settings::remove_all_keys and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write("main", "quit_application_on_main_form_closed", true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.remove_all_keys("pictures \"Menu\"");
file.save()
my_app.ini:
[main]
quit_application_on_main_form_closed = true

◆ reset()

void xtd::configuration::file_settings::reset ( )

Reset current settings.

Remarks
The settings are cleared and the settings file is removed.
To write permanently use the xtd::configuration::settings::save method.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write("main", "quit_application_on_main_form_closed", true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save();
my_app.ini:
[main]
quit_application_on_main_form_closed = true
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png
Examples
file_settings.cpp.

◆ save()

void xtd::configuration::file_settings::save ( )

Save current settings.

Remarks
The settings are saved in the settings file.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write("main", "quit_application_on_main_form_closed", true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save();
my_app.ini:
[main]
quit_application_on_main_form_closed = true
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ save_as() [1/2]

void xtd::configuration::file_settings::save_as ( const xtd::string file_path)

Save current settings in the specified file path.

Parameters
file_pathThe file to save the current settings.
Remarks
The settings are saved in the specified settings file.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::write and xtd::configuration::file_settings::save_as methods.
auto file = file_settings {};
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save_as("my_app.ini")
void write(const xtd::string &key, const xtd::string &value) noexcept
Writes a specified value for specified key in the global section.
my_app.ini:
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ save_as() [2/2]

void xtd::configuration::file_settings::save_as ( std::ostream &  stream)

Save current settings in the specified stream.

Parameters
streamThe stream to save the current settings.
Remarks
The settings are saved in the specified settings stream.

◆ to_string()

xtd::string xtd::configuration::file_settings::to_string ( ) const
overridevirtualnoexcept

Returns a xtd::string that represents the current setting in INI format.

Returns
A string that represents the current setting.
Notes to inheritors
To create your own file_settings with another format, you just need to override the xtd::configuration::file_settings::from_string and xtd::configuration::file_settings::to_string methods.

Reimplemented from xtd::object.

◆ write() [1/4]

void xtd::configuration::file_settings::write ( const xtd::string key,
const xtd::string value 
)
noexcept

Writes a specified value for specified key in the global section.

Parameters
keyThe key used to write a value.
valueA string to write.
Remarks
To write permanently use the xtd::configuration::file_settings::save method.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write("quit_application_on_main_form_closed", "true");
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save();
my_app.ini:
quit_application_on_main_form_closed = true
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ write() [2/4]

template<typename type_t >
void xtd::configuration::file_settings::write ( const xtd::string key,
type_t &&  value 
)
inline

Writes a specified value for specified key in the global section.

Parameters
keyThe key used to write a value.
valueA string to write.
Remarks
To write permanently use the xtd::configuration::file_settings::save method.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write("quit_application_on_main_form_closed", true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save();
my_app.ini:
quit_application_on_main_form_closed = true
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ write() [3/4]

void xtd::configuration::file_settings::write ( const xtd::string section,
const xtd::string key,
const xtd::string value 
)
noexcept

Writes a specified value for specified key in the specified section.

Parameters
sectionThe section where the key is write.
keyThe key used to write a value.
valueA string to write.
Remarks
To write permanently use the xtd::configuration::file_settings::save method.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write("quit_application_on_main_form_closed", "true");
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png");
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save();
my_app.ini:
quit_application_on_main_form_closed = true
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ write() [4/4]

template<typename type_t >
void xtd::configuration::file_settings::write ( const xtd::string section,
const xtd::string key,
type_t &&  value 
)
inline

Writes a specified value for specified key in the specified section.

Parameters
sectionThe section where the key is write.
keyThe key used to write a value.
valueA string to write.
Remarks
To write permanently use the xtd::configuration::file_settings::save method.
Examples
The following example shows how to create xtd::configuration::file_settings and use xtd::configuration::file_settings::reset, xtd::configuration::file_settings::write and xtd::configuration::file_settings::save methods.
auto file = file_settings {"my_app.ini"};
file.reset();
file.write("main", "quit_application_on_main_form_closed", true);
file.write("pictures \"Menu\"", "file_open", "resources/symbolic_open.png")
file.write("pictures \"Menu\"", "file_save", "resources/symbolic_save.png");
file.save();
my_app.ini:
[main]
quit_application_on_main_form_closed = true
[pictures "Menu"]
file_open = resources/symbolic_open.png
file_save = resources/symbolic_save.png

◆ operator[]() [1/2]

const string_dictionary & xtd::configuration::file_settings::operator[] ( const xtd::string section) const
noexcept

Gets key-value pairs of the specified section.

Parameters
secionThe section to get the key-value pairs
Returns
The key-value pairs of the section.
Examples
Use this operator to read value from section like xtd::configuration::file_settings::read method.
auto fs = file_settings {"my_file.ini"};
auto v1 = fs["section1"]["key1"];
// Is equivalent to call :
// auto v1 = fs.read("section1", "key1", string::empty_string);

◆ operator[]() [2/2]

string_dictionary & xtd::configuration::file_settings::operator[] ( const xtd::string section)
noexcept

Gets key-value pairs of the specified section.

Parameters
secionThe section to get the key-value pairs
Returns
The key-value pairs of the section.
Examples
Use this operator to write value to section like xtd::configuration::file_settings::write method.
auto fs = file_settings {"my_file.ini"};
fs["section1"]["key1"] = "value1";
// Is equivalent to call :
// fs.write("section1", "key1", "value1");

◆ equals() [2/3]

virtual bool xtd::object::equals ( const object obj) const
virtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.
Examples
The following code example compares the current instance with another object.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
auto object1 = new_ptr<object>();
auto object2 = new_ptr<object>();
auto object3 = object2;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
object3 = object1;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
}
// This code produces the following output :
//
// false
// false
// true
// true

Reimplemented from xtd::object.

◆ equals() [3/3]

template<typename object_a_t , typename object_b_t >
static bool xtd::object::equals ( const object_a_t &  object_a,
const object_b_t &  object_b 
)
inlinestaticnoexcept

Determines whether the specified object instances are considered equal.

Parameters
object_aThe first object to compare.
object_bThe second object to compare.
Returns
true if object_a is the same instance as object_b or if both are null references or if object_a(object_b) returns true. otherwise, false.
Examples
The following code example compares different objects.
#include <xtd/console>
using namespace xtd;
auto main() -> int {
string s1 = "Tom";
string s2 = "Carol";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Tom";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "Tom";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "Carol";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
s1 = "";
s2 = "";
console::write_line("object::equals(\"{0}\", \"{1}\") => {2}", s1, s2, object::equals(s1, s2));
}
// This code produces the following output :
//
// object::equals("Tom", "Carol") => false
// object::equals("Tom", "Tom") => true
// object::equals("", "Tom") => false
// object::equals("Carol", "") => false
// object::equals("", "") => true
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.

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