Face Engine SDK  5.23.1
A face detection, recognition and tracking engine.
include/fsdk/ISettingsProvider.h
Go to the documentation of this file.
00001 
00008 #pragma once
00009 
00010 #include <cstring>
00011 #include <fsdk/FSDKError.h>
00012 #include <fsdk/IObject.h>
00013 #include <fsdk/Types.h>
00014 #include <string>
00015 
00016 namespace fsdk {
00017 
00018 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00019     DECLARE_SMARTPTR(ISettingsProvider);
00020 #endif
00021 
00032     struct FSDK_API ISettingsProvider : IRefCounted {
00033 
00037         enum class Error : uint32_t {
00038             Ok,                
00039             IOError,           
00040             Memory,            
00041             Internal,          
00042             InvalidPi,         
00043             InvalidTag,        
00044             InvalidCdata,      
00045             FileNotFound,      
00046             InvalidPcdata,     
00047             InvalidDocType,    
00048             InvalidSettings,   
00049             InvalidComment,    
00050             InvalidAttribute,  
00051             InvalidEndElement, 
00052             AppendInvalidRoot, 
00053 
00054             NoDocumentElement, 
00055             EndElementMismatch,  
00056 
00057             InvalidStartElement, 
00058             MemoryAllocationFailed, 
00059         };
00060 
00066         virtual const char* getDefaultPath() const noexcept = 0;
00067 
00072         virtual void setDefaultPath(const char* path) noexcept = 0;
00073 
00080         virtual Result<Error> load(const char* path) noexcept = 0;
00081 
00089         virtual Result<Error> loadFromString(const char* content) noexcept = 0;
00090 
00096         virtual bool save(const char* path) const noexcept = 0;
00097 
00102         virtual void clear() noexcept = 0;
00103 
00108         virtual bool isEmpty() const noexcept = 0;
00109 
00113         struct FSDK_API Value {
00114 
00118             union Data {
00119                 struct Int1 {
00120                     int m_value;
00121                 } m_int1; 
00122 
00123                 struct Int2 {
00124                     int m_value[2];
00125                 } m_int2; 
00126 
00127                 struct Int3 {
00128                     int m_value[3];
00129                 } m_int3; 
00130 
00131                 struct Int4 {
00132                     int m_value[4];
00133                 } m_int4; 
00134 
00135                 struct Float1 {
00136                     float m_value;
00137                 } m_float1; 
00138 
00139                 struct Float2 {
00140                     float m_value[2];
00141                 } m_float2; 
00142 
00143                 struct Float3 {
00144                     float m_value[3];
00145                 } m_float3; 
00146 
00147                 struct Float4 {
00148                     float m_value[4];
00149                 } m_float4; 
00150 
00151                 struct String {
00152                     char* m_value;
00153                 } m_string; 
00154             } m_data;     
00155 
00159             enum Type {
00160                 Undefined, 
00161                 Int1,      
00162                 Int2,      
00163                 Int3,      
00164                 Int4,      
00165                 Float1,    
00166                 Float2,    
00167                 Float3,    
00168                 Float4,    
00169                 String     
00170             } m_type;    
00171 
00176             Value() noexcept;
00177 
00182             Value(int x) noexcept;
00183 
00189             Value(int x, int y) noexcept;
00190 
00197             Value(int x, int y, int z) noexcept;
00198 
00206             Value(int x, int y, int z, int w) noexcept;
00207 
00212             Value(float x) noexcept;
00213 
00219             Value(float x, float y) noexcept;
00226             Value(float x, float y, float z) noexcept;
00227 
00235             Value(float x, float y, float z, float w) noexcept;
00236 
00242             Value(const char* string) noexcept;
00243 
00248             Value(const Rect& rect) noexcept;
00249 
00254             Value(const Size& size) noexcept;
00255 
00260             Value(const Point2f& point) noexcept;
00261 
00266             Value(bool x) noexcept;
00267 
00272             operator bool() const noexcept;
00273 
00279             bool is(Type type) const noexcept;
00280 
00281 
00286             bool setString(const char* string) noexcept;
00287 
00294             bool getString(char* string) const noexcept;
00295 
00296 
00301             void setRect(const Rect& rect) noexcept;
00302 
00310             bool getRect(Rect* rect) const noexcept;
00311 
00312 
00317             void setSize(const Size& size) noexcept;
00318 
00326             bool getSize(Size* size) const noexcept;
00327 
00328 
00333             void setPoint2i(const Point2i& point) noexcept;
00334 
00342             bool getPoint2i(Point2i* point) const noexcept;
00343 
00344 
00349             void setPoint2f(const Point2f& point) noexcept;
00350 
00358             bool getPoint2f(Point2f* point) const noexcept;
00359 
00364             void setBool(bool x) noexcept;
00365 
00373             bool getBool(bool* x) const noexcept;
00374 
00375 
00380             void setInt(int x) noexcept;
00381 
00388             bool getInt(int* x) const noexcept;
00389 
00390 
00396             void setInt(int x, int y) noexcept;
00397 
00406             bool getInt(int* x, int* y) const noexcept;
00407 
00408 
00415             void setInt(int x, int y, int z) noexcept;
00416 
00426             bool getInt(int* x, int* y, int* z) const noexcept;
00427 
00428 
00436             void setInt(int x, int y, int z, int w) noexcept;
00437 
00448             bool getInt(int* x, int* y, int* z, int* w) const noexcept;
00449 
00450 
00455             void setFloat(float x) noexcept;
00456 
00463             bool getFloat(float* x) const noexcept;
00464 
00465 
00471             void setFloat(float x, float y) noexcept;
00472 
00481             bool getFloat(float* x, float* y) const noexcept;
00482 
00483 
00490             void setFloat(float x, float y, float z) noexcept;
00491 
00501             bool getFloat(float* x, float* y, float* z) const noexcept;
00502 
00503 
00511             void setFloat(float x, float y, float z, float w) noexcept;
00512 
00523             bool getFloat(float* x, float* y, float* z, float* w) const noexcept;
00524 
00525 
00532             float asFloat(float defaultValue = 0.f) const noexcept;
00533 
00534 
00542             Point2f asPoint2f(const Point2f& defaultValue = Point2f()) const noexcept;
00543 
00544 
00552             bool asBool(bool defaultValue = false) const noexcept;
00553 
00554 
00561             int asInt(int defaultValue = 0) const noexcept;
00562 
00563 
00571             Size asSize(const Size& defaultValue = Size()) const noexcept;
00572 
00573 
00581             Point2i asPoint2i(const Point2i& defaultValue = Point2i()) const noexcept;
00582 
00583 
00591             Rect asRect(const Rect& defaultValue = Rect()) const noexcept;
00592 
00593 
00601             const char* asString(const char* defaultValue = "") const noexcept;
00602 
00603             inline Value(const Value& other) = delete;
00604             Value(Value&& other);
00605 
00606             inline Value& operator=(const Value& other) = delete;
00607             Value& operator=(Value&& other);
00608 
00609             void swap(Value& first, Value& second);
00610 
00611             ~Value();
00612         };
00613 
00615         struct FSDK_API Key {
00616 
00618             Key() noexcept;
00619 
00625             Key(const char* section, const char* parameter) noexcept;
00626 
00631             const char* getSection() const noexcept;
00632 
00637             const char* getParameter() const noexcept;
00638 
00643             void setSection(const char* section) noexcept;
00644 
00649             void setParameter(const char* parameter) noexcept;
00650 
00656             bool operator<(const ISettingsProvider::Key& other) const noexcept;
00657 
00658         protected:
00659             static const unsigned int m_bufferLength = 128;
00660             char m_section[m_bufferLength];   
00661             char m_parameter[m_bufferLength]; 
00662         };
00663 
00665         struct FSDK_API Desc {
00666 
00668             Desc() noexcept;
00669 
00674             Desc(const char* desc) noexcept;
00675 
00680             const char* getDesc() const noexcept;
00681 
00686             void setDesc(const char* desc) noexcept;
00687 
00688         protected:
00689             static const unsigned int m_bufferLength = 256;
00690             char m_desc[m_bufferLength]; 
00691         };
00692 
00694         struct FSDK_API Entry {
00695 
00696             Value m_value; 
00697             Desc m_desc;   
00698 
00700             Entry() noexcept = default;
00701 
00702             Entry(Entry&& right);
00703 
00704             Entry& operator=(Entry&& right);
00705 
00706             void swap(Entry& first, Entry& second);
00712             Entry(const Desc& desc, Value&& value) noexcept;
00713 
00718             void setDesc(const Desc& desc) noexcept;
00719 
00724             void setValue(Value&& value) noexcept;
00725 
00730             const Desc& getDesc() const noexcept;
00731 
00736             const Value& getValue() const noexcept;
00737         };
00738 
00746         virtual void setDesc(const Key& key, const Desc& desc) noexcept = 0;
00747 
00756         void setDesc(const char* section, const char* parameter, const Desc& desc) noexcept;
00757 
00765         virtual void setValue(const Key& key, Value&& value) noexcept = 0;
00766 
00775         void setValue(const char* section, const char* parameter, Value&& value) noexcept;
00776 
00784         virtual void setEntry(const Key& key, Entry&& entry) noexcept = 0;
00785 
00794         void setEntry(const Key& key, const Desc& desc, Value&& value) noexcept;
00795 
00805         void setEntry(const char* section, const char* parameter, const Desc& desc, Value&& value) noexcept;
00806 
00814         virtual const Entry& getEntry(const Key& key) const noexcept = 0;
00815 
00823         Desc getDesc(const Key& key) const noexcept;
00824 
00833         Desc getDesc(const char* section, const char* parameter) const noexcept;
00834 
00842         const Value& getValue(const Key& key) const noexcept;
00843 
00852         const Value& getValue(const char* section, const char* parameter) const noexcept;
00853     };
00854 
00860     FSDK_API fsdk::ResultValue<fsdk::FSDKError, fsdk::ISettingsProviderPtr>
00861     createSettingsProvider(const char* path) noexcept;
00862 
00869     FSDK_API ResultValue<FSDKError, ISettingsProviderPtr>
00870     createSettingsProviderFromString(const char* content) noexcept;
00871 
00875     template <>
00876     struct ErrorTraits<ISettingsProvider::Error> {
00877 
00878         static bool isOk(ISettingsProvider::Error error) noexcept {
00879             return error == ISettingsProvider::Error::Ok;
00880         }
00881 
00882         static const char* toString(ISettingsProvider::Error error) noexcept {
00883             switch(error) {
00884             case ISettingsProvider::Error::Ok:
00885                 return "Ok";
00886             case ISettingsProvider::Error::Memory:
00887                 return "Could not allocate memory";
00888             case ISettingsProvider::Error::IOError:
00889                 return "Error reading from file";
00890             case ISettingsProvider::Error::Internal:
00891                 return "Internal error";
00892             case ISettingsProvider::Error::InvalidPi:
00893                 return "Error during document declaration/processing instruction parsing";
00894             case ISettingsProvider::Error::InvalidTag:
00895                 return "Parser could not determine tag type";
00896             case ISettingsProvider::Error::InvalidCdata:
00897                 return "Error during CDATA section parsing";
00898             case ISettingsProvider::Error::FileNotFound:
00899                 return "File was not found";
00900             case ISettingsProvider::Error::InvalidPcdata:
00901                 return "Error during PCDATA section parsing";
00902             case ISettingsProvider::Error::InvalidComment:
00903                 return "Error during comment parsing";
00904             case ISettingsProvider::Error::InvalidDocType:
00905                 return "Error during document type declaration parsing";
00906             case ISettingsProvider::Error::InvalidSettings:
00907                 return "Settings sections is invalid or absent";
00908             case ISettingsProvider::Error::InvalidAttribute:
00909                 return "Error during element attribute parsing";
00910             case ISettingsProvider::Error::InvalidEndElement:
00911                 return "Error during end element tag parsing";
00912             case ISettingsProvider::Error::AppendInvalidRoot:
00913                 return "Root type is not node_element or node_document";
00914             case ISettingsProvider::Error::NoDocumentElement:
00915                 return "Document without element nodes";
00916             case ISettingsProvider::Error::EndElementMismatch:
00917                 return "Mismatch of start-end tags";
00918             case ISettingsProvider::Error::InvalidStartElement:
00919                 return "Error during start element tag parsing";
00920             default:
00921                 return "Unknown error";
00922             }
00923         }
00924     };
00925 
00927 } // namespace fsdk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines