| Face Engine SDK 5.12.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 <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
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,
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 {
132 Undefined,
133 Int1,
134 Int2,
135 Int3,
136 Int4,
137 Float1,
138 Float2,
139 Float3,
140 Float4,
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;
656 Desc m_desc;
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<>
848 struct ErrorTraits<ISettingsProvider::Error> {
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) {
856 case ISettingsProvider::Error::Ok:
857 return "Ok";
858 case ISettingsProvider::Error::Memory:
859 return "Could not allocate memory";
860 case ISettingsProvider::Error::IOError:
861 return "Error reading from file";
862 case ISettingsProvider::Error::Internal:
863 return "Internal error";
864 case ISettingsProvider::Error::InvalidPi:
865 return "Error during document declaration/processing instruction parsing";
866 case ISettingsProvider::Error::InvalidTag:
867 return "Parser could not determine tag type";
868 case ISettingsProvider::Error::InvalidCdata:
869 return "Error during CDATA section parsing";
870 case ISettingsProvider::Error::FileNotFound:
871 return "File was not found";
872 case ISettingsProvider::Error::InvalidPcdata:
873 return "Error during PCDATA section parsing";
874 case ISettingsProvider::Error::InvalidComment:
875 return "Error during comment parsing";
876 case ISettingsProvider::Error::InvalidDocType:
877 return "Error during document type declaration parsing";
878 case ISettingsProvider::Error::InvalidSettings:
879 return "Settings sections is invalid or absent";
880 case ISettingsProvider::Error::InvalidAttribute:
881 return "Error during element attribute parsing";
882 case ISettingsProvider::Error::InvalidEndElement:
883 return "Error during end element tag parsing";
884 case ISettingsProvider::Error::AppendInvalidRoot:
885 return "Root type is not node_element or node_document";
886 case ISettingsProvider::Error::NoDocumentElement:
887 return "Document without element nodes";
888 case ISettingsProvider::Error::EndElementMismatch:
889 return "Mismatch of start-end tags";
890 case ISettingsProvider::Error::InvalidStartElement:
891 return "Error during start element tag parsing";
892 default: return "Unknown error";
893 }
894 }
895 };
897 }
fsdk::ISettingsProvider::Error::Memory
Could not allocate memory.
fsdk::ISettingsProvider::Value::Float2
2D floating point.
Definition: ISettingsProvider.h:138
fsdk::ISettingsProvider::Value::Float1
floating point.
Definition: ISettingsProvider.h:137
fsdk::ISettingsProvider::Error
Error
Config parsing error codes.
Definition: ISettingsProvider.h:37
fsdk::ISettingsProvider::Value::Float3
3D floating point.
Definition: ISettingsProvider.h:139
FSDK_API
#define FSDK_API
Dummy.
Definition: Def.h:27
DECLARE_SMARTPTR
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:59
fsdk::ISettingsProvider::Error::AppendInvalidRoot
Unable to append nodes since root type is not node_element or node_document (exclusive to xml_node::a...
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::Result
A structure that encapsulates an action result enumeration.
Definition: Result.h:29
Types.h
Common data types and structures.
fsdk::ISettingsProvider::Key
Configuration parameter key.
Definition: ISettingsProvider.h:572
fsdk::ISettingsProvider::Value::Data::Int2
Definition: ISettingsProvider.h:118
IObject.h
Object system types and interfaces.
fsdk::ISettingsProvider::Value::Data::Int4
Definition: ISettingsProvider.h:120
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:9
fsdk::ISettingsProvider::Error::InvalidTag
Parser could not determine tag type.
fsdk::ISettingsProvider::Value::Float4
4D floating point.
Definition: ISettingsProvider.h:140
fsdk::ISettingsProvider::Value::Type
Type
Value type.
Definition: ISettingsProvider.h:131
fsdk::ISettingsProvider::Entry::m_desc
Desc m_desc
Parameter description.
Definition: ISettingsProvider.h:656
fsdk::IRefCounted
Base strong reference counted object interface.
Definition: IRefCounted.h:36
fsdk::ISettingsProvider::Value::Data::Float4
Definition: ISettingsProvider.h:124
fsdk::ISettingsProvider::Value::Data
Value data.
Definition: ISettingsProvider.h:116
fsdk::ISettingsProvider::Value::Data::Float2
Definition: ISettingsProvider.h:122
fsdk::ISettingsProvider::Error::EndElementMismatch
There was a mismatch of start-end tags (closing tag had incorrect name, some tag was not closed or th...
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:117
fsdk::ISettingsProvider::Desc
Configuration parameter description.
Definition: ISettingsProvider.h:623
fsdk::ISettingsProvider::Value::Data::Int3
Definition: ISettingsProvider.h:119
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:133
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:25
fsdk::ISettingsProvider::Value::Data::Float3
Definition: ISettingsProvider.h:123
fsdk::ISettingsProvider::Value::Data::Float1
Definition: ISettingsProvider.h:121
fsdk::ISettingsProvider::Value::Int4
4D integer.
Definition: ISettingsProvider.h:136
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:134
fsdk::ISettingsProvider::Error::InvalidPcdata
Parsing error occurred while parsing PCDATA section.
fsdk::BaseRect< int >
fsdk::ISettingsProvider::Entry
Configuration parameter entry.
Definition: ISettingsProvider.h:653
fsdk::FSDKError
FSDKError
Common SDK error codes.
Definition: FSDKError.h:17
fsdk::ISettingsProvider::Value
Configuration parameter value.
Definition: ISettingsProvider.h:111
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:135
fsdk::ISettingsProvider::Entry::m_value
Value m_value
Parameter value.
Definition: ISettingsProvider.h:655
fsdk::ISettingsProvider::Value::Undefined
Unkown value type.
Definition: ISettingsProvider.h:132
fsdk::Vector2< int >
fsdk::ISettingsProvider::Value::Data::String
Definition: ISettingsProvider.h:125
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