xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Classes | Public Member Functions | List of all members
xtd::forms::settings Class Reference

#include <settings.h>

Definition

Represent settings associate to the application.

Namespace
xtd::forms
Library
xtd.forms
Remarks
On Windows settings are stored in registry with "HKEY_CURRENT_USER\Software\company_name\product_name" key or if no Company name "\HKEY_CURRENT_USER\Software\Product Name\Product Name" key.
On macos settings are stored in "~/Library/Preferences/product_name Preferences" file.
On linux settings are stored in "~/.product_name" file.
Examples
The following code example demonstrate the use of settings class.
#include <xtd/xtd>
#include "../properties/settings.h"
using namespace xtd::drawing;
using namespace xtd::forms;
int main() {
auto main_form = control::create<form>(settings_example::properties::settings::default_settings().text());
main_form->start_position(form_start_position::manual);
auto back_color_picker = control::create<color_picker>(*main_form, "", {10, 10}, {75, 25});
back_color_picker->color_changed += [&] {
main_form->back_color(back_color_picker->color());
};
auto save_button = control::create<button>(*main_form, "&Save", {90, 10});
save_button->click += [&] {
settings_example::properties::settings::default_settings().size(main_form->client_size());
settings_example::properties::settings::default_settings().location(main_form->location());
settings_example::properties::settings::default_settings().back_color(main_form->back_color());
settings_example::properties::settings::default_settings().save();
};
auto reload_button = control::create<button>(*main_form, "&Reload", {170, 10});
reload_button->click += [&] {
settings_example::properties::settings::default_settings().reload();
main_form->client_size(settings_example::properties::settings::default_settings().size());
main_form->location(settings_example::properties::settings::default_settings().location());
main_form->back_color(settings_example::properties::settings::default_settings().back_color());
back_color_picker->color(settings_example::properties::settings::default_settings().back_color());
};
auto reset_button = control::create<button>(*main_form, "R&eset", {250, 10});
reset_button->click += [&] {
settings_example::properties::settings::default_settings().reset();
reload_button->perform_click();
};
reload_button->perform_click();
application::run(*main_form);
}

Public Member Functions

 settings ()
 Initializes a new instance of settings class. More...
 
xtd::ustring read (const xtd::ustring &key, const xtd::ustring &default_value)
 Reads a value for specified key. If not found default value is used. More...
 
template<typename type_t >
type_t read (const xtd::ustring &key, const type_t &default_value)
 Reads a value for specified key. If not found default value is used. More...
 
void reset ()
 Reset application settings. More...
 
void save ()
 Save application settings. More...
 
void write (const xtd::ustring &key, const xtd::ustring &value)
 Writes a specified value for specified key. More...
 
template<typename type_t >
void write (const xtd::ustring &key, type_t &&value)
 Writes a specified value for specified key. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ settings()

xtd::forms::settings::settings ( )

Initializes a new instance of settings class.

Member Function Documentation

◆ read() [1/2]

xtd::ustring xtd::forms::settings::read ( const xtd::ustring key,
const xtd::ustring default_value 
)
inline

Reads a value for specified key. 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.

◆ read() [2/2]

template<typename type_t >
type_t xtd::forms::settings::read ( const xtd::ustring key,
const type_t &  default_value 
)
inline

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

Template Parameters
type_tThe type of value to read.
Parameters
keyThe key used to read a value.
default_valueA string used if value not found.
Returns
A type_t that represent the value associate to the key.

◆ reset()

void xtd::forms::settings::reset ( )

Reset application settings.

◆ save()

void xtd::forms::settings::save ( )

Save application settings.

◆ write() [1/2]

void xtd::forms::settings::write ( const xtd::ustring key,
const xtd::ustring value 
)
inline

Writes a specified value for specified key.

Parameters
keyThe key used to write a value.
valueA string to write.

◆ write() [2/2]

template<typename type_t >
void xtd::forms::settings::write ( const xtd::ustring key,
type_t &&  value 
)
inline

Writes a specified value for specified key.

Template Parameters
type_tThe type of value to write.
Parameters
keyThe key used to write a value.
valueA type_t to write.

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