Face Engine SDK  5.8.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,
46  InvalidPcdata,
47  InvalidDocType,
48  InvalidSettings,
49  InvalidComment,
50  InvalidAttribute,
51  InvalidEndElement,
52  AppendInvalidRoot,
53  NoDocumentElement,
54  EndElementMismatch,
55  InvalidStartElement,
56  MemoryAllocationFailed,
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 FSDK_API 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;
113 
117  enum Type {
127  String
128  } m_type;
129 
134  Value() noexcept;
135 
140  Value(int x) noexcept;
141 
147  Value(int x, int y) noexcept;
148 
155  Value(int x, int y, int z) noexcept;
156 
164  Value(int x, int y, int z, int w) noexcept;
165 
170  Value(float x) noexcept;
171 
177  Value(float x, float y) noexcept;
184  Value(float x, float y, float z) noexcept;
185 
193  Value(float x, float y, float z, float w) noexcept;
194 
200  Value(const char* string) noexcept;
201 
206  Value(const Rect& rect) noexcept;
207 
212  Value(const Size& size) noexcept;
213 
218  Value(const Point2f& point) noexcept;
219 
224  Value(bool x) noexcept;
225 
230  operator bool() const noexcept;
231 
237  bool is(Type type) const noexcept;
238 
239 
244  bool setString(const char* string) noexcept;
245 
252  bool getString(char* string) const noexcept;
253 
254 
259  void setRect(const Rect& rect) noexcept;
260 
267  bool getRect(Rect* rect) const noexcept;
268 
269 
274  void setSize(const Size& size) noexcept;
275 
282  bool getSize(Size* size) const noexcept;
283 
284 
289  void setPoint2i(const Point2i& point) noexcept;
290 
297  bool getPoint2i(Point2i* point) const noexcept;
298 
299 
304  void setPoint2f(const Point2f& point) noexcept;
305 
312  bool getPoint2f(Point2f* point) const noexcept;
313 
318  void setBool(bool x) noexcept;
319 
326  bool getBool(bool* x) const noexcept;
327 
328 
333  void setInt(int x) noexcept;
334 
341  bool getInt(int* x) const noexcept;
342 
343 
349  void setInt(int x, int y) noexcept;
350 
358  bool getInt(int* x, int* y) const noexcept;
359 
360 
367  void setInt(int x, int y, int z) noexcept;
368 
377  bool getInt(int* x, int* y, int* z) const noexcept;
378 
379 
387  void setInt(int x, int y, int z, int w) noexcept;
388 
398  bool getInt(int* x, int* y, int* z, int* w) const noexcept;
399 
400 
405  void setFloat(float x) noexcept;
406 
413  bool getFloat(float* x) const noexcept;
414 
415 
421  void setFloat(float x, float y) noexcept;
422 
430  bool getFloat(float* x, float* y) const noexcept;
431 
432 
439  void setFloat(float x, float y, float z) noexcept;
440 
449  bool getFloat(float* x, float* y, float* z) const noexcept;
450 
451 
459  void setFloat(float x, float y, float z, float w) noexcept;
460 
470  bool getFloat(float* x, float* y, float* z, float* w) const noexcept;
471 
472 
479  float asFloat(float defaultValue = 0.f) const noexcept;
480 
481 
488  Point2f asPoint2f(const Point2f& defaultValue = Point2f()) const noexcept;
489 
490 
497  bool asBool(bool defaultValue = false) const noexcept;
498 
499 
506  int asInt(int defaultValue = 0) const noexcept;
507 
508 
515  Size asSize(const Size& defaultValue = Size()) const noexcept;
516 
517 
524  Point2i asPoint2i(const Point2i& defaultValue = Point2i()) const noexcept;
525 
526 
533  Rect asRect(const Rect& defaultValue = Rect()) const noexcept;
534 
535 
543  const char* asString(const char* defaultValue = "") const noexcept;
544 
545  inline Value(const Value& other) = delete;
546  Value(Value&& other);
547 
548  inline Value& operator=(const Value& other) = delete;
549  Value& operator=(Value&& other);
550 
551  void swap(Value& first, Value& second);
552 
553  ~Value();
554  };
555 
556 
558  struct FSDK_API Key {
559 
561  Key() noexcept;
562 
568  Key(const char* section, const char* parameter) noexcept;
569 
574  const char* getSection() const noexcept;
575 
580  const char* getParameter() const noexcept;
581 
586  void setSection(const char* section) noexcept;
587 
592  void setParameter(const char* parameter) noexcept;
593 
599  bool operator < (const ISettingsProvider::Key& other) const noexcept;
600 
601  protected:
602  static const unsigned int m_bufferLength = 128;
603  char m_section [m_bufferLength];
604  char m_parameter [m_bufferLength];
605  };
606 
607 
609  struct FSDK_API Desc {
610 
612  Desc() noexcept;
613 
618  Desc(const char* desc) noexcept;
619 
624  const char* getDesc() const noexcept;
625 
630  void setDesc(const char* desc) noexcept;
631 
632  protected:
633  static const unsigned int m_bufferLength = 256;
634  char m_desc [m_bufferLength];
635  };
636 
637 
639  struct FSDK_API Entry {
640 
641  Value m_value;
643 
645  Entry() noexcept = default;
646 
647  Entry(Entry&& right);
648 
649  Entry& operator=(Entry&& right);
650 
651  void swap(Entry& first, Entry& second);
657  Entry(const Desc& desc, Value&& value) noexcept;
658 
663  void setDesc(const Desc& desc) noexcept;
664 
669  void setValue(Value&& value) noexcept;
670 
675  const Desc& getDesc() const noexcept;
676 
681  const Value& getValue() const noexcept;
682  };
683 
691  virtual void setDesc(const Key& key, const Desc& desc) noexcept = 0;
692 
701  void setDesc(
702  const char* section,
703  const char* parameter,
704  const Desc& desc) noexcept;
705 
713  virtual void setValue(const Key& key, Value&& value) noexcept = 0;
714 
723  void setValue(
724  const char* section,
725  const char* parameter,
726  Value&& value) noexcept;
727 
735  virtual void setEntry(const Key& key, Entry&& entry) noexcept = 0;
736 
745  void setEntry(
746  const Key& key,
747  const Desc& desc,
748  Value&& value) noexcept;
749 
759  void setEntry(
760  const char* section,
761  const char* parameter,
762  const Desc& desc,
763  Value&& value) noexcept;
764 
772  virtual const Entry& getEntry(const Key& key) const noexcept = 0;
773 
781  Desc getDesc(const Key& key) const noexcept;
782 
791  Desc getDesc(const char* section, const char* parameter) const noexcept;
792 
800  const Value& getValue(const Key& key) const noexcept;
801 
810  const Value& getValue(const char* section, const char* parameter) const noexcept;
811  };
812 
818  FSDK_API fsdk::ResultValue<fsdk::FSDKError, fsdk::ISettingsProviderPtr>
819  createSettingsProvider(const char* path) noexcept;
823  template<>
825 
826  static bool isOk(ISettingsProvider::Error error) noexcept {
827  return error == ISettingsProvider::Error::Ok;
828  }
829 
830  static const char* toString (ISettingsProvider::Error error) noexcept {
831  switch(error) {
833  return "Ok";
835  return "Could not allocate memory";
837  return "Error reading from file";
839  return "Internal error";
841  return "Error during document declaration/processing instruction parsing";
843  return "Parser could not determine tag type";
845  return "Error during CDATA section parsing";
847  return "File was not found";
849  return "Error during PCDATA section parsing";
851  return "Error during comment parsing";
853  return "Error during document type declaration parsing";
855  return "Settings sections is invalid or absent";
857  return "Error during element attribute parsing";
859  return "Error during end element tag parsing";
861  return "Root type is not node_element or node_document";
863  return "Document without element nodes";
865  return "Mismatch of start-end tags";
867  return "Error during start element tag parsing";
868  default: return "Unknown error";
869  }
870  }
871  };
873 }
Could not allocate memory.
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...
A structure that encapsulates an action result enumeration.
Definition: Result.h:29
Common data types and structures.
Configuration parameter key.
Definition: ISettingsProvider.h:558
Definition: ISettingsProvider.h:104
Object system types and interfaces.
Definition: ISettingsProvider.h:106
Common SDK error codes.
Definition: Result.h:9
Parser could not determine tag type.
4D floating point.
Definition: ISettingsProvider.h:126
Type
Value type.
Definition: ISettingsProvider.h:117
Desc m_desc
Parameter description.
Definition: ISettingsProvider.h:642
Base strong reference counted object interface.
Definition: IRefCounted.h:36
Definition: ISettingsProvider.h:110
Value data.
Definition: ISettingsProvider.h:102
Definition: ISettingsProvider.h:108
There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or th...
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
Configuration parameter description.
Definition: ISettingsProvider.h:609
Definition: ISettingsProvider.h:105
bool operator<(Version lhs, Version rhs) noexcept
Check if one version is less than another.
Definition: Version.h:36
Integer.
Definition: ISettingsProvider.h:119
File was not found during load_file()
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:25
Definition: ISettingsProvider.h:109
Definition: ISettingsProvider.h:107
4D integer.
Definition: ISettingsProvider.h:122
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:120
Parsing error occurred while parsing PCDATA section.
Configuration parameter entry.
Definition: ISettingsProvider.h:639
FSDKError
Common SDK error codes.
Definition: FSDKError.h:17
Configuration parameter value.
Definition: ISettingsProvider.h:97
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:121
Value m_value
Parameter value.
Definition: ISettingsProvider.h:641
Unkown value type.
Definition: ISettingsProvider.h:118
Definition: ISettingsProvider.h:111
Parsing error occurred while parsing element attribute.
Parsing error occurred while parsing CDATA section.
SDK settings provider interface.
Definition: ISettingsProvider.h:32