diff --git a/CMakeLists.txt b/CMakeLists.txt index e72a32f..02a48bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,27 +31,53 @@ include_directories(.) #Create src file list set(src_files etk/debugGeneric.cpp + etk/debugGeneric.h etk/debug.cpp + etk/debug.h etk/stdTools.cpp + etk/stdTools.h etk/Stream.cpp + etk/Stream.h etk/RegExp.cpp + etk/RegExp.h etk/tool.cpp + etk/tool.h etk/Noise.cpp + etk/Noise.h etk/Color.cpp + etk/Color.h etk/math/Matrix4.cpp + etk/math/Matrix4.h etk/math/Vector2D.cpp + etk/math/Vector2D.h etk/math/Vector3D.cpp + etk/math/Vector3D.h etk/math/Vector4D.cpp + etk/math/Vector4D.h etk/os/FSNode.cpp + etk/os/FSNode.h etk/os/FSNodeRight.cpp + etk/os/FSNodeRight.h etk/archive/Archive.cpp + etk/archive/Archive.h etk/archive/Zip.cpp + etk/archive/Zip.h etk/os/Mutex.Generic.cpp + etk/os/Mutex.h etk/os/Semaphore.Generic.cpp + etk/os/Semaphore.h ) add_definitions( -DDEBUG_LEVEL=3 ) add_definitions( -DDEBUG=1 ) +if (APPLE) + add_definitions( -D__TARGET_OS__MacOs ) +elseif (UNIX) + add_definitions( -D__TARGET_OS__Linux ) +elseif (WIN32) + add_definitions( -D__TARGET_OS__Windows ) +endif () + #Create a static Lib: add_library(etk STATIC ${src_files} ) diff --git a/etk/archive/Archive.cpp b/etk/archive/Archive.cpp index 7e1687a..f4e841a 100644 --- a/etk/archive/Archive.cpp +++ b/etk/archive/Archive.cpp @@ -10,21 +10,51 @@ #include #include +static const etk::Archive::Content g_error; + + +const std::string& etk::Archive::getName(size_t _id) const { + size_t id = 0; + for (auto &it : m_content) { + if (id == _id) { + return it.first; + } + ++id; + } + static const std::string error(""); + return error; +} + +const etk::Archive::Content& etk::Archive::getContent(size_t _id) const { + size_t id = 0; + for (auto &it : m_content) { + if (id == _id) { + return it.second; + } + ++id; + } + return g_error; +} + const etk::Archive::Content& etk::Archive::getContent(const std::string& _key) const { - static const etk::Archive::Content g_error; - if (m_content.exist(_key)==false) { - TK_ERROR("File does not exist : " << _key); + auto it = m_content.find(_key); + if (it == m_content.end()) { return g_error; } - return m_content[_key]; + return it->second; +} + + +bool etk::Archive::exist(const std::string& _key) const { + return m_content.find(_key) != m_content.end(); } void etk::Archive::display(void) { - for (int32_t iii=0; iiisecond.getNumberOfRef()==-1) { + loadFile(it); + it->second.increaseRef(); } - m_content[_key].increaseRef(); + it->second.increaseRef(); } void etk::Archive::close(const std::string& _key) { - if (m_content.exist(_key)==false) { + auto it = m_content.find(_key); + if (it == m_content.end()) { TK_ERROR("Try close an unexistant file : '" << _key << "'"); return; } - if (m_content[_key].getNumberOfRef()==0){ + if (it->second.getNumberOfRef()==0){ TK_ERROR("Try close one more time the file : '" << _key << "'"); } else { - m_content[_key].decreaseRef(); + it->second.decreaseRef(); } } diff --git a/etk/archive/Archive.h b/etk/archive/Archive.h index 064e373..8f0d8ab 100644 --- a/etk/archive/Archive.h +++ b/etk/archive/Archive.h @@ -11,7 +11,7 @@ #ifndef __ETK_ARCHIVE_H__ #define __ETK_ARCHIVE_H__ -#include +#include namespace etk { class Archive { @@ -68,7 +68,7 @@ namespace etk { return m_fileName; }; protected: - etk::Hash m_content; + std::map m_content; public: /** * @brief Get the number of elements @@ -82,17 +82,13 @@ namespace etk { * @param[in] _id id of the element (must be < Size()) * @return FileName of the requested id */ - const std::string& getName(int32_t _id) const { - return m_content.getKey(_id); - }; + const std::string& getName(size_t _id) const; /** * @brief Get the File name of the ID * @param[in] _id id of the element (must be < Size()) * @return the archive content */ - const Content& getContent(int32_t _id) const { - return m_content.getValue(_id); - }; + const Content& getContent(size_t _id) const; /** * @brief Get the File name of the ID * @param[in] _key name of the file @@ -104,9 +100,7 @@ namespace etk { * @param[in] _key Name of the file * @return true if the file is present */ - bool exist(const std::string& _key) const { - return m_content.exist(_key); - }; + bool exist(const std::string& _key) const; /** * @brief Load the specific file in the memory * @param[in] _key Name of the file @@ -126,7 +120,7 @@ namespace etk { * @brief Request the load in memory of the concerned file. * @param[in] _id Id of the file to load. */ - virtual void loadFile(int32_t _id) { }; + virtual void loadFile(const std::map::iterator& it) { }; public: /** * @brief Load an Achive with a specific name. diff --git a/etk/archive/Zip.cpp b/etk/archive/Zip.cpp index b1b96ce..e34fdd2 100644 --- a/etk/archive/Zip.cpp +++ b/etk/archive/Zip.cpp @@ -36,7 +36,7 @@ etk::archive::Zip::Zip(const std::string& _fileName) : if(tmpFileName[strlen(tmpFileName) - 1] == '/' ) { // find directory ... } else { - m_content.add(tmpFileName, etk::Archive::Content(tmpFileInfo.uncompressed_size)); + m_content.insert(std::pair(tmpFileName, etk::Archive::Content(tmpFileInfo.uncompressed_size))); } /* Go the the next entry listed in the zip file. */ if((iii+1) < m_info.number_entry) { @@ -55,9 +55,8 @@ etk::archive::Zip::~Zip(void) { }; } -void etk::archive::Zip::loadFile(int32_t _id) { - std::string fileNameRequested = m_content.getKey(_id); - TK_VERBOSE("Real load file : " << _id << " = '" << fileNameRequested << "'"); +void etk::archive::Zip::loadFile(const std::map::iterator& it) { + TK_VERBOSE("Real load file : '" << it->first << "'"); unzGoToFirstFile(m_ctx); @@ -70,23 +69,23 @@ void etk::archive::Zip::loadFile(int32_t _id) { TK_ERROR("Could not read file info from the zip file '" << m_fileName << "'"); return; } - if (fileNameRequested == tmpFileName ) { + if (it->first == tmpFileName ) { // Entry is a file, so extract it. if(unzOpenCurrentFile(m_ctx) != UNZ_OK) { - TK_ERROR("Could not open file '" << fileNameRequested << "' into the zip file '" << m_fileName << "'"); + TK_ERROR("Could not open file '" << it->first << "' into the zip file '" << m_fileName << "'"); return; } int error = UNZ_OK; // request the resize of the data : - m_content.getValue(_id).getDataVector().resize(m_content.getValue(_id).getTheoricSize(), 0); - void* data = m_content.getValue(_id).data(); + it->second.getDataVector().resize(it->second.getTheoricSize(), 0); + void* data = it->second.data(); if(NULL == data) { TK_ERROR("Allocation error..."); return; } /* read the file */ do { - error = unzReadCurrentFile(m_ctx, data, m_content.getValue(_id).getTheoricSize()); + error = unzReadCurrentFile(m_ctx, data, it->second.getTheoricSize()); if ( error < 0 ) { TK_ERROR("Could not read file '" << tmpFileName << "' into the zip file '" << m_fileName << "': " << error); unzCloseCurrentFile(m_ctx); diff --git a/etk/archive/Zip.h b/etk/archive/Zip.h index 164d975..c416982 100644 --- a/etk/archive/Zip.h +++ b/etk/archive/Zip.h @@ -24,7 +24,7 @@ namespace etk { Zip(const std::string& _fileName); virtual ~Zip(void); protected: // herited functions : - virtual void loadFile(int32_t _id); + virtual void loadFile(const std::map::iterator& it); }; }; }; diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 715880f..542c283 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #ifdef __TARGET_OS__Windows #include "windows.h" #endif @@ -1708,18 +1708,19 @@ void etk::FSNode::fileFlush(void) { // TODO : Add an INIT to reset all allocated parameter : -static etk::Hash g_listTheme; +static std::map g_listTheme; void etk::theme::setName(const std::string& _refName, const std::string& _folderName) { - g_listTheme.set(_refName, _folderName); + g_listTheme.insert(std::pair(_refName, _folderName)); } void etk::theme::setName(const std::u32string& _refName, const std::u32string& _folderName) { setName(std::to_string(_refName), std::to_string(_folderName)); } std::string etk::theme::getName(const std::string& _refName) { - if (g_listTheme.exist(_refName) == true) { - return g_listTheme[_refName]; + auto it=g_listTheme.find(_refName); + if (it != g_listTheme.end()) { + return it->second; } return _refName; } @@ -1729,26 +1730,31 @@ std::u32string etk::theme::getName(const std::u32string& _refName) { // get the list of all the theme folder availlable in the user Home/appl std::vector etk::theme::list(void) { - std::vector tmpp; - return tmpp; - // TODO : + std::vector keys; + for (auto &it : g_listTheme) { + keys.push_back(it.first); + } + return keys; } std::vector etk::theme::listU(void) { - std::vector tmpp; - return tmpp; - // TODO : + std::vector keys; + for (auto &it : g_listTheme) { + keys.push_back(std::to_u32string(it.first)); + } + return keys; } -static etk::Hash g_listThemeDefault; +static std::map g_listThemeDefault; void etk::theme::setNameDefault(const std::string& _refName, const std::string& _folderName) { - g_listThemeDefault.set(_refName, _folderName); + g_listThemeDefault.insert(std::pair(_refName, _folderName)); } void etk::theme::setNameDefault(const std::u32string& _refName, const std::u32string& _folderName) { setNameDefault(std::to_string(_refName), std::to_string(_folderName)); } std::string etk::theme::getNameDefault(const std::string& _refName) { - if (g_listThemeDefault.exist(_refName) == true) { - return g_listThemeDefault[_refName]; + auto it=g_listThemeDefault.find(_refName); + if (it != g_listThemeDefault.end()) { + return it->second; } return "default"; }