neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_settings.hpp
Go to the documentation of this file.
1// i_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>
40#include <neolib/core/map.hpp>
42#include <neolib/core/uuid.hpp>
48
49namespace neolib
50{
51 template <typename T>
52 class setting;
53
54 template <typename T>
56 {
57 typedef T type;
58 };
59
60 template <typename T>
62
64 {
65 public:
67 public:
68 declare_event(setting_changing, const i_setting&)
69 declare_event(setting_changed, const i_setting&)
70 declare_event(setting_deleted, const i_setting&)
71 declare_event(settings_changed, const i_string&)
72 public:
73 struct setting_already_registered : std::logic_error { setting_already_registered() : std::logic_error("i_settings::setting_already_registered") {} };
74 struct category_not_found : std::logic_error { category_not_found() : std::logic_error("i_settings::category_not_found") {} };
75 struct group_not_found : std::logic_error { group_not_found() : std::logic_error("i_settings::group_not_found") {} };
76 struct setting_not_found : std::logic_error { setting_not_found() : std::logic_error("i_settings::setting_not_found") {} };
77 public:
78 virtual void register_category(i_string const& aCategorySubkey, i_string const& aCategoryTitle = string{}) = 0;
79 virtual void register_group(i_string const& aGroupSubkey, i_string const& aGroupTitle = string{}) = 0;
80 virtual void register_setting(i_setting& aSetting) = 0;
81 virtual i_map<i_string, i_string> const& all_categories() const = 0;
82 virtual i_string const& category_title(i_string const& aCategorySubkey) const = 0;
84 virtual i_string const& group_title(i_string const& aGroupSubkey) const = 0;
87 virtual i_setting const& setting(i_string const& aKey) const = 0;
88 virtual i_setting& setting(i_string const& aKey) = 0;
89 virtual void change_setting(i_setting& aExistingSetting, i_setting_value const& aValue, bool aApplyNow = true) = 0;
90 virtual void delete_setting(i_setting& aExistingSetting) = 0;
91 virtual void apply_changes() = 0;
92 virtual void discard_changes() = 0;
93 virtual bool modified() const = 0;
94 public:
95 virtual void register_friendly_text(i_setting const& aSetting, i_string const& aText, i_string const& aFriendlyText) = 0;
96 virtual i_string const& friendly_text(i_setting const& aSetting, i_string const& aText) const = 0;
97 public:
98 virtual void load() = 0;
99 virtual void save() const = 0;
100 public:
101 virtual void changing_setting(i_setting const& aSetting) = 0;
102 virtual void changed_setting(i_setting const& aSetting) = 0;
103 public:
104 static uuid const& iid() { static uuid sId = neolib::make_uuid("E19B3C48-04F7-4207-B24A-2967A3523CE7"); return sId; }
105 // helpers
106 public:
107 void register_category(string const& aCategorySubkey, string const& aCategoryTitle = string{})
108 {
109 register_category(static_cast<i_string const&>(aCategorySubkey), static_cast<i_string const&>(aCategoryTitle));
110 }
111 void register_group(string const& aGroupSubkey, string const& aGroupTitle = string{})
112 {
113 register_group(static_cast<i_string const&>(aGroupSubkey), static_cast<i_string const&>(aGroupTitle));
114 }
115 template <typename T>
116 i_setting& register_setting(string const& aKey, T const& aDefaultValue, setting_constraints<as_setting_t<T>> const& aSettingConstraints, string const& aFormat = {})
117 {
118 auto newSetting = make_ref<neolib::setting<as_setting_t<T>>>(*this, aKey, aDefaultValue, aSettingConstraints, aFormat);
119 register_setting(*newSetting);
120 return *newSetting;
121 }
122 template <typename T>
123 i_setting& register_setting(string const& aKey, T const& aDefaultValue, string const& aFormat = {})
124 {
125 return register_setting(aKey, aDefaultValue, {}, aFormat);
126 }
127 template <typename T>
128 void change_setting(i_setting& aExistingSetting, T const& aValue, bool aApplyNow = true)
129 {
130 change_setting(aExistingSetting, static_cast<i_setting_value const&>(setting_value<as_setting_t<T>>{ aValue }), aApplyNow);
131 }
132 };
133}
virtual i_map< i_string, i_string > const & all_categories() const =0
virtual void change_setting(i_setting &aExistingSetting, i_setting_value const &aValue, bool aApplyNow=true)=0
virtual void load()=0
virtual void changed_setting(i_setting const &aSetting)=0
virtual void register_friendly_text(i_setting const &aSetting, i_string const &aText, i_string const &aFriendlyText)=0
void register_group(string const &aGroupSubkey, string const &aGroupTitle=string{})
declare_event(setting_changing, const i_setting &) declare_event(setting_changed
virtual void discard_changes()=0
i_setting & register_setting(string const &aKey, T const &aDefaultValue, string const &aFormat={})
i_setting & register_setting(string const &aKey, T const &aDefaultValue, setting_constraints< as_setting_t< T > > const &aSettingConstraints, string const &aFormat={})
virtual bool modified() const =0
virtual i_map< i_string, i_ref_ptr< i_setting > > const & all_settings() const =0
virtual i_string const & group_title(i_string const &aGroupSubkey) const =0
static uuid const & iid()
virtual i_vector< i_ref_ptr< i_setting > > const & all_settings_ordered() const =0
virtual void register_group(i_string const &aGroupSubkey, i_string const &aGroupTitle=string{})=0
i_settings abstract_type
void register_category(string const &aCategorySubkey, string const &aCategoryTitle=string{})
void change_setting(i_setting &aExistingSetting, T const &aValue, bool aApplyNow=true)
virtual i_setting & setting(i_string const &aKey)=0
virtual void save() const =0
virtual void register_category(i_string const &aCategorySubkey, i_string const &aCategoryTitle=string{})=0
virtual void changing_setting(i_setting const &aSetting)=0
virtual i_string const & friendly_text(i_setting const &aSetting, i_string const &aText) const =0
virtual void register_setting(i_setting &aSetting)=0
virtual void apply_changes()=0
virtual i_map< i_string, i_map< i_string, i_string > > const & all_groups() const =0
virtual i_string const & category_title(i_string const &aCategorySubkey) const =0
virtual i_setting const & setting(i_string const &aKey) const =0
virtual void delete_setting(i_setting &aExistingSetting)=0
uuid make_uuid(const std::string &aHyphenatedHexString)
Definition uuid.hpp:62
typename as_setting< T >::type as_setting_t
Definition plf_hive.h:79
#define declare_event(declName,...)
Definition i_event.hpp:305