Face Engine SDK  5.3.0
A face detection, recognition and tracking engine.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ISettingsProvider.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <fsdk/IObject.h>
11 #include <fsdk/Types.h>
12 #include "FSDKError.h"
13 #include <cstring>
14 #include <string>
15 
16 namespace fsdk {
17 
18 #ifndef DOXYGEN_SHOULD_SKIP_THIS
19  DECLARE_SMARTPTR(ISettingsProvider);
20 #endif
21 
33 
37  enum class Error : uint32_t {
38  Ok,
39  IOError,
40  Memory,
41  Internal,
42  InvalidPi,
43  InvalidTag,
44  InvalidCdata,
45  FileNotFound,
57  };
58 
64  virtual const char* getDefaultPath() const noexcept = 0;
65 
72  virtual Result<Error> load(const char* path) noexcept = 0;
73 
79  virtual bool save(const char* path) const noexcept = 0;
80 
85  virtual void clear() noexcept = 0;
86 
91  virtual bool isEmpty() const noexcept = 0;
92 
93 
97  struct Value {
98 
102  union Data {
103  struct Int1 { int m_value; } m_int1;
104  struct Int2 { int m_value[2]; } m_int2;
105  struct Int3 { int m_value[3]; } m_int3;
106  struct Int4 { int m_value[4]; } m_int4;
107  struct Float1 { float m_value; } m_float1;
108  struct Float2 { float m_value[2]; } m_float2;
109  struct Float3 { float m_value[3]; } m_float3;
110  struct Float4 { float m_value[4]; } m_float4;
111  struct String { char* m_value; } m_string;
112  } m_data;
117  enum Type {
120  Int2,
126  Float4,
127  String
128  } m_type;
129 
134  Value() noexcept : m_type(Undefined) {}
135 
140  Value(int x) noexcept { setInt(x); }
141 
147  Value(int x, int y) noexcept { setInt(x, y); }
155  Value(int x, int y, int z) noexcept { setInt(x, y, z); }
164  Value(int x, int y, int z, int w) noexcept { setInt(x, y, z, w); }
170  Value(float x) noexcept { setFloat(x); }
171 
177  Value(float x, float y) noexcept { setFloat(x, y); }
178 
185  Value(float x, float y, float z) noexcept { setFloat(x, y, z); }
186 
194  Value(float x, float y, float z, float w) noexcept { setFloat(x, y, z, w); }
195 
201  Value(const char* string) noexcept { setString(string); }
202 
207  Value(const Rect& rect) noexcept { setRect(rect); }
208 
213  Value(const Size& size) noexcept { setSize(size); }
214 
219  Value(const Point2f& point) noexcept { setPoint2f(point); }
220 
225  Value(bool x) noexcept { setBool(x); }
226 
231  operator bool() const noexcept { return !is(Undefined); }
232 
238  bool is(Type type) const noexcept { return m_type == type; }
239 
240 
245  inline bool setString(const char* string) noexcept;
246 
253  inline bool getString(char* string) const noexcept;
254 
255 
260  inline void setRect(const Rect& rect) noexcept;
261 
268  inline bool getRect(Rect* rect) const noexcept;
269 
270 
275  inline void setSize(const Size& size) noexcept;
276 
283  inline bool getSize(Size* size) const noexcept;
284 
285 
290  inline void setPoint2i(const Point2i& point) noexcept;
291 
298  inline bool getPoint2i(Point2i* point) const noexcept;
299 
300 
305  inline void setPoint2f(const Point2f& point) noexcept;
306 
313  inline bool getPoint2f(Point2f* point) const noexcept;
314 
319  inline void setBool(bool x) noexcept;
320 
327  inline bool getBool(bool* x) const noexcept;
329 
334  inline void setInt(int x) noexcept;
335 
342  inline bool getInt(int* x) const noexcept;
343 
344 
350  inline void setInt(int x, int y) noexcept;
351 
359  inline bool getInt(int* x, int* y) const noexcept;
361 
368  inline void setInt(int x, int y, int z) noexcept;
369 
378  inline bool getInt(int* x, int* y, int* z) const noexcept;
379 
380 
388  inline void setInt(int x, int y, int z, int w) noexcept;
389 
399  inline bool getInt(int* x, int* y, int* z, int* w) const noexcept;
400 
401 
406  inline void setFloat(float x) noexcept;
407 
414  inline bool getFloat(float* x) const noexcept;
415 
416 
422  inline void setFloat(float x, float y) noexcept;
423 
431  inline bool getFloat(float* x, float* y) const noexcept;
432 
433 
440  inline void setFloat(float x, float y, float z) noexcept;
441 
450  inline bool getFloat(float* x, float* y, float* z) const noexcept;
451 
452 
460  inline void setFloat(float x, float y, float z, float w) noexcept;
461 
471  inline bool getFloat(float* x, float* y, float* z, float* w) const noexcept;
472 
473 
480  inline float asFloat(float defaultValue = 0.f) const noexcept;
481 
482 
489  inline Point2f asPoint2f(const Point2f& defaultValue = Point2f()) const noexcept;
490 
491 
498  inline bool asBool(bool defaultValue = false) const noexcept;
499 
500 
507  inline int asInt(int defaultValue = 0) const noexcept;
508 
509 
516  inline Size asSize(const Size& defaultValue = Size()) const noexcept;
517 
518 
525  inline Point2i asPoint2i(const Point2i& defaultValue = Point2i()) const noexcept;
526 
527 
534  inline Rect asRect(const Rect& defaultValue = Rect()) const noexcept;
535 
536 
544  inline const char* asString(const char* defaultValue = "") const noexcept;
545 
546  inline Value(const Value& other) = delete;
547  inline Value(Value&& other);
548 
549  inline Value& operator=(const Value& other) = delete;
550  inline Value& operator=(Value&& other);
551 
552  inline void swap(Value& first, Value& second);
553 
554  inline ~Value();
555 
556  };
557 
558 
560  struct Key {
561 
563  inline Key() noexcept;
564 
570  inline Key(const char* section, const char* parameter) noexcept;
571 
576  const char* getSection() const noexcept {
577  return m_section;
578  }
579 
584  const char* getParameter() const noexcept {
585  return m_parameter;
586  }
587 
592  inline void setSection(const char* section) noexcept;
593 
598  inline void setParameter(const char* parameter) noexcept;
599 
605  inline bool operator < (const ISettingsProvider::Key& other) const noexcept;
606 
607  protected:
608  static const unsigned int m_bufferLength = 128;
609  char m_section [m_bufferLength];
610  char m_parameter [m_bufferLength];
611  };
612 
613 
615  struct Desc {
616 
618  inline Desc() noexcept;
619 
624  inline Desc(const char* desc) noexcept;
625 
630  const char* getDesc() const noexcept {
631  return m_desc;
632  }
633 
638  inline void setDesc(const char* desc) noexcept;
639 
640  protected:
641  static const unsigned int m_bufferLength = 256;
642  char m_desc [m_bufferLength];
643  };
644 
645 
647  struct Entry {
648 
649  Value m_value;
651 
653  Entry() noexcept = default;
654 
655  Entry(Entry&& right) :
656  m_value{std::move(right.m_value)},
657  m_desc{right.m_desc}
658  {}
659 
660  Entry& operator=(Entry&& right) {
661  Entry tmp(std::move(right));
662  swap(tmp, *this);
663  return *this;
664  }
665 
666  void swap(Entry& first, Entry& second) {
667  std::swap(first.m_desc, second.m_desc);
668  std::swap(first.m_value, second.m_value);
669  }
675  inline Entry(const Desc& desc, Value&& value) noexcept;
676 
681  inline void setDesc(const Desc& desc) noexcept;
682 
687  inline void setValue(Value&& value) noexcept;
688 
693  const Desc& getDesc() const noexcept {
694  return m_desc;
695  }
696 
701  const Value& getValue() const noexcept {
702  return m_value;
703  }
704  };
705 
713  virtual void setDesc(const Key& key, const Desc& desc) noexcept = 0;
714 
723  void setDesc(
724  const char* section,
725  const char* parameter,
726  const Desc& desc) noexcept {
727  setDesc(Key(section, parameter), desc);
728  }
729 
737  virtual void setValue(const Key& key, Value&& value) noexcept = 0;
738 
747  void setValue(
748  const char* section,
749  const char* parameter,
750  Value&& value) noexcept {
751  setValue(Key(section, parameter), std::move(value));
752  }
753 
761  virtual void setEntry(const Key& key, Entry&& entry) noexcept = 0;
762 
771  void setEntry(
772  const Key& key,
773  const Desc& desc,
774  Value&& value) noexcept {
775  setEntry(key, Entry(desc, std::move(value)));
776  }
777 
787  void setEntry(
788  const char* section,
789  const char* parameter,
790  const Desc& desc,
791  Value&& value) noexcept {
792  setEntry(Key(section, parameter), Entry(desc, std::move(value)));
793  }
794 
802  virtual const Entry& getEntry(const Key& key) const noexcept = 0;
803 
811  Desc getDesc(const Key& key) const noexcept {
812  return getEntry(key).m_desc;
813  }
814 
824  const char* section,
825  const char* parameter) const noexcept {
826  return getDesc(Key(section, parameter));
827  }
828 
836  const Value& getValue(const Key& key) const noexcept {
837  return getEntry(key).m_value;
838  }
839 
848  const Value& getValue(
849  const char* section,
850  const char* parameter) const noexcept {
851  return getValue(Key(section, parameter));
852  }
853  };
854 
861  createSettingsProvider(const char* path) noexcept;
865  template<>
867 
868  static bool isOk(ISettingsProvider::Error error) noexcept {
869  return error == ISettingsProvider::Error::Ok;
870  }
871 
872  static const char* toString (ISettingsProvider::Error error) noexcept {
873  switch(error) {
875  return "Ok";
877  return "Could not allocate memory";
879  return "Error reading from file";
881  return "Internal error";
883  return "Error during document declaration/processing instruction parsing";
885  return "Parser could not determine tag type";
887  return "Error during CDATA section parsing";
889  return "File was not found";
891  return "Error during PCDATA section parsing";
893  return "Error during comment parsing";
895  return "Error during document type declaration parsing";
897  return "Settings sections is invalid or absent";
899  return "Error during element attribute parsing";
901  return "Error during end element tag parsing";
903  return "Root type is not node_element or node_document";
905  return "Document without element nodes";
907  return "Mismatch of start-end tags";
909  return "Error during start element tag parsing";
910  default: return "Unknown error";
911  }
912  }
913  };
914 
915 #include "ISettingsProvider.inl"
916 
919 }
Could not allocate memory.
virtual void clear() noexcept=0
Clear settings.
2D floating point.
Definition: ISettingsProvider.h:124
floating point.
Definition: ISettingsProvider.h:123
Error
Config parsing error codes.
Definition: ISettingsProvider.h:37
3D floating point.
Definition: ISettingsProvider.h:125
#define FSDK_API
Dummy.
Definition: Def.h:27
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:59
Unable to append nodes since root type is not node_element or node_document (exclusive to xml_node::a...
const char * getParameter() const noexcept
Get parameter name.
Definition: ISettingsProvider.h:584
void setValue(Value &&value) noexcept
Set value.
Definition: ISettingsProvider.h:377
A structure that encapsulates an action result enumeration.
Definition: Result.h:29
virtual const Entry & getEntry(const Key &key) const noexcept=0
Find parameter entry.
Common data types and structures.
Value() noexcept
Initialize an empty value.
Definition: ISettingsProvider.h:134
virtual void setDesc(const Key &key, const Desc &desc) noexcept=0
Set parameter description.
Configuration parameter key.
Definition: ISettingsProvider.h:560
Definition: ISettingsProvider.h:104
Object system types and interfaces.
Definition: ISettingsProvider.h:106
Common SDK error codes.
virtual bool isEmpty() const noexcept=0
Definition: Result.h:9
Parser could not determine tag type.
Type
Value type.
Definition: ISettingsProvider.h:117
const Desc & getDesc() const noexcept
Get description.
Definition: ISettingsProvider.h:693
Desc m_desc
Parameter description.
Definition: ISettingsProvider.h:650
Value(const char *string) noexcept
Initialize a string value.
Definition: ISettingsProvider.h:201
Base strong reference counted object interface.
Definition: IRefCounted.h:36
Definition: ISettingsProvider.h:110
Value data.
Definition: ISettingsProvider.h:102
void setDesc(const Desc &desc) noexcept
Set description.
Definition: ISettingsProvider.h:372
Value(float x, float y) noexcept
Initialize a 2d float value.
Definition: ISettingsProvider.h:177
Value(const Point2f &point) noexcept
Initialize a point value.
Definition: ISettingsProvider.h:219
There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or th...
const Value & getValue(const Key &key) const noexcept
Get parameter value.
Definition: ISettingsProvider.h:836
Value(bool x) noexcept
Initialize a bool value.
Definition: ISettingsProvider.h:225
Parsing error occurred while parsing document declaration/processing instruction. ...
Parsing error occurred while parsing document type declaration.
Parsing error occurred while parsing comment.
Definition: ISettingsProvider.h:103
Value(int x) noexcept
Initialize an integer value.
Definition: ISettingsProvider.h:140
Configuration parameter description.
Definition: ISettingsProvider.h:615
Definition: ISettingsProvider.h:105
Value(float x) noexcept
Initialize a float value.
Definition: ISettingsProvider.h:170
Entry() noexcept=default
Initialize an empty entry.
bool operator<(Version lhs, Version rhs) noexcept
Check if one version is less than another.
Definition: Version.h:36
const char * getDesc() const noexcept
Get description text.
Definition: ISettingsProvider.h:630
void setDesc(const char *desc) noexcept
Set description text.
Definition: ISettingsProvider.h:360
Integer.
Definition: ISettingsProvider.h:119
Value(const Rect &rect) noexcept
Initialize a rect value.
Definition: ISettingsProvider.h:207
File was not found during load_file()
Desc getDesc(const Key &key) const noexcept
Get parameter description.
Definition: ISettingsProvider.h:811
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:21
Definition: ISettingsProvider.h:109
const Value & getValue() const noexcept
Get value.
Definition: ISettingsProvider.h:701
Definition: ISettingsProvider.h:107
Value(int x, int y, int z, int w) noexcept
Initialize a 4d integer value.
Definition: ISettingsProvider.h:164
4D integer.
Definition: ISettingsProvider.h:122
Value(int x, int y) noexcept
Initialize a 2d integer value.
Definition: ISettingsProvider.h:147
const char * getSection() const noexcept
Get section name.
Definition: ISettingsProvider.h:576
Value(float x, float y, float z) noexcept
Initialize a 3d float value.
Definition: ISettingsProvider.h:185
Parsing resulted in a document without element nodes.
virtual Result< Error > load(const char *path) noexcept=0
Load settings from given path.
Parsing error occurred while parsing end element tag.
Settings section is invalid or absent.
Desc() noexcept
Initialize an empty description.
Definition: ISettingsProvider.h:352
Parsing error occurred while parsing PCDATA section.
Configuration parameter entry.
Definition: ISettingsProvider.h:647
Configuration parameter value.
Definition: ISettingsProvider.h:97
virtual const char * getDefaultPath() const noexcept=0
Get settings path this provider is bound to.
Value(const Size &size) noexcept
Initialize a size value.
Definition: ISettingsProvider.h:213
Parsing error occurred while parsing start element tag.
Value(float x, float y, float z, float w) noexcept
Initialize a 4d float value.
Definition: ISettingsProvider.h:194
Error reading from file/stream.
Value(int x, int y, int z) noexcept
Initialize a 3d integer value.
Definition: ISettingsProvider.h:155
virtual void setEntry(const Key &key, Entry &&entry) noexcept=0
Set parameter.
Desc getDesc(const char *section, const char *parameter) const noexcept
Get parameter description.
Definition: ISettingsProvider.h:823
virtual bool save(const char *path) const noexcept=0
Save settings values using the default path.
FSDK_API ResultValue< FSDKError, ISettingsProviderPtr > createSettingsProvider(const char *path) noexcept
Create a settings provider.
bool is(Type type) const noexcept
Check if value type is of concrete type.
Definition: ISettingsProvider.h:238
char m_desc[m_bufferLength]
Parameter description text.
Definition: ISettingsProvider.h:642
3D integer.
Definition: ISettingsProvider.h:121
memory allocation failed for internal data
void setEntry(const char *section, const char *parameter, const Desc &desc, Value &&value) noexcept
Set parameter.
Definition: ISettingsProvider.h:787
Value m_value
Parameter value.
Definition: ISettingsProvider.h:649
Unkown value type.
Definition: ISettingsProvider.h:118
Definition: ISettingsProvider.h:111
void setDesc(const char *section, const char *parameter, const Desc &desc) noexcept
Set parameter description.
Definition: ISettingsProvider.h:723
Parsing error occurred while parsing element attribute.
Parsing error occurred while parsing CDATA section.
SDK settings provider interface.
Definition: ISettingsProvider.h:32
virtual void setValue(const Key &key, Value &&value) noexcept=0
Set parameter value.
const Value & getValue(const char *section, const char *parameter) const noexcept
Get parameter value.
Definition: ISettingsProvider.h:848