34#include <NDEVR/String.h>
35#include <NDEVR/Resource.h>
36#include <NDEVR/Scanner.h>
37#include <NDEVR/Buffer.h>
38#include <NDEVR/Dictionary.h>
39#include <NDEVR/Matrix.h>
140 template<u
int01 t_dims,
class t_type>
151 template<u
int01 t_dims,
class t_type>
158 template<
class t_type>
166 template<
class t_type>
173 template<
class t_type>
181 template<
class t_type>
192 template<
class t_type, u
int01 t_row_dims, u
int01 t_col_dims>
332 template<
class t_type>
335 return new INIObject<t_type>(mem_loc);
343 template<
class t_type>
346 return new INIObject<t_type>(value);
353 template<
class t_type>
363 , m_type_pointer_shared(&value)
364 , m_type_pointer(nullptr)
371 INIObject(t_type& value)
373 , m_type_pointer_shared(nullptr)
374 , m_type_pointer(&value)
381 INIObject(
const INIObject& other)
383 , m_type_pointer_shared(other.m_type_pointer_shared)
384 , m_type_pointer(other.m_type_pointer)
396 void readOptionAscii(Scanner& scan)
override
398 readOptionAscii(scan.getNext<String>());
405 void readOptionAscii(String option)
override
407 INIFactory::ConvertFromINIString(option);
408 if (option.size() > 0)
410 if (m_type_pointer_shared !=
nullptr)
411 m_type_pointer_shared->set(option.getAs<t_type>());
413 *m_type_pointer = option.getAs<t_type>();
421 String writeOptionAscii()
const override
424 if (m_type_pointer_shared !=
nullptr)
425 s.setFrom(m_type_pointer_shared->get());
427 s.setFrom(*m_type_pointer);
428 INIFactory::ConvertToINIString(s);
437 void readOptionBinary(
const char* bytes)
override
439 if (ObjectInfo<t_type>::Primitive)
442 memcpy(&value, bytes,
sizeof(t_type));
443 if (m_type_pointer_shared !=
nullptr)
444 m_type_pointer_shared->set(value);
446 *m_type_pointer = value;
450 readOptionAscii(String(bytes));
459 void writeOptionBinary(FILE* stream)
const override
461 if (ObjectInfo<t_type>::Primitive)
463 uint04 size =
sizeof(t_type);
464 fwrite(&size,
sizeof(uint04), 1, stream);
465 if (m_type_pointer_shared !=
nullptr)
466 fwrite(&(m_type_pointer_shared->get()),
sizeof(t_type), 1, stream);
468 fwrite(m_type_pointer,
sizeof(t_type), 1, stream);
472 const String value = writeOptionAscii();
473 const uint04 value_size = value.size();
474 fwrite(&value_size,
sizeof(uint04), 1, stream);
475 fwrite(value.c_str(),
sizeof(
char), value_size, stream);
483 INIObject<t_type>* copy()
const override
485 return new INIObject<t_type>(*
this);
488 Resource<t_type>*
const m_type_pointer_shared;
489 t_type*
const m_type_pointer;
496 template<
class t_type>
497 class INIObject<Angle<t_type>> :
public INIOption
504 INIObject(Resource<Angle<t_type>>& value)
506 , m_type_pointer_shared(&value)
507 , m_type_pointer(nullptr)
514 INIObject(Angle<t_type>& value)
516 , m_type_pointer_shared(nullptr)
517 , m_type_pointer(&value)
524 INIObject(
const INIObject& other)
526 , m_type_pointer_shared(other.m_type_pointer_shared)
527 , m_type_pointer(other.m_type_pointer)
539 void readOptionAscii(Scanner& scan)
override
541 readOptionAscii(scan.getNext<String>());
548 void readOptionAscii(String option)
override
550 INIFactory::ConvertFromINIString(option);
551 if (option.size() > 0)
553 if (m_type_pointer_shared !=
nullptr)
554 m_type_pointer_shared->set(Angle<t_type>(DEGREES, option.getAs<fltp08>()));
556 *m_type_pointer = Angle<t_type>(DEGREES, option.getAs<fltp08>());
564 String writeOptionAscii()
const override
567 if (m_type_pointer_shared !=
nullptr)
568 s.setFrom(m_type_pointer_shared->get().template as<DEGREES>());
570 s.setFrom(m_type_pointer->template as<DEGREES>());
571 INIFactory::ConvertToINIString(s);
579 void readOptionBinary(
const char* bytes)
override
582 memcpy(&value, bytes,
sizeof(Angle<t_type>));
583 if (m_type_pointer_shared !=
nullptr)
584 m_type_pointer_shared->set(value);
586 *m_type_pointer = value;
593 void writeOptionBinary(FILE* stream)
const override
595 uint04 size =
sizeof(Angle<t_type>);
596 fwrite(&size,
sizeof(uint04), 1, stream);
597 if (m_type_pointer_shared !=
nullptr)
598 fwrite(&(m_type_pointer_shared->get()),
sizeof(Angle<t_type>), 1, stream);
600 fwrite(m_type_pointer,
sizeof(Angle<t_type>), 1, stream);
607 INIObject<Angle<t_type>>* copy()
const override
609 return new INIObject<Angle<t_type>>(*this);
612 Resource<Angle<t_type>>*
const m_type_pointer_shared;
613 Angle<t_type>*
const m_type_pointer;
616 Dictionary<String, INIOption*> m_options;
617 Dictionary<uint08, INIOption*> m_hashed_options;
618 Dictionary<String, String*> m_extra_options;
619 Buffer<String> m_ordered_options;
622 bool m_preserve_order =
false;
623 bool m_use_hash_labels =
false;
A hash-based key-value store, useful for quick associative lookups.
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
void addOption(const StringView &label, t_type &mem_loc)
Registers a raw typed option that will be read/written by the factory.
void clear()
Removes all registered options and frees their memory.
void setDelimiter(char delimiter)
Sets the delimiter character used to separate keys from values.
void addOption(const StringView &label, Resource< t_type > &mem_loc)
Registers a Resource option that will be read/written by the factory.
void writeToAsciiFile(File &file, bool include_end_comment=false)
Writes all registered options to an ASCII-formatted INI file.
void setPreserveOrder(bool preserve_order)
Sets whether to preserve the order in which options appear in the file.
INIFactory(INIFactory &&reader) noexcept
Move constructor that transfers ownership of all options and state.
void addOption(const StringView &label, const t_type &mem_loc)=delete
Deleted overload to prevent binding to const references.
void addOption(const StringView &label, const Resource< t_type > &mem_loc)=delete
Deleted overload to prevent binding to const Resource references.
void setUseHashLabels(bool use_hash_labels)
Enables or disables using hashed labels for option lookup.
INIFactory(const INIFactory &reader)=delete
Deleted copy constructor to prevent unintended duplication of option ownership.
void readAsciiFile(File &file)
Reads all options from an ASCII-formatted INI file.
Dictionary< String, String * > & extraOptionsRef()
Returns a mutable reference to the extra options dictionary.
bool hasOption(const StringView &option) const
Checks whether an option with the given label has been registered.
INIFactory()
Constructs a default INIFactory with default delimiter and comment settings.
Dictionary< String, String > extraOptions() const
Returns a copy of all extra (unregistered) options as key-value pairs.
static void ConvertFromINIString(String &s)
Converts INI escape sequences in a string back to their original characters.
void writeToBinaryFile(File &file)
Writes all registered options to a binary-formatted INI file.
virtual ~INIFactory()
Virtual destructor that cleans up all owned INIOption instances.
void addINIOption(const StringView &label, INIOption *option)
Registers an INIOption under the given label.
static INIOption * ToOption(t_type &mem_loc)
Creates an INIOption wrapper for a raw typed variable.
static INIOption * ToOption(Resource< t_type > &value)
Creates an INIOption wrapper for a Resource variable.
bool hasOption(uint08 hash_option) const
Checks whether an option with the given hash exists.
void addOption(const String &label, Resource< Matrix< t_type, t_row_dims, t_col_dims > > &mem_loc)
Registers a Matrix Resource option that will be read/written by the factory.
static void ConvertToINIString(String &s)
Converts special characters in a string to INI-safe escape sequences.
void writeToLog(const StringView &title, LogPtr &log, uint01 log_level=2)
Writes all registered options to a log with the given title and level.
void addOption(const StringView &label, Vector< t_dims, t_type > &mem_loc)
Registers a raw Vector option that will be read/written by the factory.
void readBinaryFile(File &file)
Reads all options from a binary-formatted INI file.
void setComment(char comment)
Sets the comment character used to identify comment lines in the INI file.
void read(Scanner &file)
Reads option values from a Scanner stream, applying them to registered options.
void addOption(const StringView &label, Resource< Vector< t_dims, t_type > > &mem_loc)
Registers a Vector Resource option that will be read/written by the factory.
bool addManagedOption(const StringView &option_label, const StringView &option, bool replace=true)
Adds or updates a managed string option that is stored internally by the factory.
String getOption(const StringView &option, const StringView &default_value=StringView()) const
Retrieves the string value of a registered or extra option by label.
bool preserveOrder() const
Returns whether the factory preserves option ordering.
A class used with INIFactory to store a reference to an object in the program that can be inherited t...
virtual void readOptionBinary(const char *bytes)=0
Reads the option value from a raw binary byte buffer.
virtual ~INIOption()
Virtual destructor for safe polymorphic cleanup.
INIOption()
Constructs a default INIOption.
virtual void readOptionAscii(Scanner &option)=0
Reads an option value from a Scanner stream.
virtual String writeOptionAscii() const =0
Writes the option value to an ASCII string representation.
virtual void writeOptionBinary(FILE *stream) const =0
Writes the option value in binary format to a file stream.
virtual void readOptionAscii(String option)=0
Reads an option value from an ASCII string representation.
virtual INIOption * copy() const =0
Creates a deep copy of this INIOption.
A light-weight wrapper that will be a no-op if there is not a valid log reference,...
Templated logic for doing matrix multiplication.
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Contains methods for easily reading objects in an ascii stream using set deliminators and line logic.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
The primary namespace for the NDEVR SDK.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...