xtd 0.2.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 {
178 class core_export_ settings : public object {
179 struct data;
180
181 public:
183
188
190
205 const xtd::string& file_path() const noexcept;
207
209
215 xtd::string read(const xtd::string& key, const xtd::string& default_value);
221 template<class type_t>
222 type_t read(const xtd::string& key, const type_t& default_value) {
223 return xtd::parse<type_t>(read_string(key, xtd::string::format("{}", default_value)));
224 }
225
229 void reset();
230
233 void save();
234
239 void write(const xtd::string& key, const xtd::string& value);
245 template<class type_t>
246 void write(const xtd::string& key, type_t&& value) {
247 write_string(key, xtd::string::format("{}", value));
248 }
249
250
251 private:
252 xtd::string read_string(const xtd::string& key, const xtd::string& default_value);
253 void write_string(const xtd::string& key, const xtd::string& value);
254
255 xtd::sptr<data> data_;
256 };
257 }
258}
void save()
Save application settings.
void write(const xtd::string &key, const xtd::string &value)
Writes a specified value for specified key.
const xtd::string & file_path() const noexcept
Gets the file path of the application settings.
xtd::string read(const xtd::string &key, const xtd::string &default_value)
Reads a value for specified key. If not found default value is used.
settings()
Initializes a new instance of settings class.
void write(const xtd::string &key, type_t &&value)
Writes a specified value for specified key.
Definition settings.hpp:246
void reset()
Reset application settings.
object()=default
Create a new instance of the ultimate base class object.
Contains core_export_ keyword.
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
#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
value_t parse(const std::string &str)
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 const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201
Contains xtd::object class.
Contains xtd::string alias.