xtd 1.0.0
Loading...
Searching...
No Matches
settings.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../core_export.hpp"
6#include "../object.hpp"
7#include "../string.hpp"
8#include <memory>
9
11namespace xtd {
13 namespace configuration {
179 struct data;
180
181 public:
183
188
190
205 auto file_path() const noexcept -> const xtd::string&;
207
209
215 [[nodiscard]] auto read(const xtd::string& key, const xtd::string& default_value) -> xtd::string;
221 template<typename type_t>
222 [[nodiscard]] auto read(const xtd::string& key, const type_t& default_value) -> type_t {
223 return xtd::parse<type_t>(read_string(key, xtd::string::format("{}", default_value)));
224 }
225
229 auto reset() -> void;
230
233 auto save() -> void;
234
239 auto write(const xtd::string& key, const xtd::string& value) -> void;
245 template<typename type_t>
246 auto write(const xtd::string& key, type_t&& value) -> void {
247 write_string(key, xtd::string::format("{}", value));
248 }
249
250
251 private:
252 [[nodiscard]] auto read_string(const xtd::string& key, const xtd::string& default_value) -> xtd::string;
253 auto write_string(const xtd::string& key, const xtd::string& value) -> void;
254
255 xtd::sptr<data> data_;
256 };
257 }
258}
auto file_path() const noexcept -> const xtd::string &
Gets the file path of the application settings.
auto save() -> void
Save application settings.
auto write(const xtd::string &key, type_t &&value) -> void
Writes a specified value for specified key.
Definition settings.hpp:246
auto reset() -> void
Reset application settings.
auto write(const xtd::string &key, const xtd::string &value) -> void
Writes a specified value for specified key.
settings()
Initializes a new instance of settings class.
auto read(const xtd::string &key, const xtd::string &default_value) -> xtd::string
Reads a value for specified key. If not found default value is used.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Contains core_export_ keyword.
static auto format(const basic_string< char > &fmt, args_t &&... args) -> basic_string
#define core_export_
Define shared library export.
Definition core_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
auto parse(const std::string &str) -> value_t
Convert a string into a type.
Definition parse.hpp:34
Contains the types that provide the programming model for handling configuration data.
Definition file_settings.hpp:17
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr auto data() const noexcept -> const_pointer
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:197
Contains xtd::object class.
Contains xtd::string alias.