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

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 <cstring>
13 #include <string>
14
15 namespace fsdk {
16
17 #ifndef DOXYGEN_SHOULD_SKIP_THIS
18 DECLARE_SMARTPTR(ISettingsProvider);
19 #endif
20
31 struct ISettingsProvider : IRefCounted {
32
36 enum class Error : uint32_t {
37 Ok,
38 IOError,
39 Memory,
40 Internal,
41 InvalidPi,
42 InvalidTag,
43 InvalidCdata,
44 FileNotFound,
45 InvalidPcdata,
46 InvalidDocType,
47 InvalidSettings,
48 InvalidComment,
49 InvalidAttribute,
50 InvalidEndElement,
51 AppendInvalidRoot,
52 NoDocumentElement,
53 EndElementMismatch,
54 InvalidStartElement,
55 MemoryAllocationFailed,
56 };
57
63 virtual const char* getDefaultPath() const noexcept = 0;
64
71 virtual Result<Error> load(const char* path) noexcept = 0;
72
78 virtual bool save(const char* path) const noexcept = 0;
79
84 virtual void clear() noexcept = 0;
85
90 virtual bool isEmpty() const noexcept = 0;
91
92
96 struct Value {
97
101 union Data {
102 struct Int1 { int m_value; } m_int1;
103 struct Int2 { int m_value[2]; } m_int2;
104 struct Int3 { int m_value[3]; } m_int3;
105 struct Int4 { int m_value[4]; } m_int4;
106 struct Float1 { float m_value; } m_float1;
107 struct Float2 { float m_value[2]; } m_float2;
108 struct Float3 { float m_value[3]; } m_float3;
109 struct Float4 { float m_value[4]; } m_float4;
110 struct String { char* m_value; } m_string;
111 } m_data;
112
116 enum Type {
117 Undefined,
118 Int1,
119 Int2,
120 Int3,
121 Int4,
122 Float1,
123 Float2,
124 Float3,
125 Float4,
126 String
127 } m_type;
128
133 Value() noexcept : m_type(Undefined) {}
134
139 Value(int x) noexcept { setInt(x); }
140
146 Value(int x, int y) noexcept { setInt(x, y); }
147
154 Value(int x, int y, int z) noexcept { setInt(x, y, z); }
155
163 Value(int x, int y, int z, int w) noexcept { setInt(x, y, z, w); }
164
169 Value(float x) noexcept { setFloat(x); }
170
176 Value(float x, float y) noexcept { setFloat(x, y); }
177
184 Value(float x, float y, float z) noexcept { setFloat(x, y, z); }
185
193 Value(float x, float y, float z, float w) noexcept { setFloat(x, y, z, w); }
194
200 Value(const char* string) noexcept { setString(string); }
201
206 Value(const Rect& rect) noexcept { setRect(rect); }
207
212 Value(const Size& size) noexcept { setSize(size); }
213
218 Value(const Point2f& point) noexcept { setPoint2f(point); }
219
224 Value(bool x) noexcept { setBool(x); }
225
230 operator bool() const noexcept { return !is(Undefined); }
231
237 bool is(Type type) const noexcept { return m_type == type; }
238
239
244 inline bool setString(const char* string) noexcept;
245
252 inline bool getString(char* string) const noexcept;
253
254
259 inline void setRect(const Rect& rect) noexcept;
260
267 inline bool getRect(Rect* rect) const noexcept;
268
269
274 inline void setSize(const Size& size) noexcept;
275
282 inline bool getSize(Size* size) const noexcept;
283
284
289 inline void setPoint2i(const Point2i& point) noexcept;
290
297 inline bool getPoint2i(Point2i* point) const noexcept;
298
299
304 inline void setPoint2f(const Point2f& point) noexcept;
305
312 inline bool getPoint2f(Point2f* point) const noexcept;
313
318 inline void setBool(bool x) noexcept;
319
326 inline bool getBool(bool* x) const noexcept;
327
328
333 inline void setInt(int x) noexcept;
334
341 inline bool getInt(int* x) const noexcept;
342
343
349 inline void setInt(int x, int y) noexcept;
350
358 inline bool getInt(int* x, int* y) const noexcept;
359
360
367 inline void setInt(int x, int y, int z) noexcept;
368
377 inline bool getInt(int* x, int* y, int* z) const noexcept;
378
379
387 inline void setInt(int x, int y, int z, int w) noexcept;
388
398 inline bool getInt(int* x, int* y, int* z, int* w) const noexcept;
399
400
405 inline void setFloat(float x) noexcept;
406
413 inline bool getFloat(float* x) const noexcept;
414
415
421 inline void setFloat(float x, float y) noexcept;
422
430 inline bool getFloat(float* x, float* y) const noexcept;
431
432
439 inline void setFloat(float x, float y, float z) noexcept;
440
449 inline bool getFloat(float* x, float* y, float* z) const noexcept;
450
451
459 inline void setFloat(float x, float y, float z, float w) noexcept;
460
470 inline bool getFloat(float* x, float* y, float* z, float* w) const noexcept;
471
472
479 inline float asFloat(float defaultValue = 0.f) const noexcept;
480
481
488 inline Point2f asPoint2f(const Point2f& defaultValue = Point2f()) const noexcept;
489
490
497 inline bool asBool(bool defaultValue = false) const noexcept;
498
499
506 inline int asInt(int defaultValue = 0) const noexcept;
507
508
515 inline Size asSize(const Size& defaultValue = Size()) const noexcept;
516
517
524 inline Point2i asPoint2i(const Point2i& defaultValue = Point2i()) const noexcept;
525
526
533 inline Rect asRect(const Rect& defaultValue = Rect()) const noexcept;
534
535
543 inline const char* asString(const char* defaultValue = "") const noexcept;
544
545 inline Value(const Value& other) = delete;
546 inline Value(Value&& other);
547
548 inline Value& operator=(const Value& other) = delete;
549 inline Value& operator=(Value&& other);
550
551 inline void swap(Value& first, Value& second);
552
553 inline ~Value();
554
555 };
556
557
559 struct Key {
560
562 inline Key() noexcept;
563
569 inline Key(const char* section, const char* parameter) noexcept;
570
575 const char* getSection() const noexcept {
576 return m_section;
577 }
578
583 const char* getParameter() const noexcept {
584 return m_parameter;
585 }
586
591 inline void setSection(const char* section) noexcept;
592
597 inline void setParameter(const char* parameter) noexcept;
598
604 inline bool operator < (const ISettingsProvider::Key& other) const noexcept;
605
606 protected:
607 static const unsigned int m_bufferLength = 128;
608 char m_section [m_bufferLength];
609 char m_parameter [m_bufferLength];
610 };
611
612
614 struct Desc {
615
617 inline Desc() noexcept;
618
623 inline Desc(const char* desc) noexcept;
624
629 const char* getDesc() const noexcept {
630 return m_desc;
631 }
632
637 inline void setDesc(const char* desc) noexcept;
638
639 protected:
640 static const unsigned int m_bufferLength = 256;
641 char m_desc [m_bufferLength];
642 };
643
644
646 struct Entry {
647
648 Value m_value;
649 Desc m_desc;
650
652 Entry() noexcept = default;
653
654 Entry(Entry&& right) :
655 m_value{std::move(right.m_value)},
656 m_desc{right.m_desc}
657 {}
658
659 Entry& operator=(Entry&& right) {
660 Entry tmp(std::move(right));
661 swap(tmp, right);
662 return *this;
663 }
664
665 void swap(Entry& first, Entry& second) {
666 std::swap(first.m_desc, second.m_desc);
667 std::swap(first.m_value, second.m_value);
668 }
674 inline Entry(const Desc& desc, Value&& value) noexcept;
675
680 inline void setDesc(const Desc& desc) noexcept;
681
686 inline void setValue(Value&& value) noexcept;
687
692 const Desc& getDesc() const noexcept {
693 return m_desc;
694 }
695
700 const Value& getValue() const noexcept {
701 return m_value;
702 }
703 };
704
712 virtual void setDesc(const Key& key, const Desc& desc) noexcept = 0;
713
722 void setDesc(
723 const char* section,
724 const char* parameter,
725 const Desc& desc) noexcept {
726 setDesc(Key(section, parameter), desc);
727 }
728
736 virtual void setValue(const Key& key, Value&& value) noexcept = 0;
737
746 void setValue(
747 const char* section,
748 const char* parameter,
749 Value&& value) noexcept {
750 setValue(Key(section, parameter), std::move(value));
751 }
752
760 virtual void setEntry(const Key& key, Entry&& entry) noexcept = 0;
761
770 void setEntry(
771 const Key& key,
772 const Desc& desc,
773 Value&& value) noexcept {
774 setEntry(key, Entry(desc, std::move(value)));
775 }
776
786 void setEntry(
787 const char* section,
788 const char* parameter,
789 const Desc& desc,
790 Value&& value) noexcept {
791 setEntry(Key(section, parameter), Entry(desc, std::move(value)));
792 }
793
801 virtual const Entry& getEntry(const Key& key) const noexcept = 0;
802
810 Desc getDesc(const Key& key) const noexcept {
811 return getEntry(key).m_desc;
812 }
813
822 Desc getDesc(
823 const char* section,
824 const char* parameter) const noexcept {
825 return getDesc(Key(section, parameter));
826 }
827
835 const Value& getValue(const Key& key) const noexcept {
836 return getEntry(key).m_value;
837 }
838
847 const Value& getValue(
848 const char* section,
849 const char* parameter) const noexcept {
850 return getValue(Key(section, parameter));
851 }
852 };
853
859 FSDK_API fsdk::ISettingsProvider* createSettingsProvider(const char* path) noexcept;
863 template<>
864 struct ErrorTraits<ISettingsProvider::Error> {
865
866 static bool isOk(ISettingsProvider::Error error) noexcept {
867 return error == ISettingsProvider::Error::Ok;
868 }
869
870 static const char* toString (ISettingsProvider::Error error) noexcept {
871 switch(error) {
872 case ISettingsProvider::Error::Ok:
873 return "Ok";
874 case ISettingsProvider::Error::Memory:
875 return "Could not allocate memory";
876 case ISettingsProvider::Error::IOError:
877 return "Error reading from file";
878 case ISettingsProvider::Error::Internal:
879 return "Internal error";
880 case ISettingsProvider::Error::InvalidPi:
881 return "Error during document declaration/processing instruction parsing";
882 case ISettingsProvider::Error::InvalidTag:
883 return "Parser could not determine tag type";
884 case ISettingsProvider::Error::InvalidCdata:
885 return "Error during CDATA section parsing";
886 case ISettingsProvider::Error::FileNotFound:
887 return "File was not found";
888 case ISettingsProvider::Error::InvalidPcdata:
889 return "Error during PCDATA section parsing";
890 case ISettingsProvider::Error::InvalidComment:
891 return "Error during comment parsing";
892 case ISettingsProvider::Error::InvalidDocType:
893 return "Error during document type declaration parsing";
894 case ISettingsProvider::Error::InvalidSettings:
895 return "Settings sections is invalid or absent";
896 case ISettingsProvider::Error::InvalidAttribute:
897 return "Error during element attribute parsing";
898 case ISettingsProvider::Error::InvalidEndElement:
899 return "Error during end element tag parsing";
900 case ISettingsProvider::Error::AppendInvalidRoot:
901 return "Root type is not node_element or node_document";
902 case ISettingsProvider::Error::NoDocumentElement:
903 return "Document without element nodes";
904 case ISettingsProvider::Error::EndElementMismatch:
905 return "Mismatch of start-end tags";
906 case ISettingsProvider::Error::InvalidStartElement:
907 return "Error during start element tag parsing";
908 default: return "Unknown error";
909 }
910 }
911 };
912
913 #include "ISettingsProvider.inl"
914
917 }
fsdk::ISettingsProvider::Error::Memory
Could not allocate memory.
fsdk::ISettingsProvider::clear
virtual void clear() noexcept=0
Clear settings.
fsdk::ISettingsProvider::Value::Float2
2D floating point.
Definition: ISettingsProvider.h:123
fsdk::ISettingsProvider::Value::Float1
floating point.
Definition: ISettingsProvider.h:122
fsdk::ISettingsProvider::Error
Error
Config parsing error codes.
Definition: ISettingsProvider.h:36
fsdk::ISettingsProvider::Value::Float3
3D floating point.
Definition: ISettingsProvider.h:124
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::ISettingsProvider::Key::getParameter
const char * getParameter() const noexcept
Get parameter name.
Definition: ISettingsProvider.h:583
fsdk::ISettingsProvider::Entry::setValue
void setValue(Value &&value) noexcept
Set value.
Definition: ISettingsProvider.h:377
fsdk::Result
A structure that encapsulates an action result enumeration.
Definition: Result.h:29
fsdk::ISettingsProvider::getEntry
virtual const Entry & getEntry(const Key &key) const noexcept=0
Find parameter entry.
Types.h
Common data types and structures.
fsdk::ISettingsProvider::Value::Value
Value() noexcept
Initialize an empty value.
Definition: ISettingsProvider.h:133
fsdk::ISettingsProvider::setDesc
virtual void setDesc(const Key &key, const Desc &desc) noexcept=0
Set parameter description.
fsdk::ISettingsProvider::Key
Configuration parameter key.
Definition: ISettingsProvider.h:559
fsdk::ISettingsProvider::Value::Data::Int2
Definition: ISettingsProvider.h:103
IObject.h
Object system types and interfaces.
fsdk::ISettingsProvider::Value::Data::Int4
Definition: ISettingsProvider.h:105
fsdk::ISettingsProvider::isEmpty
virtual bool isEmpty() const noexcept=0
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:125
fsdk::ISettingsProvider::Value::Type
Type
Value type.
Definition: ISettingsProvider.h:116
fsdk::ISettingsProvider::Entry::getDesc
const Desc & getDesc() const noexcept
Get description.
Definition: ISettingsProvider.h:692
fsdk::ISettingsProvider::Entry::m_desc
Desc m_desc
Parameter description.
Definition: ISettingsProvider.h:649
fsdk::ISettingsProvider::Value::Value
Value(const char *string) noexcept
Initialize a string value.
Definition: ISettingsProvider.h:200
fsdk::IRefCounted
Base strong reference counted object interface.
Definition: IRefCounted.h:36
fsdk::ISettingsProvider::Value::Data::Float4
Definition: ISettingsProvider.h:109
fsdk::ISettingsProvider::Value::Data
Value data.
Definition: ISettingsProvider.h:101
fsdk::ISettingsProvider::Entry::setDesc
void setDesc(const Desc &desc) noexcept
Set description.
Definition: ISettingsProvider.h:372
fsdk::ISettingsProvider::Value::Value
Value(float x, float y) noexcept
Initialize a 2d float value.
Definition: ISettingsProvider.h:176
fsdk::ISettingsProvider::Value::Data::Float2
Definition: ISettingsProvider.h:107
fsdk::ISettingsProvider::Value::Value
Value(const Point2f &point) noexcept
Initialize a point value.
Definition: ISettingsProvider.h:218
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::getValue
const Value & getValue(const Key &key) const noexcept
Get parameter value.
Definition: ISettingsProvider.h:835
fsdk::ISettingsProvider::Value::Value
Value(bool x) noexcept
Initialize a bool value.
Definition: ISettingsProvider.h:224
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::ISettingsProvider::Error::InvalidComment
Parsing error occurred while parsing comment.
fsdk::ISettingsProvider::Value::Data::Int1
Definition: ISettingsProvider.h:102
fsdk::ISettingsProvider::Value::Value
Value(int x) noexcept
Initialize an integer value.
Definition: ISettingsProvider.h:139
fsdk::ISettingsProvider::Desc
Configuration parameter description.
Definition: ISettingsProvider.h:614
fsdk::ISettingsProvider::Value::Data::Int3
Definition: ISettingsProvider.h:104
fsdk::ISettingsProvider::Error::Ok
No error.
fsdk::ISettingsProvider::Value::Value
Value(float x) noexcept
Initialize a float value.
Definition: ISettingsProvider.h:169
fsdk::ISettingsProvider::Entry::Entry
Entry() noexcept=default
Initialize an empty entry.
fsdk::operator<
bool operator<(Version lhs, Version rhs) noexcept
Check if one version is less than another.
Definition: Version.h:36
fsdk::ISettingsProvider::Desc::getDesc
const char * getDesc() const noexcept
Get description text.
Definition: ISettingsProvider.h:629
fsdk::ISettingsProvider::Desc::setDesc
void setDesc(const char *desc) noexcept
Set description text.
Definition: ISettingsProvider.h:360
fsdk::ISettingsProvider::Value::Int1
Integer.
Definition: ISettingsProvider.h:118
fsdk::ISettingsProvider::Value::Value
Value(const Rect &rect) noexcept
Initialize a rect value.
Definition: ISettingsProvider.h:206
fsdk::ISettingsProvider::Error::FileNotFound
File was not found during load_file()
fsdk::ISettingsProvider::getDesc
Desc getDesc(const Key &key) const noexcept
Get parameter description.
Definition: ISettingsProvider.h:810
fsdk::ISettingsProvider::Entry::getValue
const Value & getValue() const noexcept
Get value.
Definition: ISettingsProvider.h:700
fsdk::ISettingsProvider::Value::Data::Float1
Definition: ISettingsProvider.h:106
fsdk::ISettingsProvider::Value::Value
Value(int x, int y, int z, int w) noexcept
Initialize a 4d integer value.
Definition: ISettingsProvider.h:163
fsdk::ISettingsProvider::Value::Int4
4D integer.
Definition: ISettingsProvider.h:121
fsdk::ISettingsProvider::Value::Value
Value(int x, int y) noexcept
Initialize a 2d integer value.
Definition: ISettingsProvider.h:146
fsdk::createSettingsProvider
FSDK_API ISettingsProvider * createSettingsProvider(const char *path) noexcept
Create a settings provider.
fsdk::ISettingsProvider::Key::getSection
const char * getSection() const noexcept
Get section name.
Definition: ISettingsProvider.h:575
fsdk::ISettingsProvider::Value::Value
Value(float x, float y, float z) noexcept
Initialize a 3d float value.
Definition: ISettingsProvider.h:184
fsdk::ISettingsProvider::Error::NoDocumentElement
Parsing resulted in a document without element nodes.
fsdk::ISettingsProvider::load
virtual Result< Error > load(const char *path) noexcept=0
Load settings from given path.
fsdk::ISettingsProvider::Error::InvalidEndElement
Parsing error occurred while parsing end element tag.
fsdk::ISettingsProvider::Error::InvalidSettings
Settings section is invalid or absent.
fsdk::ISettingsProvider::Desc::Desc
Desc() noexcept
Initialize an empty description.
Definition: ISettingsProvider.h:352
fsdk::ISettingsProvider::Error::Internal
Internal error occurred.
fsdk::ISettingsProvider::Value::Int2
2D integer.
Definition: ISettingsProvider.h:119
fsdk::ISettingsProvider::Error::InvalidPcdata
Parsing error occurred while parsing PCDATA section.
fsdk::BaseRect< int >
fsdk::ISettingsProvider::Entry
Configuration parameter entry.
Definition: ISettingsProvider.h:646
fsdk::ISettingsProvider::Value
Configuration parameter value.
Definition: ISettingsProvider.h:96
fsdk::ISettingsProvider::getDefaultPath
virtual const char * getDefaultPath() const noexcept=0
Get settings path this provider is bound to.
fsdk::ISettingsProvider::Value::Value
Value(const Size &size) noexcept
Initialize a size value.
Definition: ISettingsProvider.h:212
fsdk::ISettingsProvider::Error::InvalidStartElement
Parsing error occurred while parsing start element tag.
fsdk::ISettingsProvider::Value::Value
Value(float x, float y, float z, float w) noexcept
Initialize a 4d float value.
Definition: ISettingsProvider.h:193
fsdk::ISettingsProvider::Error::IOError
Error reading from file/stream.
fsdk::ISettingsProvider::Value::Value
Value(int x, int y, int z) noexcept
Initialize a 3d integer value.
Definition: ISettingsProvider.h:154
fsdk::ISettingsProvider::setEntry
virtual void setEntry(const Key &key, Entry &&entry) noexcept=0
Set parameter.
fsdk::ISettingsProvider::getDesc
Desc getDesc(const char *section, const char *parameter) const noexcept
Get parameter description.
Definition: ISettingsProvider.h:822
fsdk::ISettingsProvider::save
virtual bool save(const char *path) const noexcept=0
Save settings values using the default path.
fsdk::ISettingsProvider::Value::is
bool is(Type type) const noexcept
Check if value type is of concrete type.
Definition: ISettingsProvider.h:237
fsdk::ISettingsProvider::Desc::m_desc
char m_desc[m_bufferLength]
Parameter description text.
Definition: ISettingsProvider.h:641
fsdk::ISettingsProvider::Error::MemoryAllocationFailed
memory allocation failed for internal data
fsdk::ISettingsProvider::setEntry
void setEntry(const char *section, const char *parameter, const Desc &desc, Value &&value) noexcept
Set parameter.
Definition: ISettingsProvider.h:786
fsdk::ISettingsProvider::Entry::m_value
Value m_value
Parameter value.
Definition: ISettingsProvider.h:648
fsdk::ISettingsProvider::Value::Undefined
Unkown value type.
Definition: ISettingsProvider.h:117
fsdk::Vector2< int >
fsdk::ISettingsProvider::Value::Data::String
Definition: ISettingsProvider.h:110
fsdk::ISettingsProvider::setDesc
void setDesc(const char *section, const char *parameter, const Desc &desc) noexcept
Set parameter description.
Definition: ISettingsProvider.h:722
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:31
fsdk::ISettingsProvider::setValue
virtual void setValue(const Key &key, Value &&value) noexcept=0
Set parameter value.
fsdk::ISettingsProvider::getValue
const Value & getValue(const char *section, const char *parameter) const noexcept
Get parameter value.
Definition: ISettingsProvider.h:847