xtd - Reference Guide  0.1.2
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
settings.h
Go to the documentation of this file.
1
4#pragma once
5#include <memory>
6#include <xtd/object.h>
7#include <xtd/ustring.h>
8#include "../forms_export.h"
9
11namespace xtd {
13 namespace forms {
26 class forms_export_ settings : public object {
27 public:
31 ~settings();
33
38 xtd::ustring read(const xtd::ustring& key, const xtd::ustring& default_value) {return read_string(key, default_value);}
44 template<typename type_t>
45 type_t read(const xtd::ustring& key, const type_t& default_value) {
46 return xtd::parse<type_t>(read_string(key, xtd::ustring::format("{}", default_value)));
47 }
48
50 void reset();
51
53 void save();
54
58 void write(const xtd::ustring& key, const xtd::ustring& value) {write_string(key, value);}
59
64 template<typename type_t>
65 void write(const xtd::ustring& key, type_t&& value) {
66 write_string(key, xtd::ustring::format("{}", value));
67 }
68
69 private:
70 xtd::ustring read_string(const xtd::ustring& key, const xtd::ustring& default_value);
71 void write_string(const xtd::ustring& key, const xtd::ustring& value);
72 struct data {
73 intptr_t settings_;
74 };
75
76 std::shared_ptr<data> data_ = std::make_shared<data>();
77 };
78 }
79}
Represent settings associate to the application.
Definition settings.h:26
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.
Definition settings.h:45
void reset()
Reset application settings.
void write(const xtd::ustring &key, const xtd::ustring &value)
Writes a specified value for specified key.
Definition settings.h:58
void save()
Save application settings.
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.
Definition settings.h:38
void write(const xtd::ustring &key, type_t &&value)
Writes a specified value for specified key.
Definition settings.h:65
settings()
Initializes a new instance of settings class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:26
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:48
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition ustring.h:689
#define forms_export_
Define shared library export.
Definition forms_export.h:13
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition system_report.h:17
Contains xtd::object class.
Contains xtd::ustring class.