API Documentation
Loading...
Searching...
No Matches
GenericOptions.h
Go to the documentation of this file.
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/Pointer.h>
4#include <NDEVR/TypeInfo.h>
5#include <NDEVR/String.h>
6#include <NDEVR/Unit.h>
7#include <NDEVR/TranslatedString.h>
8#include <NDEVR/Dictionary.h>
9#include <NDEVR/Resource.h>
10namespace NDEVR
11{
12 /*struct GenericContainer
13 {
14 union ContainerValue
15 {
16 ContainerValue() {};
17 ~ContainerValue() {}
18 String string_value;
19 fltp08 fltp08_value;
20 fltp04 fltp04_value;
21 sint08 sint08_value;
22 uint08 uint08_value;
23 sint04 sint04_value;
24 uint04 uint04_value;
25 bool bool_value;
26 };
27 template<class t_type> GenericContainer(const t_type& value) { value.string_value = String(value); }
28 GenericContainer(const String& value) { m_value.string_value = value; }
29 GenericContainer(fltp08 value) { m_value.fltp08_value = value; }
30 GenericContainer(fltp04 value) { m_value.fltp04_value = value; }
31 GenericContainer(sint08 value) { m_value.sint08_value = value; }
32 GenericContainer(sint04 value) { m_value.sint04_value = value; }
33 GenericContainer(uint08 value) { m_value.uint08_value = value; }
34 GenericContainer(uint04 value) { m_value.uint04_value = value; }
35 GenericContainer(bool value) { m_value.bool_value = value; }
36 template<class t_type> t_type getValue() const { return m_value.string_value.template getAs<t_type>(); }
37 template<> String getValue() const { return m_value.string_value.getAs<String>(); }
38 template<> fltp08 getValue<fltp08>() const { return m_value.fltp08_value; }
39 template<> fltp04 getValue<fltp04>() const { return m_value.fltp04_value; }
40 template<> sint08 getValue<sint08>() const { return m_value.sint08_value; }
41 template<> sint04 getValue<sint04>() const { return m_value.sint04_value; }
42 template<> uint08 getValue<uint08>() const { return m_value.uint08_value; }
43 template<> uint04 getValue<uint04>() const { return m_value.uint04_value; }
44 template<> bool getValue<bool>() const { return m_value.bool_value; }
45
46 protected:
47 ContainerValue m_value;
48 };*/
49 class INIFactory;
50 class JSONNode;
51 class ProgressInfo;
52 /**--------------------------------------------------------------------------------------------------
53 \brief Stores a generic option of any type as well as some information about how the user
54 might interact with that type.
55 **/
57 {
59 GenericOption(const String& id, const TranslatedString& name, const String& value);
60 template<class t_type>
61 GenericOption(const String& id, const TranslatedString& name, const t_type& value)
62 : name(name)
63 , id(id)
64 , value(String(value))
65 , default_value(String(value))
66 , parameter_type(GetTypeInfo<t_type>())
67 {}
69 : name(option.name)
70 , description(option.description)
71 , id(option.id)
72 , value(option.value.get())
73 , default_value(option.default_value)
74 , file_extensions(option.file_extensions)
75 , icon(option.icon)
76 , regex(option.regex)
77 , parameter_type(option.parameter_type)
78 , available_options(option.available_options)
79 , value_bounds(option.value_bounds)
80 , unit(option.unit)
81 , allow_custom_option(option.allow_custom_option)
82 , is_editable(option.is_editable)
83 , is_viewable(option.is_viewable)
84 {}
85 template<class t_type>
86 [[nodiscard]] t_type getAs() const
87 {
88 return value.get().getAs<t_type>();
89 }
90 template<class t_type>
91 void set(const t_type& new_value)
92 {
93 return value.set(String(new_value));
94 }
95 void set(const String& new_value)
96 {
97 return value.set(new_value);
98 }
100 {
101 value.set(default_value);
102 }
103 bool operator==(const GenericOption& option) const
104 {
105 return option.value.get() == value.get();
106 }
107 bool operator!=(const GenericOption& option) const
108 {
109 return option.value.get() != value.get();
110 }
112 {
113 name = option.name;
114 description = option.description;
115 id = option.id;
116 default_value = option.default_value;
117 parameter_type = option.parameter_type;
118 icon = option.icon;
119 regex = option.regex;
120 parameter_type = option.parameter_type;
121 available_options = option.available_options;
122 value_bounds = option.value_bounds;
123 file_extensions = option.file_extensions;
124 unit = option.unit;
125 is_editable = option.is_editable;
126 is_viewable = option.is_viewable;
127 allow_custom_option = option.allow_custom_option;
128 value.set(option.value.get());
129 return *this;
130 }
136 String file_extensions;//If blank, not a file
143 bool allow_custom_option = false;
144 bool is_editable = true;
145 bool is_viewable = true;
146 };
147 /**--------------------------------------------------------------------------------------------------
148 \brief Stores a groups of GenericOptions that can be used to group them.
149 **/
151 {
152 public:
154 GenericOptionGroup(const TranslatedString& group_name, const String& group_id = String());
156 template<class t_type>
157 void addOption(const TranslatedString& name, const t_type& value, bool is_editable = true)
158 {
159 GenericOption option(name.translationID(), name, value);
160 option.is_editable = is_editable;
161 addOption(option);
162 }
163 void addOption(const GenericOption& option)
164 {
165 lib_assert(!options.hasKey(option.id), "Bad Option");
166 options.add(option.id, option);
167 ordered_options.add(option.id);
168 };
169 bool hasOption(const TranslatedString& option_name) const
170 {
171 return options.hasKey(option_name.translationID());
172 }
173 bool hasOption(const String& option_name) const
174 {
175 return options.hasKey(option_name);
176 }
177
178 template<class t_type>
179 void setValue(const TranslatedString& name, const t_type& value)
180 {
181 lib_assert(options.hasKey(name.translationID()), "Bad Option");
182 options[name.translationID()].value.set(String(value));
183 }
184 template<class t_type>
185 void setValue(const String& name, const t_type& value)
186 {
187 lib_assert(options.hasKey(name), "Bad Option");
188 options[name].value.set(String(value));
189 }
190 void setOption(const GenericOption& option)
191 {
192 lib_assert(options.hasKey(option.id), "Bad Option");
193 if (!options.hasKey(option.id))
194 ordered_options.add(option.id);
195 options[option.id] = option;
196
197 }
199 {
200 return options.get(n.translationID());
201 }
203 {
204 return options.get(n.translationID());
205 }
206
207 template<class t_type>
208 t_type getValue(const TranslatedString& name) const
209 {
210 return options.get(name.translationID()).getAs<t_type>();
211 }
212 template<class t_type>
213 t_type getValue(const String& name) const
214 {
215 return options.get(name).getAs<t_type>();
216 }
217
218 template<class t_type>
219 t_type getValue(const TranslatedString& name, const t_type& value_if_not_exist) const
220 {
221 auto iter = options.find(name.translationID());
222 if (iter != options.end())
223 return iter.value().getAs<t_type>();
224 else
225 return value_if_not_exist;
226 }
227 template<class t_type>
228 t_type getValue(const String& name, const t_type& value_if_not_exist) const
229 {
230 auto iter = options.find(name);
231 if (iter != options.end())
232 return iter.value().getAs<t_type>();
233 else
234 return value_if_not_exist;
235 }
236 bool operator==(const GenericOptionGroup& option_group) const;
237 bool operator!=(const GenericOptionGroup& option_group) const;
240 [[nodiscard]] virtual JSONNode toJSONNode(bool only_value = true) const;
241 virtual void fromJSONNode(const JSONNode& node);
242 void clear();
247 };
248}
#define NDEVR_BASE_API
Definition DLLInfo.h:57
#define lib_assert(expression, message)
Definition LibAssert.h:61
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:52
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition GraphicsPipeline.h:42
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Stores a groups of GenericOptions that can be used to group them.
Definition GenericOptions.h:151
bool hasOption(const String &option_name) const
Definition GenericOptions.h:173
virtual JSONNode toJSONNode(bool only_value=true) const
bool operator==(const GenericOptionGroup &option_group) const
t_type getValue(const TranslatedString &name, const t_type &value_if_not_exist) const
Definition GenericOptions.h:219
void addOption(const GenericOption &option)
Definition GenericOptions.h:163
t_type getValue(const TranslatedString &name) const
Definition GenericOptions.h:208
GenericOption & getOption(const TranslatedString &n)
Definition GenericOptions.h:202
t_type getValue(const String &name) const
Definition GenericOptions.h:213
void setValue(const TranslatedString &name, const t_type &value)
Definition GenericOptions.h:179
bool hasOption(const TranslatedString &option_name) const
Definition GenericOptions.h:169
const GenericOption & getOption(const TranslatedString &n) const
Definition GenericOptions.h:198
TranslatedString name
Definition GenericOptions.h:245
GenericOptionGroup(const TranslatedString &group_name, const String &group_id=String())
bool operator!=(const GenericOptionGroup &option_group) const
String id
Definition GenericOptions.h:246
Buffer< String > ordered_options
Definition GenericOptions.h:244
void addOptionsToINI(INIFactory &factory)
void setValue(const String &name, const t_type &value)
Definition GenericOptions.h:185
Dictionary< String, GenericOption > options
Definition GenericOptions.h:243
virtual void fromJSONNode(const JSONNode &node)
t_type getValue(const String &name, const t_type &value_if_not_exist) const
Definition GenericOptions.h:228
void addOption(const TranslatedString &name, const t_type &value, bool is_editable=true)
Definition GenericOptions.h:157
void setOption(const GenericOption &option)
Definition GenericOptions.h:190
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:68
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:60
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
The core String class for the NDEVR API.
Definition String.h:69
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
const String & translationID() const
Stores information about a type, relevant for certain templated functions. To get information about a...
Definition TypeInfo.h:43
Definition ACIColor.h:37
constexpr std::enable_if<!ObjectInfo< t_type >::Buffer, TypeInfo >::type GetTypeInfo()
Definition TypeInfo.h:103
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233
Stores a generic option of any type as well as some information about how the user might interact wit...
Definition GenericOptions.h:57
GenericOption & operator=(const GenericOption &option)
Definition GenericOptions.h:111
String icon
Definition GenericOptions.h:137
bool allow_custom_option
Definition GenericOptions.h:143
String regex
Definition GenericOptions.h:138
bool is_viewable
Definition GenericOptions.h:145
GenericOption(const String &id, const TranslatedString &name, const String &value)
void setToDefault()
Definition GenericOptions.h:99
Resource< String > value
Definition GenericOptions.h:134
TranslatedString description
Definition GenericOptions.h:132
TranslatedString name
Definition GenericOptions.h:131
ConstPointer< Unit > unit
Definition GenericOptions.h:142
String id
Definition GenericOptions.h:133
Buffer< std::pair< TranslatedString, String > > available_options
Definition GenericOptions.h:140
GenericOption(const String &id, const TranslatedString &name, const t_type &value)
Definition GenericOptions.h:61
bool is_editable
Definition GenericOptions.h:144
t_type getAs() const
Definition GenericOptions.h:86
GenericOption(const GenericOption &option)
Definition GenericOptions.h:68
bool operator==(const GenericOption &option) const
Definition GenericOptions.h:103
void set(const String &new_value)
Definition GenericOptions.h:95
void set(const t_type &new_value)
Definition GenericOptions.h:91
bool operator!=(const GenericOption &option) const
Definition GenericOptions.h:107
String default_value
Definition GenericOptions.h:135
TypeInfo parameter_type
Definition GenericOptions.h:139
Bounds< 1, fltp08 > value_bounds
Definition GenericOptions.h:141
String file_extensions
Definition GenericOptions.h:136