34#include <NDEVR/String.h>
35#include <NDEVR/ProgressInfo.h>
36#include <NDEVR/Resource.h>
37#include <NDEVR/Scanner.h>
38#include <NDEVR/Buffer.h>
39#include <NDEVR/Dictionary.h>
40#include <NDEVR/Matrix.h>
75 template<u
int01 t_dims,
class t_type>
81 template<u
int01 t_dims,
class t_type>
87 template<
class t_type>
90 template<
class t_type>
93 addINIOption(label,
new INIObject<t_type>(mem_loc));
95 template<
class t_type>
98 template<
class t_type>
101 addINIOption(label,
new INIObject<t_type>(mem_loc));
103 template<
class t_type, u
int01 t_row_dims, u
int01 t_col_dims>
128 template<
class t_type>
131 return new INIObject<t_type>(mem_loc);
133 template<
class t_type>
136 return new INIObject<t_type>(value);
139 template<
class t_type>
145 , m_type_pointer_shared(&value)
146 , m_type_pointer(nullptr)
148 INIObject(t_type& value)
150 , m_type_pointer_shared(nullptr)
151 , m_type_pointer(&value)
153 INIObject(
const INIObject& other)
155 , m_type_pointer_shared(other.m_type_pointer_shared)
156 , m_type_pointer(other.m_type_pointer)
159 void readOptionAscii(Scanner& scan)
override
161 readOptionAscii(scan.getNext<String>());
163 void readOptionAscii(String option)
override
165 INIFactory::ConvertFromINIString(option);
166 if (option.size() > 0)
168 if (m_type_pointer_shared !=
nullptr)
169 m_type_pointer_shared->set(option.getAs<t_type>());
171 *m_type_pointer = option.getAs<t_type>();
174 String writeOptionAscii()
const override
177 if (m_type_pointer_shared !=
nullptr)
178 s = String(m_type_pointer_shared->get());
180 s = String(*m_type_pointer);
181 INIFactory::ConvertToINIString(s);
184 void readOptionBinary(
const char* bytes)
override
186 if (ObjectInfo<t_type>::Primitive)
189 memcpy(&value, bytes,
sizeof(t_type));
190 if (m_type_pointer_shared !=
nullptr)
191 m_type_pointer_shared->set(value);
193 *m_type_pointer = value;
197 readOptionAscii(String(bytes));
200 void writeOptionBinary(FILE* stream)
const override
202 if (ObjectInfo<t_type>::Primitive)
204 uint04 size =
sizeof(t_type);
205 fwrite(&size,
sizeof(uint04), 1, stream);
206 if (m_type_pointer_shared !=
nullptr)
207 fwrite(&(m_type_pointer_shared->get()),
sizeof(t_type), 1, stream);
209 fwrite(m_type_pointer,
sizeof(t_type), 1, stream);
213 const String value = writeOptionAscii();
214 const uint04 value_size = value.size();
215 fwrite(&value_size,
sizeof(uint04), 1, stream);
216 fwrite(value.c_str(),
sizeof(
char), value_size, stream);
219 INIObject<t_type>* copy()
const override
221 return new INIObject<t_type>(*
this);
224 Resource<t_type>*
const m_type_pointer_shared;
225 t_type*
const m_type_pointer;
227 template<
class t_type>
228 class INIObject<Angle<t_type>> :
public INIOption
231 INIObject(Resource<Angle<t_type>>& value)
233 , m_type_pointer_shared(&value)
234 , m_type_pointer(nullptr)
236 INIObject(Angle<t_type>& value)
238 , m_type_pointer_shared(nullptr)
239 , m_type_pointer(&value)
241 INIObject(
const INIObject& other)
243 , m_type_pointer_shared(other.m_type_pointer_shared)
244 , m_type_pointer(other.m_type_pointer)
247 void readOptionAscii(Scanner& scan)
override
249 readOptionAscii(scan.getNext<String>());
251 void readOptionAscii(String option)
override
253 INIFactory::ConvertFromINIString(option);
254 if (option.size() > 0)
256 if (m_type_pointer_shared !=
nullptr)
257 m_type_pointer_shared->set(Angle<t_type>(DEGREES, option.getAs<fltp08>()));
259 *m_type_pointer = Angle<t_type>(DEGREES, option.getAs<fltp08>());
262 String writeOptionAscii()
const override
265 if (m_type_pointer_shared !=
nullptr)
266 s = String(m_type_pointer_shared->get().template as<DEGREES>());
268 s = String(m_type_pointer->template as<DEGREES>());
269 INIFactory::ConvertToINIString(s);
272 void readOptionBinary(
const char* bytes)
override
275 memcpy(&value, bytes,
sizeof(Angle<t_type>));
276 if (m_type_pointer_shared !=
nullptr)
277 m_type_pointer_shared->set(value);
279 *m_type_pointer = value;
281 void writeOptionBinary(FILE* stream)
const override
283 uint04 size =
sizeof(Angle<t_type>);
284 fwrite(&size,
sizeof(uint04), 1, stream);
285 if (m_type_pointer_shared !=
nullptr)
286 fwrite(&(m_type_pointer_shared->get()),
sizeof(Angle<t_type>), 1, stream);
288 fwrite(m_type_pointer,
sizeof(Angle<t_type>), 1, stream);
290 INIObject<Angle<t_type>>* copy()
const override
292 return new INIObject<Angle<t_type>>(*this);
295 Resource<Angle<t_type>>*
const m_type_pointer_shared;
296 Angle<t_type>*
const m_type_pointer;
299 Dictionary<String, INIOption*> m_options;
300 Dictionary<uint08, INIOption*> m_hashed_options;
301 Dictionary<String, String*> m_extra_options;
302 Buffer<String> m_ordered_options;
305 bool m_preserve_order =
false;
306 bool m_use_hash_labels =
false;
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:68
void addOption(const String &label, Resource< Matrix< t_type, t_row_dims, t_col_dims > > &mem_loc)
Definition INIReader.h:104
void addOption(const String &label, const t_type &mem_loc)=delete
Dictionary< String, String > extraOptions() const
void addOption(const String &label, Resource< Vector< t_dims, t_type > > &mem_loc)
Definition INIReader.h:76
bool preserveOrder() const
Definition INIReader.h:118
void writeToAsciiFile(File &file, bool include_end_comment=false)
bool addManagedOption(const String &option_label, const String &option, bool replace=true)
void setComment(char comment)
Definition INIReader.h:113
bool hasOption(uint08 hash_option) const
static INIOption * ToOption(t_type &mem_loc)
Definition INIReader.h:129
bool hasOption(const String &option) const
void writeToLog(const String &title, ProgressInfo *log, uint01 log_level=2)
void addOption(const String &label, const Resource< t_type > &mem_loc)=delete
void addINIOption(const String &label, INIOption *option)
void readBinaryFile(File &file)
INIFactory(const INIFactory &reader)=delete
void setDelimiter(char delimiter)
static INIOption * ToOption(Resource< t_type > &value)
Definition INIReader.h:134
Dictionary< String, String * > & extraOptionsRef()
Definition INIReader.h:124
void addOption(const String &label, t_type &mem_loc)
Definition INIReader.h:99
void addOption(const String &label, Vector< t_dims, t_type > &mem_loc)
Definition INIReader.h:82
INIFactory(INIFactory &&reader) noexcept
void writeToBinaryFile(File &file)
void addOption(const String &label, Resource< t_type > &mem_loc)
Definition INIReader.h:91
void readAsciiFile(File &file)
void setPreserveOrder(bool preserve_order)
Definition INIReader.h:117
static void ConvertToINIString(String &s)
String getOption(const String &option, const String &default_value=String()) const
void setUseHashLabels(bool use_hash_labels)
static void ConvertFromINIString(String &s)
A class used with INIFactory to store a reference to an object in the program that can be inherited t...
Definition INIReader.h:49
virtual String writeOptionAscii() const =0
virtual void readOptionAscii(String option)=0
virtual void readOptionAscii(Scanner &option)=0
virtual INIOption * copy() const =0
virtual void readOptionBinary(const char *bytes)=0
virtual void writeOptionBinary(FILE *stream) const =0
virtual ~INIOption()
Definition INIReader.h:52
Definition Matrix.hpp:176
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
Contains methods for easily reading objects in an ascii stream.
Definition Scanner.h:45
The core String class for the NDEVR API.
Definition String.h:69
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96