Editor API
UnigineEditor public API
SettingManager.h
1 // Copyright (C), UNIGINE. All rights reserved.
2 #pragma once
3 
4 #include <editor/EditorGlobal.h>
5 
6 #include <UnigineString.h>
7 #include <UnigineGUID.h>
8 
9 
10 namespace Editor
11 {
12 
13 class EDITOR_API SettingsParameters
14 {
15 public:
16  virtual ~SettingsParameters();
17 
18  virtual bool contains(const char *full_parameter_name) const = 0;
19  virtual bool remove(const char *full_parameter_name) = 0;
20 
21  virtual void setInt(const char *full_parameter_name, int value) = 0;
22  virtual int getInt(const char *full_parameter_name, int default_value = 0) const = 0;
23 
24  virtual void setInt64(const char *full_parameter_name, int64_t value) = 0;
25  virtual int64_t getInt64(const char *full_parameter_name, int64_t default_value = 0) const = 0;
26 
27  virtual void setFloat(const char *full_parameter_name, float value) = 0;
28  virtual float getFloat(const char *full_parameter_name, float default_value = 0) const = 0;
29 
30  virtual void setDouble(const char *full_parameter_name, double value) = 0;
31  virtual double getDouble(const char *full_parameter_name, double default_value = 0) const = 0;
32 
33  virtual void setBool(const char *full_parameter_name, bool value) = 0;
34  virtual bool getBool(const char *full_parameter_name, bool default_value = false) const = 0;
35 
36  virtual void setGUID(const char *full_parameter_name, const Unigine::UGUID &value) = 0;
37  virtual Unigine::UGUID getGUID(const char *full_parameter_name,
38  const Unigine::UGUID &default_value = Unigine::UGUID::empty) const = 0;
39 
40  virtual void setString(const char *full_parameter_name, const char *value) = 0;
41  virtual Unigine::StringStack<> getString(const char *full_parameter_name,
42  const char *default_value = nullptr) const = 0;
43 };
44 
45 class EDITOR_API UserSettings : public SettingsParameters
46 {
47 public:
48  virtual const char *getPath() const = 0;
49 };
50 
51 class EDITOR_API SettingManager final
52 {
53 public:
54  static UserSettings &userSettings();
55 };
56 
57 namespace Utils
58 {
59 
61 {
62 public:
64  : sp{s}
65  , group_path(group)
66  {}
67 
68  bool contains(const char *parameter_name) const
69  {
70  return sp.contains(makeFullName(parameter_name).get());
71  }
72  void remove(const char *parameter_name)
73  {
74  sp.remove(makeFullName(parameter_name).get());
75  }
76 
77  void setInt(const char *parameter_name, int value)
78  {
79  sp.setInt(makeFullName(parameter_name).get(), value);
80  }
81  int getInt(const char *parameter_name, int default_value = 0) const
82  {
83  return sp.getInt(makeFullName(parameter_name).get(), default_value);
84  }
85 
86  void setInt64(const char *parameter_name, int64_t value)
87  {
88  sp.setInt64(makeFullName(parameter_name).get(), value);
89  }
90  int64_t getInt64(const char *parameter_name, int64_t default_value = 0) const
91  {
92  return sp.getInt64(makeFullName(parameter_name).get(), default_value);
93  }
94 
95  void setFloat(const char *parameter_name, float value)
96  {
97  sp.setFloat(makeFullName(parameter_name).get(), value);
98  }
99  float getFloat(const char *parameter_name, float default_value = 0.0) const
100  {
101  return sp.getFloat(makeFullName(parameter_name).get(), default_value);
102  }
103 
104  void setDouble(const char *parameter_name, double value)
105  {
106  sp.setDouble(makeFullName(parameter_name).get(), value);
107  }
108  double getDouble(const char *parameter_name, double default_value = 0.0) const
109  {
110  return sp.getDouble(makeFullName(parameter_name).get(), default_value);
111  }
112 
113  void setBool(const char *parameter_name, bool value)
114  {
115  sp.setBool(makeFullName(parameter_name).get(), value);
116  }
117  bool getBool(const char *parameter_name, bool default_value = 0) const
118  {
119  return sp.getBool(makeFullName(parameter_name).get(), default_value);
120  }
121 
122  void setGUID(const char *parameter_name, const Unigine::UGUID &value)
123  {
124  sp.setGUID(makeFullName(parameter_name).get(), value);
125  }
126  Unigine::UGUID getGUID(const char *parameter_name,
127  const Unigine::UGUID &default_value = Unigine::UGUID::empty) const
128  {
129  return sp.getGUID(makeFullName(parameter_name).get(), default_value);
130  }
131 
132  void setString(const char *parameter_name, const char *value)
133  {
134  sp.setString(makeFullName(parameter_name).get(), value);
135  }
136  Unigine::StringStack<> getString(const char *parameter_name,
137  const char *default_value = nullptr) const
138  {
139  return sp.getString(makeFullName(parameter_name).get(), default_value);
140  }
141 
142  Unigine::StringStack<> makeFullName(const char *parameter_name) const
143  {
144  return group_path + parameter_name;
145  }
146 
147 private:
148  SettingsParameters &sp;
149  const Unigine::StringStack<> group_path;
150 };
151 
152 } // namespace Utils
153 } // namespace Editor
virtual void setBool(const char *full_parameter_name, bool value)=0
virtual Unigine::UGUID getGUID(const char *full_parameter_name, const Unigine::UGUID &default_value=Unigine::UGUID::empty) const =0
Unigine::StringStack getString(const char *parameter_name, const char *default_value=nullptr) const
Definition: SettingManager.h:136
Definition: Actions.h:11
virtual void setInt64(const char *full_parameter_name, int64_t value)=0
Definition: SettingManager.h:51
virtual void setDouble(const char *full_parameter_name, double value)=0
virtual int getInt(const char *full_parameter_name, int default_value=0) const =0
Definition: SettingManager.h:13
double getDouble(const char *parameter_name, double default_value=0.0) const
Definition: SettingManager.h:108
virtual bool getBool(const char *full_parameter_name, bool default_value=false) const =0
virtual int64_t getInt64(const char *full_parameter_name, int64_t default_value=0) const =0
bool getBool(const char *parameter_name, bool default_value=0) const
Definition: SettingManager.h:117
virtual void setString(const char *full_parameter_name, const char *value)=0
Definition: SettingManager.h:45
virtual void setInt(const char *full_parameter_name, int value)=0
virtual double getDouble(const char *full_parameter_name, double default_value=0) const =0
virtual bool contains(const char *full_parameter_name) const =0
void setFloat(const char *parameter_name, float value)
Definition: SettingManager.h:95
int64_t getInt64(const char *parameter_name, int64_t default_value=0) const
Definition: SettingManager.h:90
Unigine::StringStack makeFullName(const char *parameter_name) const
Definition: SettingManager.h:142
float getFloat(const char *parameter_name, float default_value=0.0) const
Definition: SettingManager.h:99
void setString(const char *parameter_name, const char *value)
Definition: SettingManager.h:132
void setBool(const char *parameter_name, bool value)
Definition: SettingManager.h:113
void setGUID(const char *parameter_name, const Unigine::UGUID &value)
Definition: SettingManager.h:122
virtual Unigine::StringStack getString(const char *full_parameter_name, const char *default_value=nullptr) const =0
int getInt(const char *parameter_name, int default_value=0) const
Definition: SettingManager.h:81
virtual void setGUID(const char *full_parameter_name, const Unigine::UGUID &value)=0
void setDouble(const char *parameter_name, double value)
Definition: SettingManager.h:104
void setInt64(const char *parameter_name, int64_t value)
Definition: SettingManager.h:86
bool contains(const char *parameter_name) const
Definition: SettingManager.h:68
void setInt(const char *parameter_name, int value)
Definition: SettingManager.h:77
virtual float getFloat(const char *full_parameter_name, float default_value=0) const =0
virtual void setFloat(const char *full_parameter_name, float value)=0
virtual bool remove(const char *full_parameter_name)=0
void remove(const char *parameter_name)
Definition: SettingManager.h:72
Definition: SettingManager.h:60
SettingsParametersGroup(SettingsParameters &s, const char *group)
Definition: SettingManager.h:63
Unigine::UGUID getGUID(const char *parameter_name, const Unigine::UGUID &default_value=Unigine::UGUID::empty) const
Definition: SettingManager.h:126