xtd 0.2.0
settings.h
Go to the documentation of this file.
1 #pragma once
5 #include "../forms_export.h"
6 #include <xtd/object>
7 #include <xtd/ustring>
8 #include <memory>
9 
11 namespace xtd {
13  namespace forms {
28  class forms_export_ settings : public object {
29  struct data;
30 
31  public:
33 
36  settings();
38 
40  ~settings();
42 
44 
50  xtd::ustring read(const xtd::ustring& key, const xtd::ustring& default_value) {return read_string(key, default_value);}
56  template<typename type_t>
57  type_t read(const xtd::ustring& key, const type_t& default_value) {
58  return xtd::parse<type_t>(read_string(key, xtd::ustring::format("{}", default_value)));
59  }
60 
62  void reset();
63 
65  void save();
66 
70  void write(const xtd::ustring& key, const xtd::ustring& value) {write_string(key, value);}
71 
76  template<typename type_t>
77  void write(const xtd::ustring& key, type_t&& value) {
78  write_string(key, xtd::ustring::format("{}", value));
79  }
81 
82  private:
83  xtd::ustring read_string(const xtd::ustring& key, const xtd::ustring& default_value);
84  void write_string(const xtd::ustring& key, const xtd::ustring& value);
85 
86  std::shared_ptr<data> data_;
87  };
88  }
89 }
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represent settings associate to the application.
Definition: settings.h:28
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
void write(const xtd::ustring &key, const xtd::ustring &value)
Writes a specified value for specified key.
Definition: settings.h:70
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:50
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
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:57
void write(const xtd::ustring &key, type_t &&value)
Writes a specified value for specified key.
Definition: settings.h:77
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:744
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13