Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
structs.hpp
Go to the documentation of this file.
1#ifndef IV_SRC_DIAMAR_STRUCTS_HPP_
2#define IV_SRC_DIAMAR_STRUCTS_HPP_
3
4#include "core/defines.hpp"
5#include "core/enums.hpp"
6#include "core/paths.hpp"
8#include "third_party/magic_enum/magic_enum.hpp"
9
10namespace iv::diamar
11{
12
14{
18
19 static std::optional<Preferences> load()
20 {
21 const auto preferencesFilePath = iv::paths::diamar::preferencesFilePath();
22
23 if (not iv::file::exists(preferencesFilePath))
24 {
25 return std::nullopt;
26 }
27
28 iv::file::xml::File preferencesFile(preferencesFilePath);
29 preferencesFile.read();
30 Preferences preferences;
31 preferences.load(preferencesFile.getChild(Sections::preferences));
32
33 return preferences;
34 }
35
36 static bool save(const Preferences &preferences)
37 {
38 const auto preferencesFilePath = iv::paths::diamar::preferencesFilePath();
39 iv::file::xml::File preferencesFile(preferencesFilePath);
40 auto node = preferencesFile.setChild(Sections::preferences);
41 preferences.save(node);
42
43 return preferencesFile.save();
44 }
45
46 bool load(const iv::file::xml::node &nodePreferences)
47 {
48 bool success {true};
49 const auto activeLangTmp = magic_enum::enum_cast<iv::eLanguage>(
51
52 activeLanguage = activeLangTmp.has_value() ? activeLangTmp.value() : DefaultValues::language;
53 success &= activeLangTmp.has_value();
54
55 const auto gmtOffsetTmp = magic_enum::enum_cast<iv::eGmtArea>(
57 gmtOffset = gmtOffsetTmp.has_value() ? gmtOffsetTmp.value() : DefaultValues::gmtOffset;
58 success &= gmtOffsetTmp.has_value();
59
61
62 return success;
63 }
64
65 bool save(iv::file::xml::node &nodePreferences) const
66 {
67 bool success {true};
68
69 success &= nodePreferences.addAttribute(Keys::activeLanguage, magic_enum::enum_name(activeLanguage));
70 success &= nodePreferences.addAttribute(Keys::gmtOffset, magic_enum::enum_name(gmtOffset));
71 success &= nodePreferences.addAttribute(Keys::volume, volume);
72
73 return success;
74 }
75
76private:
77 struct Sections
78 {
79 static constexpr std::string_view preferences {"Preferences"};
80 };
81
83 {
84 static constexpr std::string string {};
87 static constexpr iv::types::volume volume {128};
88 };
89
90 struct Keys
91 {
92 static constexpr std::string_view activeLanguage {"ActiveLanguage"};
93 static constexpr std::string_view gmtOffset {"GMTOffset"};
94 static constexpr std::string_view volume {"Volume"};
95 };
96};
97
98}// namespace iv::diamar
99
100#endif//IV_SRC_DIAMAR_STRUCTS_HPP_
Definition xmlFile.hpp:128
bool save()
Definition xmlFile.cpp:124
iv::file::xml::node getChild(std::string_view name) const
Definition xmlFile.cpp:170
bool read(bool checkIntegrity=true)
Definition xmlFile.cpp:99
iv::file::xml::node setChild(std::string_view name, std::string_view parentName="")
Definition xmlFile.cpp:182
Definition xmlFile.hpp:15
T getAttribute(const std::string_view key, T defaultValue) const
Definition xmlFile.hpp:33
bool addAttribute(const std::string_view key, T value)
Definition xmlFile.hpp:77
Definition DataLoggerManager.cpp:10
bool exists(const std::string_view path)
Definition file.cpp:97
std::string preferencesFilePath()
Definition paths.cpp:84
uint8_t volume
Definition types.hpp:25
eLanguage
Definition enums.hpp:37
eGmtArea
Definition enums.hpp:149
static constexpr iv::types::volume volume
Definition structs.hpp:87
static constexpr std::string string
Definition structs.hpp:84
static constexpr iv::eLanguage language
Definition structs.hpp:85
static constexpr iv::eGmtArea gmtOffset
Definition structs.hpp:86
Definition structs.hpp:91
static constexpr std::string_view volume
Definition structs.hpp:94
static constexpr std::string_view gmtOffset
Definition structs.hpp:93
static constexpr std::string_view activeLanguage
Definition structs.hpp:92
Definition structs.hpp:78
static constexpr std::string_view preferences
Definition structs.hpp:79
Definition structs.hpp:14
bool save(iv::file::xml::node &nodePreferences) const
Definition structs.hpp:65
bool load(const iv::file::xml::node &nodePreferences)
Definition structs.hpp:46
iv::eGmtArea gmtOffset
Definition structs.hpp:16
static std::optional< Preferences > load()
Definition structs.hpp:19
static bool save(const Preferences &preferences)
Definition structs.hpp:36
iv::types::volume volume
Definition structs.hpp:17
iv::eLanguage activeLanguage
Definition structs.hpp:15