neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
settings.hpp
Go to the documentation of this file.
1// settings.hpp
2/*
3 * Copyright (c) 2007, 2020 Leigh Johnston.
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * * Neither the name of Leigh Johnston nor the names of any
19 * other contributors to this software may be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#pragma once
37
38#include <neolib/neolib.hpp>
39#include <fstream>
40#include <set>
41#include <memory>
42#include <neolib/core/map.hpp>
47#include <neolib/file/xml.hpp>
48#include <neolib/task/event.hpp>
52
53namespace neolib
54{
55 class NEOLIB_EXPORT settings : public reference_counted<i_settings>
56 {
57 public:
58 define_declared_event(SettingChanging, setting_changing, const i_setting&)
59 define_declared_event(SettingChanged, setting_changed, const i_setting&)
60 define_declared_event(SettingDeleted, setting_deleted, const i_setting&)
61 define_declared_event(SettingsChanged, settings_changed, const i_string&)
62 private:
63 typedef map<string, string> category_titles;
64 typedef map<string, map<string, string>> group_titles;
65 typedef map<string, ref_ptr<i_setting>> setting_list;
67 public:
68 settings(const i_string& aFileName);
69 settings(const i_application& aApp, const i_string& aFileName = string{ "settings.xml" });
70 public:
74 void register_category(i_string const& aCategorySubkey, i_string const& aCategoryTitle = string{}) override;
75 void register_group(i_string const& aGroupSubkey, i_string const& aGroupTitle = string{}) override;
76 void register_setting(i_setting& aSetting) override;
77 category_titles const& all_categories() const override;
78 i_string const& category_title(i_string const& aCategorySubkey) const override;
79 group_titles const& all_groups() const override;
80 i_string const& group_title(i_string const& aGroupSubkey) const override;
81 setting_list const& all_settings() const override;
83 i_setting const& setting(i_string const& aKey) const override;
84 i_setting& setting(i_string const& aKey) override;
85 void change_setting(i_setting& aExistingSetting, const i_setting_value& aValue, bool aApplyNow = true) override;
86 void delete_setting(i_setting& aExistingSetting) override;
87 void apply_changes() override;
88 void discard_changes() override;
89 bool modified() const override;
90 public:
91 void register_friendly_text(i_setting const& aSetting, i_string const& aText, i_string const& aFriendlyText) override;
92 i_string const& friendly_text(i_setting const& aSetting, i_string const& aText) const override;
93 public:
94 void load() override;
95 void save() const override;
96 public:
97 void changing_setting(i_setting const& aSetting) override;
98 void changed_setting(i_setting const& aSetting) override;
99 private:
100 string iFileName;
101 mutable bool iModified = false;
102 bool iRegisteringSetting = false;
103 mutable std::unique_ptr<xml> iStore;
104 category_titles iCategoryTitles;
105 group_titles iGroupTitles;
106 setting_list iSettings;
107 setting_ordered_list iSettingsOrdered;
108 std::map<std::pair<i_setting const*, string>, string> iFriendlyText;
109 };
110}
virtual void register_group(i_string const &aGroupSubkey, i_string const &aGroupTitle=string{})=0
virtual void register_category(i_string const &aCategorySubkey, i_string const &aCategoryTitle=string{})=0
virtual void register_setting(i_setting &aSetting)=0
void apply_changes() override
void discard_changes() override
void changing_setting(i_setting const &aSetting) override
category_titles const & all_categories() const override
i_string const & group_title(i_string const &aGroupSubkey) const override
i_string const & friendly_text(i_setting const &aSetting, i_string const &aText) const override
setting_list const & all_settings() const override
void change_setting(i_setting &aExistingSetting, const i_setting_value &aValue, bool aApplyNow=true) override
i_string const & category_title(i_string const &aCategorySubkey) const override
group_titles const & all_groups() const override
i_setting const & setting(i_string const &aKey) const override
setting_ordered_list const & all_settings_ordered() const override
void load() override
bool modified() const override
void register_setting(i_setting &aSetting) override
i_setting & setting(i_string const &aKey) override
define_declared_event(SettingChanging, setting_changing, const i_setting &) define_declared_event(SettingChanged
void register_friendly_text(i_setting const &aSetting, i_string const &aText, i_string const &aFriendlyText) override
void register_group(i_string const &aGroupSubkey, i_string const &aGroupTitle=string{}) override
void changed_setting(i_setting const &aSetting) override
void save() const override
void delete_setting(i_setting &aExistingSetting) override
void register_category(i_string const &aCategorySubkey, i_string const &aCategoryTitle=string{}) override
#define define_declared_event(name, declName,...)
Definition event.hpp:195