diff --git a/src/lib/tvgLoaderMgr.cpp b/src/lib/tvgLoaderMgr.cpp index b2414157..8f59eabe 100644 --- a/src/lib/tvgLoaderMgr.cpp +++ b/src/lib/tvgLoaderMgr.cpp @@ -25,8 +25,43 @@ #include "tvgSvgLoader.h" #endif +/************************************************************************/ +/* Internal Class Implementation */ +/************************************************************************/ + static int initCnt = 0; + +static Loader* find(FileType type) +{ + switch(type) { + case FileType::Svg: { +#ifdef THORVG_SVG_LOADER_SUPPORT + return new SvgLoader; +#endif + break; + } + default: { + break; + } + } + return nullptr; +} + + +static Loader* find(const string& path) +{ + auto ext = path.substr(path.find_last_of(".") + 1); + if (!ext.compare("svg")) return find(FileType::Svg); + return nullptr; +} + + +/************************************************************************/ +/* External Class Implementation */ +/************************************************************************/ + + bool LoaderMgr::init() { if (initCnt > 0) return true; @@ -37,6 +72,7 @@ bool LoaderMgr::init() return true; } + bool LoaderMgr::term() { --initCnt; @@ -47,47 +83,22 @@ bool LoaderMgr::term() return true; } -unique_ptr findLoaderByType(FileType type) -{ - switch (type) { - case FileType::Svg : -#ifdef THORVG_SVG_LOADER_SUPPORT - return unique_ptr(new SvgLoader); -#endif - break; - default: - break; - } - return nullptr; -} - -unique_ptr findLoaderByExt(const string& path) -{ - string ext = path.substr(path.find_last_of(".") + 1); - if (!ext.compare("svg")) { - return findLoaderByType(FileType::Svg); - } - return nullptr; -} unique_ptr LoaderMgr::loader(const string& path) { - unique_ptr loader = nullptr; - loader = findLoaderByExt(path); - if (loader && loader->open(path.c_str())) { - return loader; - } + auto loader = find(path); + + if (loader && loader->open(path.c_str())) return unique_ptr(loader); + return nullptr; } + unique_ptr LoaderMgr::loader(const char* data, uint32_t size) { - unique_ptr loader = nullptr; for (int i = 0; i < static_cast(FileType::Unknown); i++) { - loader = findLoaderByType(static_cast(i)); - if (loader && loader->open(data, size)) { - return loader; - } + auto loader = find(static_cast(i)); + if (loader && loader->open(data, size)) return unique_ptr(loader); } return nullptr; } diff --git a/src/lib/tvgLoaderMgr.h b/src/lib/tvgLoaderMgr.h index 193294a1..a62f5ad5 100644 --- a/src/lib/tvgLoaderMgr.h +++ b/src/lib/tvgLoaderMgr.h @@ -24,7 +24,7 @@ #include "tvgLoader.h" -enum class FileType { Svg = 0, Unknown = 1}; +enum class FileType { Svg = 0, Unknown}; struct LoaderMgr {