Face Engine SDK  5.8.0
A face detection, recognition and tracking engine.
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 
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 }
fsdk::ISettingsProvider::Error::IOError
@ IOError
Error reading from file/stream.
fsdk::ISettingsProvider::Value::Data::String
Definition: ISettingsProvider.h:111
fsdk::ISettingsProvider::Value::Int2
@ Int2
2D integer.
Definition: ISettingsProvider.h:120
fsdk::ISettingsProvider::Error
Error
Config parsing error codes.
Definition: ISettingsProvider.h:37
fsdk::ISettingsProvider::Value::Int4
@ Int4
4D integer.
Definition: ISettingsProvider.h:122
fsdk::ISettingsProvider::Error::InvalidTag
@ InvalidTag
Parser could not determine tag type.
fsdk::ISettingsProvider::Error::InvalidEndElement
@ InvalidEndElement
Parsing error occurred while parsing end element tag.
fsdk::FSDKError
FSDKError
Common SDK error codes.
Definition: FSDKError.h:17
fsdk::FutureError::Ok
@ Ok
All good.
fsdk::ISettingsProvider::Value::Float4
@ Float4
4D floating point.
Definition: ISettingsProvider.h:126
DECLARE_SMARTPTR
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:59
fsdk::ISettingsProvider::Value::Value
Value() noexcept
Initialize an empty value.
fsdk::ISettingsProvider::Error::InvalidPcdata
@ InvalidPcdata
Parsing error occurred while parsing PCDATA section.
fsdk::Vector2< int >
fsdk::ISettingsProvider::Error::InvalidSettings
@ InvalidSettings
Settings section is invalid or absent.
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::ISettingsProvider::Entry::m_value
Value m_value
Parameter value.
Definition: ISettingsProvider.h:641
fsdk::ISettingsProvider::Error::EndElementMismatch
@ EndElementMismatch
There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or th...
fsdk::BaseRect< int >
fsdk::ISettingsProvider::Value::Float2
@ Float2
2D floating point.
Definition: ISettingsProvider.h:124
fsdk::ISettingsProvider::Desc::Desc
Desc() noexcept
Initialize an empty description.
fsdk::createSettingsProvider
FSDK_API ResultValue< FSDKError, ISettingsProviderPtr > createSettingsProvider(const char *path) noexcept
Create a settings provider.
fsdk::ISettingsProvider::Key
Configuration parameter key.
Definition: ISettingsProvider.h:558
fsdk::ISettingsProvider::Value::Data::Int2
Definition: ISettingsProvider.h:104
fsdk::ISettingsProvider::Error::InvalidStartElement
@ InvalidStartElement
Parsing error occurred while parsing start element tag.
fsdk::ISettingsProvider::Error::FileNotFound
@ FileNotFound
File was not found during load_file()
fsdk::ISettingsProvider::Value::Data::Int4
Definition: ISettingsProvider.h:106
fsdk::ISettingsProvider
SDK settings provider interface.
Definition: ISettingsProvider.h:32
fsdk::ISettingsProvider::Error::AppendInvalidRoot
@ AppendInvalidRoot
Unable to append nodes since root type is not node_element or node_document (exclusive to xml_node::a...
fsdk::ISettingsProvider::Value::Data::Float3
Definition: ISettingsProvider.h:109
fsdk::ISettingsProvider::Desc
Configuration parameter description.
Definition: ISettingsProvider.h:609
FSDK_API
#define FSDK_API
Dummy.
Definition: Def.h:27
fsdk::ISettingsProvider::Entry::Entry
Entry() noexcept=default
Initialize an empty entry.
fsdk::ISettingsProvider::Error::InvalidAttribute
@ InvalidAttribute
Parsing error occurred while parsing element attribute.
fsdk::ISettingsProvider::Error::InvalidDocType
@ InvalidDocType
Parsing error occurred while parsing document type declaration.
fsdk::ISettingsProvider::Value::Data::Float1
Definition: ISettingsProvider.h:107
fsdk::ISettingsProvider::Value::Data::Int1
Definition: ISettingsProvider.h:103
fsdk::ISettingsProvider::Value::Data::Int3
Definition: ISettingsProvider.h:105
fsdk::ISettingsProvider::Error::Internal
@ Internal
Internal error occurred.
fsdk::ErrorTraits
Definition: Result.h:10
fsdk::ISettingsProvider::Error::Memory
@ Memory
Could not allocate memory.
fsdk::ISettingsProvider::Value::Data::Float4
Definition: ISettingsProvider.h:110
fsdk::ISettingsProvider::Value
Configuration parameter value.
Definition: ISettingsProvider.h:97
fsdk::ISettingsProvider::Entry::m_desc
Desc m_desc
Parameter description.
Definition: ISettingsProvider.h:642
fsdk::ISettingsProvider::Value::Float3
@ Float3
3D floating point.
Definition: ISettingsProvider.h:125
fsdk::ISettingsProvider::Value::Float1
@ Float1
floating point.
Definition: ISettingsProvider.h:123
fsdk::ISettingsProvider::Value::Undefined
@ Undefined
Unkown value type.
Definition: ISettingsProvider.h:118
fsdk::ISettingsProvider::Error::InvalidComment
@ InvalidComment
Parsing error occurred while parsing comment.
fsdk::ISettingsProvider::Value::Int3
@ Int3
3D integer.
Definition: ISettingsProvider.h:121
fsdk::Result
A structure that encapsulates an action result enumeration.
Definition: Result.h:30
fsdk::ISettingsProvider::Value::Int1
@ Int1
Integer.
Definition: ISettingsProvider.h:119
FSDKError.h
Common SDK error codes.
fsdk::ISettingsProvider::Value::Type
Type
Value type.
Definition: ISettingsProvider.h:117
fsdk::ISettingsProvider::Value::Data::Float2
Definition: ISettingsProvider.h:108
fsdk::ISettingsProvider::Error::InvalidCdata
@ InvalidCdata
Parsing error occurred while parsing CDATA section.
fsdk::ISettingsProvider::getDefaultPath
virtual const char * getDefaultPath() const noexcept=0
Get settings path this provider is bound to.
fsdk::ISettingsProvider::Error::InvalidPi
@ InvalidPi
Parsing error occurred while parsing document declaration/processing instruction.
fsdk::ISettingsProvider::Value::Data
Value data.
Definition: ISettingsProvider.h:102
fsdk::IRefCounted
Base strong reference counted object interface.
Definition: IRefCounted.h:36
fsdk::ISettingsProvider::Entry
Configuration parameter entry.
Definition: ISettingsProvider.h:639
fsdk::ISettingsProvider::Error::NoDocumentElement
@ NoDocumentElement
Parsing resulted in a document without element nodes.
fsdk::ISettingsProvider::Error::Ok
@ Ok
No error.
fsdk::ISettingsProvider::Key::Key
Key() noexcept
Initialize an empty key.
fsdk::ResultValue
Addon for Result to output some value aside the result. Specialization for copiable types.
Definition: ResultValue.h:25