Face Engine SDK  5.14.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 <fsdk/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 
70  virtual void setDefaultPath(const char* path) noexcept = 0;
71 
78  virtual Result<Error> load(const char* path) noexcept = 0;
79 
86  virtual Result<Error> loadFromString(const char* content) noexcept = 0;
87 
93  virtual bool save(const char* path) const noexcept = 0;
94 
99  virtual void clear() noexcept = 0;
100 
105  virtual bool isEmpty() const noexcept = 0;
106 
107 
111  struct FSDK_API Value {
112 
116  union Data {
117  struct Int1 { int m_value; } m_int1;
118  struct Int2 { int m_value[2]; } m_int2;
119  struct Int3 { int m_value[3]; } m_int3;
120  struct Int4 { int m_value[4]; } m_int4;
121  struct Float1 { float m_value; } m_float1;
122  struct Float2 { float m_value[2]; } m_float2;
123  struct Float3 { float m_value[3]; } m_float3;
124  struct Float4 { float m_value[4]; } m_float4;
125  struct String { char* m_value; } m_string;
126  } m_data;
127 
131  enum Type {
141  String
142  } m_type;
143 
148  Value() noexcept;
149 
154  Value(int x) noexcept;
155 
161  Value(int x, int y) noexcept;
162 
169  Value(int x, int y, int z) noexcept;
170 
178  Value(int x, int y, int z, int w) noexcept;
179 
184  Value(float x) noexcept;
185 
191  Value(float x, float y) noexcept;
198  Value(float x, float y, float z) noexcept;
199 
207  Value(float x, float y, float z, float w) noexcept;
208 
214  Value(const char* string) noexcept;
215 
220  Value(const Rect& rect) noexcept;
221 
226  Value(const Size& size) noexcept;
227 
232  Value(const Point2f& point) noexcept;
233 
238  Value(bool x) noexcept;
239 
244  operator bool() const noexcept;
245 
251  bool is(Type type) const noexcept;
252 
253 
258  bool setString(const char* string) noexcept;
259 
266  bool getString(char* string) const noexcept;
267 
268 
273  void setRect(const Rect& rect) noexcept;
274 
281  bool getRect(Rect* rect) const noexcept;
282 
283 
288  void setSize(const Size& size) noexcept;
289 
296  bool getSize(Size* size) const noexcept;
297 
298 
303  void setPoint2i(const Point2i& point) noexcept;
304 
311  bool getPoint2i(Point2i* point) const noexcept;
312 
313 
318  void setPoint2f(const Point2f& point) noexcept;
319 
326  bool getPoint2f(Point2f* point) const noexcept;
327 
332  void setBool(bool x) noexcept;
333 
340  bool getBool(bool* x) const noexcept;
341 
342 
347  void setInt(int x) noexcept;
348 
355  bool getInt(int* x) const noexcept;
356 
357 
363  void setInt(int x, int y) noexcept;
364 
372  bool getInt(int* x, int* y) const noexcept;
373 
374 
381  void setInt(int x, int y, int z) noexcept;
382 
391  bool getInt(int* x, int* y, int* z) const noexcept;
392 
393 
401  void setInt(int x, int y, int z, int w) noexcept;
402 
412  bool getInt(int* x, int* y, int* z, int* w) const noexcept;
413 
414 
419  void setFloat(float x) noexcept;
420 
427  bool getFloat(float* x) const noexcept;
428 
429 
435  void setFloat(float x, float y) noexcept;
436 
444  bool getFloat(float* x, float* y) const noexcept;
445 
446 
453  void setFloat(float x, float y, float z) noexcept;
454 
463  bool getFloat(float* x, float* y, float* z) const noexcept;
464 
465 
473  void setFloat(float x, float y, float z, float w) noexcept;
474 
484  bool getFloat(float* x, float* y, float* z, float* w) const noexcept;
485 
486 
493  float asFloat(float defaultValue = 0.f) const noexcept;
494 
495 
502  Point2f asPoint2f(const Point2f& defaultValue = Point2f()) const noexcept;
503 
504 
511  bool asBool(bool defaultValue = false) const noexcept;
512 
513 
520  int asInt(int defaultValue = 0) const noexcept;
521 
522 
529  Size asSize(const Size& defaultValue = Size()) const noexcept;
530 
531 
538  Point2i asPoint2i(const Point2i& defaultValue = Point2i()) const noexcept;
539 
540 
547  Rect asRect(const Rect& defaultValue = Rect()) const noexcept;
548 
549 
557  const char* asString(const char* defaultValue = "") const noexcept;
558 
559  inline Value(const Value& other) = delete;
560  Value(Value&& other);
561 
562  inline Value& operator=(const Value& other) = delete;
563  Value& operator=(Value&& other);
564 
565  void swap(Value& first, Value& second);
566 
567  ~Value();
568  };
569 
570 
572  struct FSDK_API Key {
573 
575  Key() noexcept;
576 
582  Key(const char* section, const char* parameter) noexcept;
583 
588  const char* getSection() const noexcept;
589 
594  const char* getParameter() const noexcept;
595 
600  void setSection(const char* section) noexcept;
601 
606  void setParameter(const char* parameter) noexcept;
607 
613  bool operator < (const ISettingsProvider::Key& other) const noexcept;
614 
615  protected:
616  static const unsigned int m_bufferLength = 128;
617  char m_section [m_bufferLength];
618  char m_parameter [m_bufferLength];
619  };
620 
621 
623  struct FSDK_API Desc {
624 
626  Desc() noexcept;
627 
632  Desc(const char* desc) noexcept;
633 
638  const char* getDesc() const noexcept;
639 
644  void setDesc(const char* desc) noexcept;
645 
646  protected:
647  static const unsigned int m_bufferLength = 256;
648  char m_desc [m_bufferLength];
649  };
650 
651 
653  struct FSDK_API Entry {
654 
655  Value m_value;
657 
659  Entry() noexcept = default;
660 
661  Entry(Entry&& right);
662 
663  Entry& operator=(Entry&& right);
664 
665  void swap(Entry& first, Entry& second);
671  Entry(const Desc& desc, Value&& value) noexcept;
672 
677  void setDesc(const Desc& desc) noexcept;
678 
683  void setValue(Value&& value) noexcept;
684 
689  const Desc& getDesc() const noexcept;
690 
695  const Value& getValue() const noexcept;
696  };
697 
705  virtual void setDesc(const Key& key, const Desc& desc) noexcept = 0;
706 
715  void setDesc(
716  const char* section,
717  const char* parameter,
718  const Desc& desc) noexcept;
719 
727  virtual void setValue(const Key& key, Value&& value) noexcept = 0;
728 
737  void setValue(
738  const char* section,
739  const char* parameter,
740  Value&& value) noexcept;
741 
749  virtual void setEntry(const Key& key, Entry&& entry) noexcept = 0;
750 
759  void setEntry(
760  const Key& key,
761  const Desc& desc,
762  Value&& value) noexcept;
763 
773  void setEntry(
774  const char* section,
775  const char* parameter,
776  const Desc& desc,
777  Value&& value) noexcept;
778 
786  virtual const Entry& getEntry(const Key& key) const noexcept = 0;
787 
795  Desc getDesc(const Key& key) const noexcept;
796 
805  Desc getDesc(const char* section, const char* parameter) const noexcept;
806 
814  const Value& getValue(const Key& key) const noexcept;
815 
824  const Value& getValue(const char* section, const char* parameter) const noexcept;
825  };
826 
832  FSDK_API fsdk::ResultValue<fsdk::FSDKError, fsdk::ISettingsProviderPtr>
833  createSettingsProvider(const char* path) noexcept;
834 
841  FSDK_API ResultValue<FSDKError, ISettingsProviderPtr> createSettingsProviderFromString(const char* content) noexcept;
842 
843 
847  template<>
849 
850  static bool isOk(ISettingsProvider::Error error) noexcept {
851  return error == ISettingsProvider::Error::Ok;
852  }
853 
854  static const char* toString (ISettingsProvider::Error error) noexcept {
855  switch(error) {
857  return "Ok";
859  return "Could not allocate memory";
861  return "Error reading from file";
863  return "Internal error";
865  return "Error during document declaration/processing instruction parsing";
867  return "Parser could not determine tag type";
869  return "Error during CDATA section parsing";
871  return "File was not found";
873  return "Error during PCDATA section parsing";
875  return "Error during comment parsing";
877  return "Error during document type declaration parsing";
879  return "Settings sections is invalid or absent";
881  return "Error during element attribute parsing";
883  return "Error during end element tag parsing";
885  return "Root type is not node_element or node_document";
887  return "Document without element nodes";
889  return "Mismatch of start-end tags";
891  return "Error during start element tag parsing";
892  default: return "Unknown error";
893  }
894  }
895  };
897 }
Could not allocate memory.
2D floating point.
Definition: ISettingsProvider.h:138
floating point.
Definition: ISettingsProvider.h:137
Error
Config parsing error codes.
Definition: ISettingsProvider.h:37
3D floating point.
Definition: ISettingsProvider.h:139
#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:572
Definition: ISettingsProvider.h:118
Object system types and interfaces.
Definition: ISettingsProvider.h:120
Common SDK error codes.
Definition: Result.h:9
Parser could not determine tag type.
4D floating point.
Definition: ISettingsProvider.h:140
Type
Value type.
Definition: ISettingsProvider.h:131
Desc m_desc
Parameter description.
Definition: ISettingsProvider.h:656
Base strong reference counted object interface.
Definition: IRefCounted.h:36
Definition: ISettingsProvider.h:124
Value data.
Definition: ISettingsProvider.h:116
Definition: ISettingsProvider.h:122
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:117
Configuration parameter description.
Definition: ISettingsProvider.h:623
Definition: ISettingsProvider.h:119
FSDK_API ResultValue< FSDKError, ISettingsProviderPtr > createSettingsProviderFromString(const char *content) noexcept
Creates a settings provider from the xml-formatted string.
bool operator<(Version lhs, Version rhs) noexcept
Check if one version is less than another.
Definition: Version.h:36
Integer.
Definition: ISettingsProvider.h:133
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:123
Definition: ISettingsProvider.h:121
4D integer.
Definition: ISettingsProvider.h:136
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:134
Parsing error occurred while parsing PCDATA section.
Configuration parameter entry.
Definition: ISettingsProvider.h:653
FSDKError
Common SDK error codes.
Definition: FSDKError.h:17
Configuration parameter value.
Definition: ISettingsProvider.h:111
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:135
Value m_value
Parameter value.
Definition: ISettingsProvider.h:655
Unkown value type.
Definition: ISettingsProvider.h:132
Definition: ISettingsProvider.h:125
Parsing error occurred while parsing element attribute.
Parsing error occurred while parsing CDATA section.
SDK settings provider interface.
Definition: ISettingsProvider.h:32