Face Engine SDK  5.21.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 <cstring>
11 #include <fsdk/FSDKError.h>
12 #include <fsdk/IObject.h>
13 #include <fsdk/Types.h>
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,
46  InvalidPcdata,
47  InvalidDocType,
48  InvalidSettings,
49  InvalidComment,
50  InvalidAttribute,
51  InvalidEndElement,
52  AppendInvalidRoot,
53  NoDocumentElement,
55  EndElementMismatch,
56  InvalidStartElement,
58  MemoryAllocationFailed,
59  };
60 
66  virtual const char* getDefaultPath() const noexcept = 0;
67 
72  virtual void setDefaultPath(const char* path) noexcept = 0;
73 
80  virtual Result<Error> load(const char* path) noexcept = 0;
81 
89  virtual Result<Error> loadFromString(const char* content) noexcept = 0;
90 
96  virtual bool save(const char* path) const noexcept = 0;
97 
102  virtual void clear() noexcept = 0;
103 
108  virtual bool isEmpty() const noexcept = 0;
109 
113  struct FSDK_API Value {
114 
118  union Data {
119  struct Int1 {
120  int m_value;
121  } m_int1;
122 
123  struct Int2 {
124  int m_value[2];
125  } m_int2;
126 
127  struct Int3 {
128  int m_value[3];
129  } m_int3;
130 
131  struct Int4 {
132  int m_value[4];
133  } m_int4;
134 
135  struct Float1 {
136  float m_value;
137  } m_float1;
138 
139  struct Float2 {
140  float m_value[2];
141  } m_float2;
142 
143  struct Float3 {
144  float m_value[3];
145  } m_float3;
146 
147  struct Float4 {
148  float m_value[4];
149  } m_float4;
150 
151  struct String {
152  char* m_value;
153  } m_string;
154  } m_data;
155 
159  enum Type {
169  String
170  } m_type;
171 
176  Value() noexcept;
177 
182  Value(int x) noexcept;
183 
189  Value(int x, int y) noexcept;
190 
197  Value(int x, int y, int z) noexcept;
198 
206  Value(int x, int y, int z, int w) noexcept;
207 
212  Value(float x) noexcept;
213 
219  Value(float x, float y) noexcept;
226  Value(float x, float y, float z) noexcept;
227 
235  Value(float x, float y, float z, float w) noexcept;
236 
242  Value(const char* string) noexcept;
243 
248  Value(const Rect& rect) noexcept;
249 
254  Value(const Size& size) noexcept;
255 
260  Value(const Point2f& point) noexcept;
261 
266  Value(bool x) noexcept;
267 
272  operator bool() const noexcept;
273 
279  bool is(Type type) const noexcept;
280 
281 
286  bool setString(const char* string) noexcept;
287 
294  bool getString(char* string) const noexcept;
295 
296 
301  void setRect(const Rect& rect) noexcept;
302 
310  bool getRect(Rect* rect) const noexcept;
311 
312 
317  void setSize(const Size& size) noexcept;
318 
326  bool getSize(Size* size) const noexcept;
327 
328 
333  void setPoint2i(const Point2i& point) noexcept;
334 
342  bool getPoint2i(Point2i* point) const noexcept;
343 
344 
349  void setPoint2f(const Point2f& point) noexcept;
350 
358  bool getPoint2f(Point2f* point) const noexcept;
359 
364  void setBool(bool x) noexcept;
365 
373  bool getBool(bool* x) const noexcept;
374 
375 
380  void setInt(int x) noexcept;
381 
388  bool getInt(int* x) const noexcept;
389 
390 
396  void setInt(int x, int y) noexcept;
397 
406  bool getInt(int* x, int* y) const noexcept;
407 
408 
415  void setInt(int x, int y, int z) noexcept;
416 
426  bool getInt(int* x, int* y, int* z) const noexcept;
427 
428 
436  void setInt(int x, int y, int z, int w) noexcept;
437 
448  bool getInt(int* x, int* y, int* z, int* w) const noexcept;
449 
450 
455  void setFloat(float x) noexcept;
456 
463  bool getFloat(float* x) const noexcept;
464 
465 
471  void setFloat(float x, float y) noexcept;
472 
481  bool getFloat(float* x, float* y) const noexcept;
482 
483 
490  void setFloat(float x, float y, float z) noexcept;
491 
501  bool getFloat(float* x, float* y, float* z) const noexcept;
502 
503 
511  void setFloat(float x, float y, float z, float w) noexcept;
512 
523  bool getFloat(float* x, float* y, float* z, float* w) const noexcept;
524 
525 
532  float asFloat(float defaultValue = 0.f) const noexcept;
533 
534 
542  Point2f asPoint2f(const Point2f& defaultValue = Point2f()) const noexcept;
543 
544 
552  bool asBool(bool defaultValue = false) const noexcept;
553 
554 
561  int asInt(int defaultValue = 0) const noexcept;
562 
563 
571  Size asSize(const Size& defaultValue = Size()) const noexcept;
572 
573 
581  Point2i asPoint2i(const Point2i& defaultValue = Point2i()) const noexcept;
582 
583 
591  Rect asRect(const Rect& defaultValue = Rect()) const noexcept;
592 
593 
601  const char* asString(const char* defaultValue = "") const noexcept;
602 
603  inline Value(const Value& other) = delete;
604  Value(Value&& other);
605 
606  inline Value& operator=(const Value& other) = delete;
607  Value& operator=(Value&& other);
608 
609  void swap(Value& first, Value& second);
610 
611  ~Value();
612  };
613 
615  struct FSDK_API Key {
616 
618  Key() noexcept;
619 
625  Key(const char* section, const char* parameter) noexcept;
626 
631  const char* getSection() const noexcept;
632 
637  const char* getParameter() const noexcept;
638 
643  void setSection(const char* section) noexcept;
644 
649  void setParameter(const char* parameter) noexcept;
650 
656  bool operator<(const ISettingsProvider::Key& other) const noexcept;
657 
658  protected:
659  static const unsigned int m_bufferLength = 128;
660  char m_section[m_bufferLength];
661  char m_parameter[m_bufferLength];
662  };
663 
665  struct FSDK_API Desc {
666 
668  Desc() noexcept;
669 
674  Desc(const char* desc) noexcept;
675 
680  const char* getDesc() const noexcept;
681 
686  void setDesc(const char* desc) noexcept;
687 
688  protected:
689  static const unsigned int m_bufferLength = 256;
690  char m_desc[m_bufferLength];
691  };
692 
694  struct FSDK_API Entry {
695 
696  Value m_value;
698 
700  Entry() noexcept = default;
701 
702  Entry(Entry&& right);
703 
704  Entry& operator=(Entry&& right);
705 
706  void swap(Entry& first, Entry& second);
712  Entry(const Desc& desc, Value&& value) noexcept;
713 
718  void setDesc(const Desc& desc) noexcept;
719 
724  void setValue(Value&& value) noexcept;
725 
730  const Desc& getDesc() const noexcept;
731 
736  const Value& getValue() const noexcept;
737  };
738 
746  virtual void setDesc(const Key& key, const Desc& desc) noexcept = 0;
747 
756  void setDesc(const char* section, const char* parameter, const Desc& desc) noexcept;
757 
765  virtual void setValue(const Key& key, Value&& value) noexcept = 0;
766 
775  void setValue(const char* section, const char* parameter, Value&& value) noexcept;
776 
784  virtual void setEntry(const Key& key, Entry&& entry) noexcept = 0;
785 
794  void setEntry(const Key& key, const Desc& desc, Value&& value) noexcept;
795 
805  void setEntry(const char* section, const char* parameter, const Desc& desc, Value&& value) noexcept;
806 
814  virtual const Entry& getEntry(const Key& key) const noexcept = 0;
815 
823  Desc getDesc(const Key& key) const noexcept;
824 
833  Desc getDesc(const char* section, const char* parameter) const noexcept;
834 
842  const Value& getValue(const Key& key) const noexcept;
843 
852  const Value& getValue(const char* section, const char* parameter) const noexcept;
853  };
854 
860  FSDK_API fsdk::ResultValue<fsdk::FSDKError, fsdk::ISettingsProviderPtr>
861  createSettingsProvider(const char* path) noexcept;
862 
869  FSDK_API ResultValue<FSDKError, ISettingsProviderPtr>
870  createSettingsProviderFromString(const char* content) noexcept;
871 
875  template <>
877 
878  static bool isOk(ISettingsProvider::Error error) noexcept {
879  return error == ISettingsProvider::Error::Ok;
880  }
881 
882  static const char* toString(ISettingsProvider::Error error) noexcept {
883  switch(error) {
885  return "Ok";
887  return "Could not allocate memory";
889  return "Error reading from file";
891  return "Internal error";
893  return "Error during document declaration/processing instruction parsing";
895  return "Parser could not determine tag type";
897  return "Error during CDATA section parsing";
899  return "File was not found";
901  return "Error during PCDATA section parsing";
903  return "Error during comment parsing";
905  return "Error during document type declaration parsing";
907  return "Settings sections is invalid or absent";
909  return "Error during element attribute parsing";
911  return "Error during end element tag parsing";
913  return "Root type is not node_element or node_document";
915  return "Document without element nodes";
917  return "Mismatch of start-end tags";
919  return "Error during start element tag parsing";
920  default:
921  return "Unknown error";
922  }
923  }
924  };
925 
927 } // namespace fsdk
Could not allocate memory.
2D floating point.
Definition: ISettingsProvider.h:166
floating point.
Definition: ISettingsProvider.h:165
Error
Config parsing error codes.
Definition: ISettingsProvider.h:37
3D floating point.
Definition: ISettingsProvider.h:167
#define FSDK_API
Dummy.
Definition: Def.h:27
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:56
(exclusive to xml_node::append_buffer)
A structure that encapsulates an action result enumeration.
Definition: Result.h:27
Common data types and structures.
Configuration parameter key.
Definition: ISettingsProvider.h:615
Definition: ISettingsProvider.h:123
Object system types and interfaces.
Definition: ISettingsProvider.h:131
Common SDK error codes.
FSDK_API ResultValue< FSDKError, ISettingsProviderPtr > createSettingsProviderFromString(const char *content) noexcept
Creates a settings provider from the xml-formatted string.
Definition: Result.h:8
Parser could not determine tag type.
4D floating point.
Definition: ISettingsProvider.h:168
Type
Value type.
Definition: ISettingsProvider.h:159
Desc m_desc
Parameter description.
Definition: ISettingsProvider.h:697
Base strong reference counted object interface.
Definition: IRefCounted.h:37
Definition: ISettingsProvider.h:147
Value data.
Definition: ISettingsProvider.h:118
Definition: ISettingsProvider.h:139
tag was not closed or there was an excessive closing tag)
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:119
Configuration parameter description.
Definition: ISettingsProvider.h:665
Definition: ISettingsProvider.h:127
bool operator<(Version lhs, Version rhs) noexcept
Check if one version is less than another.
Definition: Version.h:36
Integer.
Definition: ISettingsProvider.h:161
File was not found during load_file()
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:21
Definition: ISettingsProvider.h:143
Definition: ISettingsProvider.h:135
4D integer.
Definition: ISettingsProvider.h:164
Parsing resulted in a document without element nodes.
Parsing error occurred while parsing end element tag.
Settings section is invalid or absent.
2D integer.
Definition: ISettingsProvider.h:162
Parsing error occurred while parsing PCDATA section.
Configuration parameter entry.
Definition: ISettingsProvider.h:694
FSDKError
Common SDK error codes.
Definition: FSDKError.h:17
Configuration parameter value.
Definition: ISettingsProvider.h:113
Parsing error occurred while parsing start element tag.
Error reading from file/stream.
FSDK_API ResultValue< FSDKError, ISettingsProviderPtr > createSettingsProvider(const char *path) noexcept
Create a settings provider.
3D integer.
Definition: ISettingsProvider.h:163
Value m_value
Parameter value.
Definition: ISettingsProvider.h:696
Unkown value type.
Definition: ISettingsProvider.h:160
Definition: ISettingsProvider.h:151
Parsing error occurred while parsing element attribute.
Parsing error occurred while parsing CDATA section.
SDK settings provider interface.
Definition: ISettingsProvider.h:32