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;
53 {
55 GenericOption(const String& id, const TranslatedString& name, const String& value);
56 template<class t_type>
57 GenericOption(const String& id, const TranslatedString& name, const t_type& value)
58 : name(name)
59 , id(id)
60 , value(String(value))
61 , default_value(String(value))
62 , parameter_type(GetTypeInfo<t_type>())
63 {}
65 : name(option.name)
66 , description(option.description)
67 , id(option.id)
68 , value(option.value.get())
69 , default_value(option.default_value)
70 , file_extensions(option.file_extensions)
71 , icon(option.icon)
72 , regex(option.regex)
73 , parameter_type(option.parameter_type)
74 , available_options(option.available_options)
75 , value_bounds(option.value_bounds)
76 , unit(option.unit)
77 , allow_custom_option(option.allow_custom_option)
78 , is_editable(option.is_editable)
79 , is_viewable(option.is_viewable)
80 {}
81 template<class t_type>
82 [[nodiscard]] t_type getAs() const
83 {
84 return value.get().getAs<t_type>();
85 }
86 template<class t_type>
87 void set(const t_type& new_value)
88 {
89 return value.set(String(new_value));
90 }
91 void set(const String& new_value)
92 {
93 return value.set(new_value);
94 }
96 {
97 value.set(default_value);
98 }
99 bool operator==(const GenericOption& option) const
100 {
101 return option.value.get() == value.get();
102 }
103 bool operator!=(const GenericOption& option) const
104 {
105 return option.value.get() != value.get();
106 }
108 {
109 name = option.name;
110 description = option.description;
111 id = option.id;
112 default_value = option.default_value;
113 parameter_type = option.parameter_type;
114 icon = option.icon;
115 regex = option.regex;
116 parameter_type = option.parameter_type;
117 available_options = option.available_options;
118 value_bounds = option.value_bounds;
119 file_extensions = option.file_extensions;
120 unit = option.unit;
121 is_editable = option.is_editable;
122 is_viewable = option.is_viewable;
123 allow_custom_option = option.allow_custom_option;
124 value.set(option.value.get());
125 return *this;
126 }
132 String file_extensions;//If blank, not a file
139 bool allow_custom_option = false;
140 bool is_editable = true;
141 bool is_viewable = true;
142 };
143
145 {
146 public:
148 GenericOptionGroup(const TranslatedString& group_name, const String& group_id = String());
149 virtual ~GenericOptionGroup();
150 template<class t_type>
151 void addOption(const TranslatedString& name, const t_type& value, bool is_editable = true)
152 {
153 GenericOption option(name.translationID(), name, value);
154 option.is_editable = is_editable;
155 addOption(option);
156 }
157 void addOption(const GenericOption& option)
158 {
159 lib_assert(!options.hasKey(option.id), "Bad Option");
160 options.add(option.id, option);
161 ordered_options.add(option.id);
162 };
163 bool hasOption(const TranslatedString& option_name) const
164 {
165 return options.hasKey(option_name.translationID());
166 }
167 bool hasOption(const String& option_name) const
168 {
169 return options.hasKey(option_name);
170 }
171
172 template<class t_type>
173 void setValue(const TranslatedString& name, const t_type& value)
174 {
175 lib_assert(options.hasKey(name.translationID()), "Bad Option");
176 options[name.translationID()].value.set(String(value));
177 }
178 template<class t_type>
179 void setValue(const String& name, const t_type& value)
180 {
181 lib_assert(options.hasKey(name), "Bad Option");
182 options[name].value.set(String(value));
183 }
184 void setOption(const GenericOption& option)
185 {
186 lib_assert(options.hasKey(option.id), "Bad Option");
187 if (!options.hasKey(option.id))
188 ordered_options.add(option.id);
189 options[option.id] = option;
190
191 }
193 {
194 return options.get(n.translationID());
195 }
197 {
198 return options.get(n.translationID());
199 }
200
201 template<class t_type>
202 t_type getValue(const TranslatedString& name) const
203 {
204 return options.get(name.translationID()).getAs<t_type>();
205 }
206 template<class t_type>
207 t_type getValue(const String& name) const
208 {
209 return options.get(name).getAs<t_type>();
210 }
211
212 template<class t_type>
213 t_type getValue(const TranslatedString& name, const t_type& value_if_not_exist) const
214 {
215 auto iter = options.find(name.translationID());
216 if (iter != options.end())
217 return iter.value().getAs<t_type>();
218 else
219 return value_if_not_exist;
220 }
221 template<class t_type>
222 t_type getValue(const String& name, const t_type& value_if_not_exist) const
223 {
224 auto iter = options.find(name);
225 if (iter != options.end())
226 return iter.value().getAs<t_type>();
227 else
228 return value_if_not_exist;
229 }
230 bool operator==(const GenericOptionGroup& option_group) const;
231 bool operator!=(const GenericOptionGroup& option_group) const;
232 INIFactory ini();
233 void addOptionsToINI(INIFactory& factory);
234 [[nodiscard]] virtual JSONNode toJSONNode(bool only_value = true) const;
235 virtual void fromJSONNode(const JSONNode& node);
236 void clear();
241 };
242}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
bool operator!=(const VkVertexInputAttributeDescription &a, const VkVertexInputAttributeDescription &b)
Definition VulkanRenderObject.cpp:10
bool operator==(const VkVertexInputAttributeDescription &a, const VkVertexInputAttributeDescription &b)
Definition VulkanRenderObject.cpp:18
A specification of upper and lower bounds in N-dimensions.
Definition Bounds.hpp:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
decltype(auto) get(t_index_type index)
Definition Buffer.hpp:857
Definition GraphicsPipeline.h:42
Definition Dictionary.h:48
Definition GenericOptions.h:145
bool hasOption(const String &option_name) const
Definition GenericOptions.h:167
t_type getValue(const TranslatedString &name, const t_type &value_if_not_exist) const
Definition GenericOptions.h:213
void addOption(const GenericOption &option)
Definition GenericOptions.h:157
t_type getValue(const TranslatedString &name) const
Definition GenericOptions.h:202
GenericOption & getOption(const TranslatedString &n)
Definition GenericOptions.h:196
t_type getValue(const String &name) const
Definition GenericOptions.h:207
void setValue(const TranslatedString &name, const t_type &value)
Definition GenericOptions.h:173
bool hasOption(const TranslatedString &option_name) const
Definition GenericOptions.h:163
const GenericOption & getOption(const TranslatedString &n) const
Definition GenericOptions.h:192
TranslatedString name
Definition GenericOptions.h:239
String id
Definition GenericOptions.h:240
Buffer< String > ordered_options
Definition GenericOptions.h:238
void setValue(const String &name, const t_type &value)
Definition GenericOptions.h:179
Dictionary< String, GenericOption > options
Definition GenericOptions.h:237
t_type getValue(const String &name, const t_type &value_if_not_exist) const
Definition GenericOptions.h:222
void addOption(const TranslatedString &name, const t_type &value, bool is_editable=true)
Definition GenericOptions.h:151
void setOption(const GenericOption &option)
Definition GenericOptions.h:184
Definition INIReader.h:57
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:121
Definition Toggle.h:41
Definition String.h:40
Definition TranslatedString.h:9
NDEVR_BASE_API const String & translationID() const
Definition TranslatedString.cpp:134
Definition TypeInfo.h:39
Definition ACIColor.h:37
constexpr std::enable_if<!ObjectInfo< t_type >::Buffer, TypeInfo >::type GetTypeInfo()
Definition TypeInfo.h:99
Definition BaseValues.hpp:272
Definition GenericOptions.h:53
GenericOption & operator=(const GenericOption &option)
Definition GenericOptions.h:107
String icon
Definition GenericOptions.h:133
bool allow_custom_option
Definition GenericOptions.h:139
String regex
Definition GenericOptions.h:134
bool is_viewable
Definition GenericOptions.h:141
void setToDefault()
Definition GenericOptions.h:95
Resource< String > value
Definition GenericOptions.h:130
TranslatedString description
Definition GenericOptions.h:128
TranslatedString name
Definition GenericOptions.h:127
ConstPointer< Unit > unit
Definition GenericOptions.h:138
String id
Definition GenericOptions.h:129
Buffer< std::pair< TranslatedString, String > > available_options
Definition GenericOptions.h:136
GenericOption(const String &id, const TranslatedString &name, const t_type &value)
Definition GenericOptions.h:57
bool is_editable
Definition GenericOptions.h:140
t_type getAs() const
Definition GenericOptions.h:82
GenericOption(const GenericOption &option)
Definition GenericOptions.h:64
bool operator==(const GenericOption &option) const
Definition GenericOptions.h:99
void set(const String &new_value)
Definition GenericOptions.h:91
void set(const t_type &new_value)
Definition GenericOptions.h:87
bool operator!=(const GenericOption &option) const
Definition GenericOptions.h:103
String default_value
Definition GenericOptions.h:131
TypeInfo parameter_type
Definition GenericOptions.h:135
Bounds< 1, fltp08 > value_bounds
Definition GenericOptions.h:137
String file_extensions
Definition GenericOptions.h:132