| Face Engine SDK 5.31.2 A face detection, recognition and tracking engine.

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
32 struct FSDK_API ISettingsProvider : IRefCounted {
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 {
160 Undefined,
161 Int1,
162 Int2,
163 Int3,
164 Int4,
165 Float1,
166 Float2,
167 Float3,
168 Float4,
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;
697 Desc m_desc;
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 <>
876 struct ErrorTraits<ISettingsProvider::Error> {
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) {
884 case ISettingsProvider::Error::Ok:
885 return "Ok";
886 case ISettingsProvider::Error::Memory:
887 return "Could not allocate memory";
888 case ISettingsProvider::Error::IOError:
889 return "Error reading from file";
890 case ISettingsProvider::Error::Internal:
891 return "Internal error";
892 case ISettingsProvider::Error::InvalidPi:
893 return "Error during document declaration/processing instruction parsing";
894 case ISettingsProvider::Error::InvalidTag:
895 return "Parser could not determine tag type";
896 case ISettingsProvider::Error::InvalidCdata:
897 return "Error during CDATA section parsing";
898 case ISettingsProvider::Error::FileNotFound:
899 return "File was not found";
900 case ISettingsProvider::Error::InvalidPcdata:
901 return "Error during PCDATA section parsing";
902 case ISettingsProvider::Error::InvalidComment:
903 return "Error during comment parsing";
904 case ISettingsProvider::Error::InvalidDocType:
905 return "Error during document type declaration parsing";
906 case ISettingsProvider::Error::InvalidSettings:
907 return "Settings sections is invalid or absent";
908 case ISettingsProvider::Error::InvalidAttribute:
909 return "Error during element attribute parsing";
910 case ISettingsProvider::Error::InvalidEndElement:
911 return "Error during end element tag parsing";
912 case ISettingsProvider::Error::AppendInvalidRoot:
913 return "Root type is not node_element or node_document";
914 case ISettingsProvider::Error::NoDocumentElement:
915 return "Document without element nodes";
916 case ISettingsProvider::Error::EndElementMismatch:
917 return "Mismatch of start-end tags";
918 case ISettingsProvider::Error::InvalidStartElement:
919 return "Error during start element tag parsing";
920 default:
921 return "Unknown error";
922 }
923 }
924 };
925
927 } // namespace fsdk
fsdk::ISettingsProvider::Error::Memory
Could not allocate memory.
fsdk::ISettingsProvider::Value::Float2
2D floating point.
Definition: ISettingsProvider.h:166
fsdk::ISettingsProvider::Value::Float1
floating point.
Definition: ISettingsProvider.h:165
fsdk::ISettingsProvider::Error
Error
Config parsing error codes.
Definition: ISettingsProvider.h:37
fsdk::ISettingsProvider::Value::Float3
3D floating point.
Definition: ISettingsProvider.h:167
FSDK_API
#define FSDK_API
Dummy.
Definition: Def.h:27
DECLARE_SMARTPTR
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:56
fsdk::ISettingsProvider::Error::AppendInvalidRoot
(exclusive to xml_node::append_buffer)
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::Result
A structure that encapsulates an action result enumeration.
Definition: Result.h:27
Types.h
Common data types and structures.
fsdk::ISettingsProvider::Key
Configuration parameter key.
Definition: ISettingsProvider.h:615
fsdk::ISettingsProvider::Value::Data::Int2
Definition: ISettingsProvider.h:123
IObject.h
Object system types and interfaces.
fsdk::ISettingsProvider::Value::Data::Int4
Definition: ISettingsProvider.h:131
FSDKError.h
Common SDK error codes.
fsdk::createSettingsProviderFromString
FSDK_API ResultValue< FSDKError, ISettingsProviderPtr > createSettingsProviderFromString(const char *content) noexcept
Creates a settings provider from the xml-formatted string.
fsdk::FSDKError::Internal
Internal error.
fsdk::ErrorTraits
Definition: Result.h:8
fsdk::ISettingsProvider::Error::InvalidTag
Parser could not determine tag type.
fsdk::ISettingsProvider::Value::Float4
4D floating point.
Definition: ISettingsProvider.h:168
fsdk::ISettingsProvider::Value::Type
Type
Value type.
Definition: ISettingsProvider.h:159
fsdk::ISettingsProvider::Entry::m_desc
Desc m_desc
Parameter description.
Definition: ISettingsProvider.h:697
fsdk::IRefCounted
Base strong reference counted object interface.
Definition: IRefCounted.h:37
fsdk::ISettingsProvider::Value::Data::Float4
Definition: ISettingsProvider.h:147
fsdk::ISettingsProvider::Value::Data
Value data.
Definition: ISettingsProvider.h:118
fsdk::ISettingsProvider::Value::Data::Float2
Definition: ISettingsProvider.h:139
fsdk::ISettingsProvider::Error::EndElementMismatch
tag was not closed or there was an excessive closing tag)
fsdk::ISettingsProvider::Error::InvalidPi
Parsing error occurred while parsing document declaration/processing instruction. ...
fsdk::ISettingsProvider::Error::InvalidDocType
Parsing error occurred while parsing document type declaration.
fsdk::FSDKError::Ok
Ok.
fsdk::ISettingsProvider::Error::InvalidComment
Parsing error occurred while parsing comment.
fsdk::ISettingsProvider::Value::Data::Int1
Definition: ISettingsProvider.h:119
fsdk::ISettingsProvider::Desc
Configuration parameter description.
Definition: ISettingsProvider.h:665
fsdk::ISettingsProvider::Value::Data::Int3
Definition: ISettingsProvider.h:127
fsdk::ISettingsProvider::Error::Ok
No error.
fsdk::operator<
bool operator<(Version lhs, Version rhs) noexcept
Check if one version is less than another.
Definition: Version.h:36
fsdk::ISettingsProvider::Value::Int1
Integer.
Definition: ISettingsProvider.h:161
fsdk::ISettingsProvider::Error::FileNotFound
File was not found during load_file()
fsdk::ResultValue
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:21
fsdk::ISettingsProvider::Value::Data::Float3
Definition: ISettingsProvider.h:143
fsdk::ISettingsProvider::Value::Data::Float1
Definition: ISettingsProvider.h:135
fsdk::ISettingsProvider::Value::Int4
4D integer.
Definition: ISettingsProvider.h:164
fsdk::ISettingsProvider::Error::NoDocumentElement
Parsing resulted in a document without element nodes.
fsdk::ISettingsProvider::Error::InvalidEndElement
Parsing error occurred while parsing end element tag.
fsdk::ISettingsProvider::Error::InvalidSettings
Settings section is invalid or absent.
fsdk::ISettingsProvider::Error::Internal
Internal error occurred.
fsdk::ISettingsProvider::Value::Int2
2D integer.
Definition: ISettingsProvider.h:162
fsdk::ISettingsProvider::Error::InvalidPcdata
Parsing error occurred while parsing PCDATA section.
fsdk::toString
const char * toString(Image::MemoryResidence residence)
Returns a string representation of a MemoryResidence type.
fsdk::BaseRect< int >
fsdk::ISettingsProvider::Entry
Configuration parameter entry.
Definition: ISettingsProvider.h:694
fsdk::FSDKError
FSDKError
Common SDK error codes.
Definition: FSDKError.h:17
fsdk::ISettingsProvider::Value
Configuration parameter value.
Definition: ISettingsProvider.h:113
fsdk::ISettingsProvider::Error::InvalidStartElement
Parsing error occurred while parsing start element tag.
fsdk::ISettingsProvider::Error::IOError
Error reading from file/stream.
fsdk::createSettingsProvider
FSDK_API ResultValue< FSDKError, ISettingsProviderPtr > createSettingsProvider(const char *path) noexcept
Creates a settings provider.
fsdk::ISettingsProvider::Value::Int3
3D integer.
Definition: ISettingsProvider.h:163
fsdk::ISettingsProvider::Entry::m_value
Value m_value
Parameter value.
Definition: ISettingsProvider.h:696
fsdk::ISettingsProvider::Value::Undefined
Unkown value type.
Definition: ISettingsProvider.h:160
fsdk::Vector2< int >
fsdk::ISettingsProvider::Value::Data::String
Definition: ISettingsProvider.h:151
fsdk::ISettingsProvider::Error::InvalidAttribute
Parsing error occurred while parsing element attribute.
fsdk::ISettingsProvider::Error::InvalidCdata
Parsing error occurred while parsing CDATA section.
fsdk::ISettingsProvider
SDK settings provider interface.
Definition: ISettingsProvider.h:32