API Documentation
Loading...
Searching...
No Matches
ApplicationOptions.h
Go to the documentation of this file.
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/String.h>
4#include <NDEVR/GenericOption.h>
5#include <NDEVR/INIFactory.h>
6#include <NDEVR/Dictionary.h>
7namespace NDEVR
8{
9 class INIFactory;
10 class INIOption;
11 class ResourceListener;
12
13 /**--------------------------------------------------------------------------------------------------
14 Class: ApplicationOptionBase
15
16 \brief The core of the default object to store data of any type that should persist through sessions
17 of the application. Developers should use ApplicationOption.
18
19 Stores data of any type that can easily be saved or retrieved at runtime. Option belongs to a
20 specific group for easy sorting and can be used to automatically generate widgets.
21 **/
23 {
24 public:
26 virtual String toString() const = 0;
27 virtual void fromString(const String&) = 0;
28 virtual bool isDefault() const = 0;
29 virtual void setToDefaultValue() = 0;
30 virtual INIOption* iniOption() = 0;
31 };
32 /**--------------------------------------------------------------------------------------------------
33 Class: ApplicationOptions
34
35 \brief The container for storing N-number of ApplicationOption for the program. Almost all options are
36 typically "user options" and are added to that container by default.
37
38 Stores data of any type that can easily be saved or retrieved at runtime. Option belongs to a
39 specific group for easy sorting and can be used to automatically generate widgets.
40 **/
42 {
43 public:
46 {
47 addOption(TranslatedString(), name, value);
48 }
49 void addOption(const TranslatedString& group_name, const TranslatedString& name, ApplicationOptionBase* value)
50 {
51 lib_assert(!m_options[group_name].hasKey(name), "Duplicate entry");
52 m_options[group_name][name] = value;
53 }
55 {
56 return m_options[group][name];
57 }
59 {
60 return getOption(TranslatedString(), name);
61 }
62 void addToINI(INIFactory& factory);
63 void addToINI(const TranslatedString& group_name, INIFactory& factory);
65 void setToDefaults(const TranslatedString& group_name);
66 void logOptions(ProgressInfo* log, bool log_only_non_defaults);
68 protected:
70 };
71
72 /**--------------------------------------------------------------------------------------------------
73 Class: ApplicationOption
74
75 \brief The default object to store data of any type that should persist through sessions of the
76 application.
77
78 Stores data of any type that can easily be saved or retrieved at runtime. Option belongs to a
79 specific group for easy sorting and can be used to automatically generate widgets.
80 **/
81 template<class t_type>
83 {
84 public:
86 : m_group(group)
87 , m_label(label)
88 , m_value(value)
89 , m_options(options)
90 , m_default_value(value)
91 {
93 }
95 : m_label(label)
96 , m_value(value)
97 , m_options(options)
98 , m_default_value(value)
99 {
101 }
102 t_type get() const
103 {
104 return m_value.get();// m_options.getValue<t_type>(m_group, m_label);
105 }
107 {
108 return m_value;
109 }
110 void set(const t_type& value, bool make_default = false)
111 {
112 if (make_default)
113 m_default_value = value;
114 return m_value.set(value);
115 }
116 void setDefaultValue(const t_type& value)
117 {
118 m_default_value = value;
119 }
120 void addListener(ResourceListener* listener, bool silent_add = false)
121 {
122 m_value.addListener(listener, silent_add);
123 }
124 virtual String toString() const override
125 {
126 return String(m_value.get());
127 }
128 virtual void fromString(const String& value) override
129 {
130 m_value.set(value.getAs<t_type>());
131 }
132 virtual bool isDefault() const override
133 {
134 return m_value.get() == m_default_value;
135 }
136 virtual void setToDefaultValue() override
137 {
139 }
140 virtual INIOption* iniOption() override
141 {
143 }
144 const TranslatedString& label() const
145 {
146 return m_label;
147 }
148 const TranslatedString& group() const
149 {
150 return m_group;
151 }
152 protected:
158 };
159}
#define NDEVR_BASE_API
Definition DLLInfo.h:57
#define lib_assert(expression, message)
Definition LibAssert.h:61
The core of the default object to store data of any type that should persist through sessions of the ...
Definition ApplicationOptions.h:23
virtual bool isDefault() const =0
virtual void setToDefaultValue()=0
virtual INIOption * iniOption()=0
virtual String toString() const =0
virtual void fromString(const String &)=0
virtual ~ApplicationOptionBase()
Definition ApplicationOptions.h:25
The default object to store data of any type that should persist through sessions of the application.
Definition Button.h:57
Resource< t_type > & getResource()
Definition ApplicationOptions.h:106
ApplicationOptions & m_options
Definition ApplicationOptions.h:156
virtual void fromString(const String &value) override
Definition ApplicationOptions.h:128
void set(const t_type &value, bool make_default=false)
Definition ApplicationOptions.h:110
virtual void setToDefaultValue() override
Definition ApplicationOptions.h:136
virtual INIOption * iniOption() override
Definition ApplicationOptions.h:140
const TranslatedString m_group
Definition ApplicationOptions.h:153
ApplicationOption(const TranslatedString &group, const TranslatedString &label, const t_type &value, ApplicationOptions &options=ApplicationOptions::UserOptions())
Definition ApplicationOptions.h:85
virtual String toString() const override
Definition ApplicationOptions.h:124
const TranslatedString m_label
Definition ApplicationOptions.h:154
t_type m_default_value
Definition ApplicationOptions.h:157
ApplicationOption(const TranslatedString &label, const t_type &value, ApplicationOptions &options=ApplicationOptions::UserOptions())
Definition ApplicationOptions.h:94
const TranslatedString & label() const
Definition ApplicationOptions.h:144
void addListener(ResourceListener *listener, bool silent_add=false)
Definition ApplicationOptions.h:120
const TranslatedString & group() const
Definition ApplicationOptions.h:148
t_type get() const
Definition ApplicationOptions.h:102
virtual bool isDefault() const override
Definition ApplicationOptions.h:132
Resource< t_type > m_value
Definition ApplicationOptions.h:155
void setDefaultValue(const t_type &value)
Definition ApplicationOptions.h:116
The container for storing N-number of ApplicationOption for the program. Almost all options are typic...
Definition ApplicationOptions.h:42
void setToDefaults(const TranslatedString &group_name)
void addToINI(const TranslatedString &group_name, INIFactory &factory)
void logOptions(ProgressInfo *log, bool log_only_non_defaults)
void addToINI(INIFactory &factory)
const ApplicationOptionBase * getOption(const TranslatedString &group, const TranslatedString &name) const
Definition ApplicationOptions.h:54
const ApplicationOptionBase * getOption(const TranslatedString &name) const
Definition ApplicationOptions.h:58
void addOption(const TranslatedString &group_name, const TranslatedString &name, ApplicationOptionBase *value)
Definition ApplicationOptions.h:49
void addOption(const TranslatedString &name, ApplicationOptionBase *value)
Definition ApplicationOptions.h:45
Dictionary< TranslatedString, Dictionary< TranslatedString, ApplicationOptionBase * > > m_options
Definition ApplicationOptions.h:69
static ApplicationOptions & UserOptions()
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:68
static INIOption * ToOption(t_type &mem_loc)
Definition INIReader.h:129
A class used with INIFactory to store a reference to an object in the program that can be inherited t...
Definition INIReader.h:49
A light-weight base class for Log that allows processes to update, without the need for additional in...
Definition ProgressInfo.hpp:48
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
A class that can subscribe to any number of Resources which will get updates when the Resource(s) hav...
Definition ResourceListener.h:62
The core String class for the NDEVR API.
Definition String.h:69
t_type getAs() const
Converts a string into an object. To use this function an object must have overwritten StringStream<t...
Definition String.h:143
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
Definition ACIColor.h:37