Face Engine SDK  5.33.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 ULong {
136  std::uint64_t m_value;
137  } m_uLong;
138 
139  struct Float1 {
140  float m_value;
141  } m_float1;
142 
143  struct Float2 {
144  float m_value[2];
145  } m_float2;
146 
147  struct Float3 {
148  float m_value[3];
149  } m_float3;
150 
151  struct Float4 {
152  float m_value[4];
153  } m_float4;
154 
155  struct String {
156  char* m_value;
157  } m_string;
158  } m_data;
159 
163  enum Type {
174  String
175  } m_type;
176 
181  Value() noexcept;
182 
187  Value(int x) noexcept;
188 
193  Value(std::uint64_t x) noexcept;
194 
200  Value(int x, int y) noexcept;
201 
208  Value(int x, int y, int z) noexcept;
209 
217  Value(int x, int y, int z, int w) noexcept;
218 
223  Value(float x) noexcept;
224 
230  Value(float x, float y) noexcept;
237  Value(float x, float y, float z) noexcept;
238 
246  Value(float x, float y, float z, float w) noexcept;
247 
253  Value(const char* string) noexcept;
254 
259  Value(const Rect& rect) noexcept;
260 
265  Value(const Size& size) noexcept;
266 
271  Value(const Point2f& point) noexcept;
272 
277  Value(bool x) noexcept;
278 
283  operator bool() const noexcept;
284 
290  bool is(Type type) const noexcept;
291 
292 
297  bool setString(const char* string) noexcept;
298 
305  bool getString(char* string) const noexcept;
306 
307 
312  void setRect(const Rect& rect) noexcept;
313 
321  bool getRect(Rect* rect) const noexcept;
322 
323 
328  void setSize(const Size& size) noexcept;
329 
337  bool getSize(Size* size) const noexcept;
338 
339 
344  void setPoint2i(const Point2i& point) noexcept;
345 
353  bool getPoint2i(Point2i* point) const noexcept;
354 
355 
360  void setPoint2f(const Point2f& point) noexcept;
361 
369  bool getPoint2f(Point2f* point) const noexcept;
370 
375  void setBool(bool x) noexcept;
376 
384  bool getBool(bool* x) const noexcept;
385 
386 
391  void setInt(int x) noexcept;
392 
399  bool getInt(int* x) const noexcept;
400 
405  void setULong(std::uint64_t x) noexcept;
406 
413  bool getULong(std::uint64_t* x) const noexcept;
414 
415 
421  void setInt(int x, int y) noexcept;
422 
431  bool getInt(int* x, int* y) const noexcept;
432 
433 
440  void setInt(int x, int y, int z) noexcept;
441 
451  bool getInt(int* x, int* y, int* z) const noexcept;
452 
453 
461  void setInt(int x, int y, int z, int w) noexcept;
462 
473  bool getInt(int* x, int* y, int* z, int* w) const noexcept;
474 
475 
480  void setFloat(float x) noexcept;
481 
488  bool getFloat(float* x) const noexcept;
489 
490 
496  void setFloat(float x, float y) noexcept;
497 
506  bool getFloat(float* x, float* y) const noexcept;
507 
508 
515  void setFloat(float x, float y, float z) noexcept;
516 
526  bool getFloat(float* x, float* y, float* z) const noexcept;
527 
528 
536  void setFloat(float x, float y, float z, float w) noexcept;
537 
548  bool getFloat(float* x, float* y, float* z, float* w) const noexcept;
549 
550 
557  float asFloat(float defaultValue = 0.f) const noexcept;
558 
559 
567  Point2f asPoint2f(const Point2f& defaultValue = Point2f()) const noexcept;
568 
569 
577  bool asBool(bool defaultValue = false) const noexcept;
578 
579 
586  int asInt(int defaultValue = 0) const noexcept;
587 
594  std::uint64_t asULong(std::uint64_t defaultValue = 0) const noexcept;
595 
596 
604  Size asSize(const Size& defaultValue = Size()) const noexcept;
605 
606 
614  Point2i asPoint2i(const Point2i& defaultValue = Point2i()) const noexcept;
615 
616 
624  Rect asRect(const Rect& defaultValue = Rect()) const noexcept;
625 
626 
634  const char* asString(const char* defaultValue = "") const noexcept;
635 
636  inline Value(const Value& other) = delete;
637  Value(Value&& other);
638 
639  inline Value& operator=(const Value& other) = delete;
640  Value& operator=(Value&& other);
641 
642  void swap(Value& first, Value& second);
643 
644  ~Value();
645  };
646 
648  struct FSDK_API Key {
649 
651  Key() noexcept;
652 
658  Key(const char* section, const char* parameter) noexcept;
659 
664  const char* getSection() const noexcept;
665 
670  const char* getParameter() const noexcept;
671 
676  void setSection(const char* section) noexcept;
677 
682  void setParameter(const char* parameter) noexcept;
683 
689  bool operator<(const ISettingsProvider::Key& other) const noexcept;
690 
691  protected:
692  static const unsigned int m_bufferLength = 128;
693  char m_section[m_bufferLength];
694  char m_parameter[m_bufferLength];
695  };
696 
698  struct FSDK_API Desc {
699 
701  Desc() noexcept;
702 
707  Desc(const char* desc) noexcept;
708 
713  const char* getDesc() const noexcept;
714 
719  void setDesc(const char* desc) noexcept;
720 
721  protected:
722  static const unsigned int m_bufferLength = 256;
723  char m_desc[m_bufferLength];
724  };
725 
727  struct FSDK_API Entry {
728 
729  Value m_value;
731 
733  Entry() noexcept = default;
734 
735  Entry(Entry&& right);
736 
737  Entry& operator=(Entry&& right);
738 
739  void swap(Entry& first, Entry& second);
745  Entry(const Desc& desc, Value&& value) noexcept;
746 
751  void setDesc(const Desc& desc) noexcept;
752 
757  void setValue(Value&& value) noexcept;
758 
763  const Desc& getDesc() const noexcept;
764 
769  const Value& getValue() const noexcept;
770  };
771 
779  virtual void setDesc(const Key& key, const Desc& desc) noexcept = 0;
780 
789  void setDesc(const char* section, const char* parameter, const Desc& desc) noexcept;
790 
798  virtual void setValue(const Key& key, Value&& value) noexcept = 0;
799 
808  void setValue(const char* section, const char* parameter, Value&& value) noexcept;
809 
817  virtual void setEntry(const Key& key, Entry&& entry) noexcept = 0;
818 
827  void setEntry(const Key& key, const Desc& desc, Value&& value) noexcept;
828 
838  void setEntry(const char* section, const char* parameter, const Desc& desc, Value&& value) noexcept;
839 
847  virtual const Entry& getEntry(const Key& key) const noexcept = 0;
848 
856  Desc getDesc(const Key& key) const noexcept;
857 
866  Desc getDesc(const char* section, const char* parameter) const noexcept;
867 
875  const Value& getValue(const Key& key) const noexcept;
876 
885  const Value& getValue(const char* section, const char* parameter) const noexcept;
886  };
887 
893  FSDK_API fsdk::ResultValue<fsdk::FSDKError, fsdk::ISettingsProviderPtr>
894  createSettingsProvider(const char* path) noexcept;
895 
902  FSDK_API ResultValue<FSDKError, ISettingsProviderPtr>
903  createSettingsProviderFromString(const char* content) noexcept;
904 
908  template <>
910 
911  static bool isOk(ISettingsProvider::Error error) noexcept {
912  return error == ISettingsProvider::Error::Ok;
913  }
914 
915  static const char* toString(ISettingsProvider::Error error) noexcept {
916  switch(error) {
918  return "Ok";
920  return "Could not allocate memory";
922  return "Error reading from file";
924  return "Internal error";
926  return "Error during document declaration/processing instruction parsing";
928  return "Parser could not determine tag type";
930  return "Error during CDATA section parsing";
932  return "File was not found";
934  return "Error during PCDATA section parsing";
936  return "Error during comment parsing";
938  return "Error during document type declaration parsing";
940  return "Settings sections is invalid or absent";
942  return "Error during element attribute parsing";
944  return "Error during end element tag parsing";
946  return "Root type is not node_element or node_document";
948  return "Document without element nodes";
950  return "Mismatch of start-end tags";
952  return "Error during start element tag parsing";
953  default:
954  return "Unknown error";
955  }
956  }
957  };
958 
960 } // namespace fsdk
Could not allocate memory.
2D floating point.
Definition: ISettingsProvider.h:171
floating point.
Definition: ISettingsProvider.h:170
Error
Config parsing error codes.
Definition: ISettingsProvider.h:37
3D floating point.
Definition: ISettingsProvider.h:172
#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:648
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:173
Type
Value type.
Definition: ISettingsProvider.h:163
Desc m_desc
Parameter description.
Definition: ISettingsProvider.h:730
Base strong reference counted object interface.
Definition: IRefCounted.h:37
Definition: ISettingsProvider.h:151
Value data.
Definition: ISettingsProvider.h:118
Definition: ISettingsProvider.h:143
tag was not closed or there was an excessive closing tag)
Parsing error occurred while parsing document declaration/processing instruction. ...
std::uint64_t.
Definition: ISettingsProvider.h:169
Parsing error occurred while parsing document type declaration.
Parsing error occurred while parsing comment.
Definition: ISettingsProvider.h:119
Configuration parameter description.
Definition: ISettingsProvider.h:698
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:165
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:147
Definition: ISettingsProvider.h:139
4D integer.
Definition: ISettingsProvider.h:168
Definition: ISettingsProvider.h:135
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:166
Parsing error occurred while parsing PCDATA section.
const char * toString(Image::MemoryResidence residence)
Returns a string representation of a MemoryResidence type.
Configuration parameter entry.
Definition: ISettingsProvider.h:727
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:167
Value m_value
Parameter value.
Definition: ISettingsProvider.h:729
Unkown value type.
Definition: ISettingsProvider.h:164
Definition: ISettingsProvider.h:155
Parsing error occurred while parsing element attribute.
Parsing error occurred while parsing CDATA section.
SDK settings provider interface.
Definition: ISettingsProvider.h:32