[DEV] cmake file update and start update to std::map

This commit is contained in:
Edouard DUPIN 2014-03-04 21:18:41 +01:00
parent 041266c5f9
commit d431e72b09
6 changed files with 110 additions and 53 deletions

View File

@ -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} )

View File

@ -10,21 +10,51 @@
#include <etk/archive/Zip.h>
#include <etk/debug.h>
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; iii<m_content.size(); iii++) {
int32_t size = m_content.getValue(iii).getTheoricSize();
int32_t sizeR = m_content.getValue(iii).size();
TK_INFO(" element : " << m_content.getKey(iii) << " size=" << size << " allocated=" << sizeR);
for (auto &it : m_content) {
int32_t size = it.second.getTheoricSize();
int32_t sizeR = it.second.size();
TK_INFO(" element : " << it.first << " size=" << size << " allocated=" << sizeR);
}
}
@ -46,25 +76,27 @@ etk::Archive* etk::Archive::load(const std::string& _fileName) {
void etk::Archive::open(const std::string& _key) {
if (m_content.exist(_key)==false) {
auto it = m_content.find(_key);
if (it == m_content.end()) {
TK_ERROR("Try open an unexistant file : '" << _key << "'");
return;
}
if (m_content[_key].getNumberOfRef()==-1) {
loadFile(m_content.getId(_key));
m_content[_key].increaseRef();
if (it->second.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();
}
}

View File

@ -11,7 +11,7 @@
#ifndef __ETK_ARCHIVE_H__
#define __ETK_ARCHIVE_H__
#include <etk/Hash.h>
#include <map>
namespace etk {
class Archive {
@ -68,7 +68,7 @@ namespace etk {
return m_fileName;
};
protected:
etk::Hash<Content> m_content;
std::map<std::string, Content> 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<std::string, Content>::iterator& it) { };
public:
/**
* @brief Load an Achive with a specific name.

View File

@ -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<std::string, etk::Archive::Content>(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<std::string, Content>::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);

View File

@ -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<std::string, Content>::iterator& it);
};
};
};

View File

@ -12,7 +12,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <etk/tool.h>
#include <etk/Hash.h>
#include <map>
#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<std::string> g_listTheme;
static std::map<std::string, std::string> g_listTheme;
void etk::theme::setName(const std::string& _refName, const std::string& _folderName) {
g_listTheme.set(_refName, _folderName);
g_listTheme.insert(std::pair<std::string,std::string>(_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<std::string> etk::theme::list(void) {
std::vector<std::string> tmpp;
return tmpp;
// TODO :
std::vector<std::string> keys;
for (auto &it : g_listTheme) {
keys.push_back(it.first);
}
return keys;
}
std::vector<std::u32string> etk::theme::listU(void) {
std::vector<std::u32string> tmpp;
return tmpp;
// TODO :
std::vector<std::u32string> keys;
for (auto &it : g_listTheme) {
keys.push_back(std::to_u32string(it.first));
}
return keys;
}
static etk::Hash<std::string> g_listThemeDefault;
static std::map<std::string, std::string> g_listThemeDefault;
void etk::theme::setNameDefault(const std::string& _refName, const std::string& _folderName) {
g_listThemeDefault.set(_refName, _folderName);
g_listThemeDefault.insert(std::pair<std::string,std::string>(_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";
}