linux stuff
This commit is contained in:
parent
f83fa2be8b
commit
95bc7fafac
@ -1,159 +1,162 @@
|
|||||||
#ifndef CONSOLE_H_INCLUDED
|
#ifndef CONSOLE_H_INCLUDED
|
||||||
#define CONSOLE_H_INCLUDED
|
#define CONSOLE_H_INCLUDED
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This code contains console/log to work with
|
This code contains console/log to work with
|
||||||
|
|
||||||
Use global variable Console like that:
|
Use global variable Console like that:
|
||||||
|
|
||||||
*Console<<"something"<<endl;
|
*Console<<"something"<<endl;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef TARGET_WIN32
|
#ifdef TARGET_WIN32
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#endif
|
#endif
|
||||||
#ifdef TARGET_LINUX
|
#ifdef TARGET_LINUX
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#endif
|
#endif
|
||||||
#ifdef TARGET_ANDROID
|
#ifdef TARGET_ANDROID
|
||||||
#include <asm/page.h>
|
#include <asm/page.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include "boost/thread.hpp"
|
#include "boost/thread.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "include/Utils/DataTypes/DataTypes.h"
|
||||||
#include "include/Render/RenderMisc.h"
|
|
||||||
|
#ifndef UTILS_ENGINE
|
||||||
|
#include "include/Render/RenderMisc.h"
|
||||||
namespace SE
|
#endif
|
||||||
{
|
|
||||||
|
namespace SE
|
||||||
extern const std::string CONST_CONSOLE_TEX_NAME;
|
{
|
||||||
|
|
||||||
|
extern const std::string CONST_CONSOLE_TEX_NAME;
|
||||||
|
|
||||||
class TSimpleConsole
|
|
||||||
{
|
|
||||||
protected:
|
class TSimpleConsole
|
||||||
std::string History;
|
{
|
||||||
|
protected:
|
||||||
std::string TextSavedInTriangleList;
|
std::string History;
|
||||||
|
|
||||||
std::shared_ptr<TTriangleList> HistoryTriangeList;
|
std::string TextSavedInTriangleList;
|
||||||
|
|
||||||
|
#ifndef UTILS_ENGINE
|
||||||
|
std::shared_ptr<TTriangleList> HistoryTriangeList;
|
||||||
public:
|
#endif
|
||||||
std::string ConsoleInput;
|
|
||||||
cardinal ConsoleCursor;
|
|
||||||
std::vector<std::string> InputHistory;
|
public:
|
||||||
cardinal InputHistoryCursor;
|
std::string ConsoleInput;
|
||||||
|
cardinal ConsoleCursor;
|
||||||
TSimpleConsole() : History(""), TextSavedInTriangleList(""), ConsoleCursor(0), InputHistoryCursor(0) { }
|
std::vector<std::string> InputHistory;
|
||||||
|
cardinal InputHistoryCursor;
|
||||||
virtual ~TSimpleConsole() { }
|
|
||||||
|
TSimpleConsole() : History(""), TextSavedInTriangleList(""), ConsoleCursor(0), InputHistoryCursor(0) { }
|
||||||
void Clear() { History = ""; }
|
|
||||||
|
virtual ~TSimpleConsole() { }
|
||||||
void CutHistory();
|
|
||||||
|
void Clear() { History = ""; }
|
||||||
virtual std::string GetHistory();
|
|
||||||
|
void CutHistory();
|
||||||
#ifndef UTILS_ENGINE
|
|
||||||
virtual void Draw();
|
virtual std::string GetHistory();
|
||||||
#endif
|
|
||||||
};
|
#ifndef UTILS_ENGINE
|
||||||
|
virtual void Draw();
|
||||||
|
#endif
|
||||||
#ifdef TARGET_WIN32
|
};
|
||||||
|
|
||||||
class TFileConsole : public TSimpleConsole
|
|
||||||
{
|
#ifdef TARGET_WIN32
|
||||||
protected:
|
|
||||||
std::string filename;
|
class TFileConsole : public TSimpleConsole
|
||||||
std::ofstream f;
|
{
|
||||||
public:
|
protected:
|
||||||
TFileConsole();
|
std::string filename;
|
||||||
|
std::ofstream f;
|
||||||
TFileConsole(const std::string& Afilename);
|
public:
|
||||||
|
TFileConsole();
|
||||||
~TFileConsole();
|
|
||||||
|
TFileConsole(const std::string& Afilename);
|
||||||
TFileConsole& operator<<(const std::string& s);
|
|
||||||
|
~TFileConsole();
|
||||||
void PrintImmediate(const std::string& s);
|
|
||||||
};
|
TFileConsole& operator<<(const std::string& s);
|
||||||
|
|
||||||
#endif
|
void PrintImmediate(const std::string& s);
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef TARGET_LINUX
|
#endif
|
||||||
|
|
||||||
class TFileConsole : public TSimpleConsole
|
|
||||||
{
|
#ifdef TARGET_LINUX
|
||||||
protected:
|
|
||||||
std::string filename;
|
class TFileConsole : public TSimpleConsole
|
||||||
std::ofstream f;
|
{
|
||||||
public:
|
protected:
|
||||||
TFileConsole();
|
std::string filename;
|
||||||
|
std::ofstream f;
|
||||||
TFileConsole(const std::string& Afilename);
|
public:
|
||||||
|
TFileConsole();
|
||||||
~TFileConsole();
|
|
||||||
|
TFileConsole(const std::string& Afilename);
|
||||||
TFileConsole& operator<<(const std::string& s);
|
|
||||||
|
~TFileConsole();
|
||||||
void PrintImmediate(const std::string& s);
|
|
||||||
};
|
TFileConsole& operator<<(const std::string& s);
|
||||||
|
|
||||||
#endif
|
void PrintImmediate(const std::string& s);
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef TARGET_ANDROID
|
#endif
|
||||||
|
|
||||||
class TJavaConsole : public TSimpleConsole
|
|
||||||
{
|
#ifdef TARGET_ANDROID
|
||||||
protected:
|
|
||||||
boost::mutex ConsoleMutex;
|
class TJavaConsole : public TSimpleConsole
|
||||||
std::string AppDir;
|
{
|
||||||
std::string LogFilename;
|
protected:
|
||||||
public:
|
boost::mutex ConsoleMutex;
|
||||||
|
std::string AppDir;
|
||||||
TJavaConsole();
|
std::string LogFilename;
|
||||||
|
public:
|
||||||
TJavaConsole& operator<<(const std::string& s);
|
|
||||||
|
TJavaConsole();
|
||||||
void PrintImmediate(const std::string& s);
|
|
||||||
};
|
TJavaConsole& operator<<(const std::string& s);
|
||||||
|
|
||||||
#endif
|
void PrintImmediate(const std::string& s);
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef TARGET_IOS
|
#endif
|
||||||
|
|
||||||
class TIosConsole : public TSimpleConsole
|
|
||||||
{
|
#ifdef TARGET_IOS
|
||||||
protected:
|
|
||||||
public:
|
class TIosConsole : public TSimpleConsole
|
||||||
TIosConsole();
|
{
|
||||||
|
protected:
|
||||||
//TFileConsole(const std::string& Afilename);
|
public:
|
||||||
|
TIosConsole();
|
||||||
~TIosConsole();
|
|
||||||
|
//TFileConsole(const std::string& Afilename);
|
||||||
TIosConsole& operator<<(const std::string& s);
|
|
||||||
|
~TIosConsole();
|
||||||
void PrintImmediate(const std::string& s);
|
|
||||||
};
|
TIosConsole& operator<<(const std::string& s);
|
||||||
|
|
||||||
|
void PrintImmediate(const std::string& s);
|
||||||
#endif
|
};
|
||||||
|
|
||||||
} //namespace SE
|
|
||||||
|
#endif
|
||||||
#endif
|
|
||||||
|
} //namespace SE
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -1,323 +1,325 @@
|
|||||||
#ifndef FILE_UTILS_H_INCLUDED
|
#ifndef FILE_UTILS_H_INCLUDED
|
||||||
#define FILE_UTILS_H_INCLUDED
|
#define FILE_UTILS_H_INCLUDED
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This code contains API to ease file access
|
This code contains API to ease file access
|
||||||
|
|
||||||
WINDOWS AND ANDROID
|
WINDOWS AND ANDROID
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "include/Utils/DataTypes/DataTypes.h"
|
#include "include/Utils/DataTypes/DataTypes.h"
|
||||||
#include "include/Utils/Console/Console.h"
|
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
||||||
#include "boost/shared_array.hpp"
|
#include "include/Utils/Console/Console.h"
|
||||||
|
#include "boost/shared_array.hpp"
|
||||||
#ifdef TARGET_WIN32
|
|
||||||
#include "include/Utils/WinApi/WinApi.h"
|
#ifdef TARGET_WIN32
|
||||||
#endif
|
#include "include/Utils/WinApi/WinApi.h"
|
||||||
|
#endif
|
||||||
#ifdef TARGET_ANDROID
|
|
||||||
#include "include/Utils/JniApi/JniApi.h"
|
#ifdef TARGET_ANDROID
|
||||||
#endif
|
#include "include/Utils/JniApi/JniApi.h"
|
||||||
|
#endif
|
||||||
#ifdef TARGET_IOS
|
|
||||||
#include "include/Utils/IosApi/IosApi.h"
|
#ifdef TARGET_IOS
|
||||||
#endif
|
#include "include/Utils/IosApi/IosApi.h"
|
||||||
|
#endif
|
||||||
namespace SE
|
|
||||||
{
|
namespace SE
|
||||||
|
{
|
||||||
namespace ST
|
|
||||||
{
|
namespace ST
|
||||||
|
{
|
||||||
extern std::string PathToResources;
|
|
||||||
|
extern std::string PathToResources;
|
||||||
}
|
|
||||||
|
}
|
||||||
bool findString(char* in, char* list);
|
|
||||||
//utility for opengl extensions parsing. Not safe
|
bool findString(char* in, char* list);
|
||||||
|
//utility for opengl extensions parsing. Not safe
|
||||||
|
|
||||||
bool IsFileExistsInUserData(const std::string& filename);
|
|
||||||
|
bool IsFileExistsInUserData(const std::string& filename);
|
||||||
std::string GetFilePathUserData(const std::string& filename);
|
|
||||||
|
std::string GetFilePathUserData(const std::string& filename);
|
||||||
|
|
||||||
|
|
||||||
//utitily to process texture uploading
|
|
||||||
inline char* GetFileName(const char* filename)
|
//utitily to process texture uploading
|
||||||
{
|
inline char* GetFileName(const char* filename)
|
||||||
char* fname = (char*)filename + strlen(filename);
|
{
|
||||||
|
char* fname = (char*)filename + strlen(filename);
|
||||||
while ((*fname != '\\')&&(*fname != '/')&&(fname >= filename ))
|
|
||||||
--fname;
|
while ((*fname != '\\')&&(*fname != '/')&&(fname >= filename ))
|
||||||
|
--fname;
|
||||||
++fname;
|
|
||||||
|
++fname;
|
||||||
return fname;
|
|
||||||
}
|
return fname;
|
||||||
|
}
|
||||||
inline std::string GetFileName(const std::string& filename)
|
|
||||||
{
|
inline std::string GetFileName(const std::string& filename)
|
||||||
std::string::const_iterator i = filename.end() - 1;
|
{
|
||||||
|
std::string::const_iterator i = filename.end() - 1;
|
||||||
while ((i > filename.begin() )&&(*i != '\\')&&(*i != '/'))
|
|
||||||
--i;
|
while ((i > filename.begin() )&&(*i != '\\')&&(*i != '/'))
|
||||||
|
--i;
|
||||||
if (*i == '\\' || *i == '/')
|
|
||||||
{
|
if (*i == '\\' || *i == '/')
|
||||||
i++;
|
{
|
||||||
}
|
i++;
|
||||||
|
}
|
||||||
return std::string(i, filename.cend());
|
|
||||||
}
|
return std::string(i, filename.cend());
|
||||||
|
}
|
||||||
//utitily to process texture uploading
|
|
||||||
inline char* GetFileExt(const char* filename)
|
//utitily to process texture uploading
|
||||||
{
|
inline char* GetFileExt(const char* filename)
|
||||||
char* fext = (char*)filename + strlen(filename);
|
{
|
||||||
|
char* fext = (char*)filename + strlen(filename);
|
||||||
while (*fext != '.')
|
|
||||||
--fext;
|
while (*fext != '.')
|
||||||
|
--fext;
|
||||||
return fext;
|
|
||||||
}
|
return fext;
|
||||||
|
}
|
||||||
inline std::string GetFileExt(const std::string& filename)
|
|
||||||
{
|
inline std::string GetFileExt(const std::string& filename)
|
||||||
std::string::const_iterator i = filename.end() - 1;
|
{
|
||||||
|
std::string::const_iterator i = filename.end() - 1;
|
||||||
while (*i != '.')
|
|
||||||
--i;
|
while (*i != '.')
|
||||||
|
--i;
|
||||||
return std::string(i, filename.cend());
|
|
||||||
|
return std::string(i, filename.cend());
|
||||||
}
|
|
||||||
|
}
|
||||||
inline std::string GetFileNameWithoutExt(const std::string& filename)
|
|
||||||
{
|
inline std::string GetFileNameWithoutExt(const std::string& filename)
|
||||||
std::string result = GetFileName(filename);
|
{
|
||||||
|
std::string result = GetFileName(filename);
|
||||||
std::string::const_iterator i = result.end() - 1;
|
|
||||||
|
std::string::const_iterator i = result.end() - 1;
|
||||||
while (*i != '.')
|
|
||||||
--i;
|
while (*i != '.')
|
||||||
|
--i;
|
||||||
return std::string(result.cbegin(), i);
|
|
||||||
}
|
return std::string(result.cbegin(), i);
|
||||||
|
}
|
||||||
std::string GetFilePath(const std::string& filename);
|
|
||||||
|
std::string GetFilePath(const std::string& filename);
|
||||||
|
|
||||||
|
|
||||||
#ifdef TARGET_WIN32
|
|
||||||
|
#ifdef TARGET_WIN32
|
||||||
void GetFileList(const std::string& searchkey, std::vector<std::string> &list);
|
|
||||||
|
void GetFileList(const std::string& searchkey, std::vector<std::string> &list);
|
||||||
std::string AutocompleteExtension(const std::string& fileName);
|
|
||||||
|
std::string AutocompleteExtension(const std::string& fileName);
|
||||||
template<typename TYPENAME>
|
|
||||||
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
template<typename TYPENAME>
|
||||||
{
|
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
||||||
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
{
|
||||||
|
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
||||||
FILE * pFile;
|
|
||||||
|
FILE * pFile;
|
||||||
long fSize;
|
|
||||||
|
long fSize;
|
||||||
size_t result;
|
|
||||||
|
size_t result;
|
||||||
TYPENAME* fileData;
|
|
||||||
|
TYPENAME* fileData;
|
||||||
|
|
||||||
if (fopen_s(&pFile, fileName.c_str(), "rb" ) != 0)
|
|
||||||
{
|
if (fopen_s(&pFile, fileName.c_str(), "rb" ) != 0)
|
||||||
throw ErrorToLog("File not loaded: " + fileName);
|
{
|
||||||
}
|
throw ErrorToLog("File not loaded: " + fileName);
|
||||||
|
}
|
||||||
// obtain file size:
|
|
||||||
fseek (pFile , 0 , SEEK_END);
|
// obtain file size:
|
||||||
fSize = ftell (pFile);
|
fseek (pFile , 0 , SEEK_END);
|
||||||
rewind (pFile);
|
fSize = ftell (pFile);
|
||||||
|
rewind (pFile);
|
||||||
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
|
||||||
|
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
||||||
result = fread (&fileData[0], 1, fSize, pFile);
|
|
||||||
|
result = fread (&fileData[0], 1, fSize, pFile);
|
||||||
if (result != fSize)
|
|
||||||
{
|
if (result != fSize)
|
||||||
throw ErrorToLog("File not loaded: " + fileName);
|
{
|
||||||
}
|
throw ErrorToLog("File not loaded: " + fileName);
|
||||||
|
}
|
||||||
// terminate
|
|
||||||
fclose (pFile);
|
// terminate
|
||||||
|
fclose (pFile);
|
||||||
intCount = fSize;
|
|
||||||
|
intCount = fSize;
|
||||||
return boost::shared_array<TYPENAME>(fileData);
|
|
||||||
|
return boost::shared_array<TYPENAME>(fileData);
|
||||||
}
|
|
||||||
#endif
|
}
|
||||||
|
#endif
|
||||||
#ifdef TARGET_LINUX
|
|
||||||
|
#ifdef TARGET_LINUX
|
||||||
template<typename TYPENAME>
|
|
||||||
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
template<typename TYPENAME>
|
||||||
{
|
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
||||||
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
{
|
||||||
|
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
||||||
FILE * pFile;
|
|
||||||
|
FILE * pFile;
|
||||||
long fSize;
|
|
||||||
|
long fSize;
|
||||||
size_t result;
|
|
||||||
|
size_t result;
|
||||||
TYPENAME* fileData;
|
|
||||||
|
TYPENAME* fileData;
|
||||||
|
|
||||||
if (fopen(&pFile, fileName.c_str(), "rb" ) != 0)
|
pFile = fopen(fileName.c_str(), "rb" );
|
||||||
{
|
|
||||||
throw ErrorToLog("File not loaded: " + fileName);
|
if (!pFile)
|
||||||
}
|
{
|
||||||
|
throw ErrorToLog("File not loaded: " + fileName);
|
||||||
// obtain file size:
|
}
|
||||||
fseek (pFile , 0 , SEEK_END);
|
|
||||||
fSize = ftell (pFile);
|
// obtain file size:
|
||||||
rewind (pFile);
|
fseek (pFile , 0 , SEEK_END);
|
||||||
|
fSize = ftell (pFile);
|
||||||
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
rewind (pFile);
|
||||||
|
|
||||||
result = fread (&fileData[0], 1, fSize, pFile);
|
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
||||||
|
|
||||||
if (result != fSize)
|
result = fread (&fileData[0], 1, fSize, pFile);
|
||||||
{
|
|
||||||
throw ErrorToLog("File not loaded: " + fileName);
|
if (result != fSize)
|
||||||
}
|
{
|
||||||
|
throw ErrorToLog("File not loaded: " + fileName);
|
||||||
// terminate
|
}
|
||||||
fclose (pFile);
|
|
||||||
|
// terminate
|
||||||
intCount = fSize;
|
fclose (pFile);
|
||||||
|
|
||||||
return boost::shared_array<TYPENAME>(fileData);
|
intCount = fSize;
|
||||||
|
|
||||||
}
|
return boost::shared_array<TYPENAME>(fileData);
|
||||||
#endif
|
|
||||||
|
}
|
||||||
#ifdef TARGET_ANDROID
|
#endif
|
||||||
|
|
||||||
template<typename TYPENAME>
|
#ifdef TARGET_ANDROID
|
||||||
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
|
||||||
{
|
template<typename TYPENAME>
|
||||||
if (std::string(fileName.begin(), fileName.begin() + 5) == "/data")
|
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
||||||
{
|
{
|
||||||
*Console<<"File is in userdata - "+fileName;
|
if (std::string(fileName.begin(), fileName.begin() + 5) == "/data")
|
||||||
|
{
|
||||||
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
*Console<<"File is in userdata - "+fileName;
|
||||||
|
|
||||||
FILE * pFile;
|
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
||||||
|
|
||||||
long fSize;
|
FILE * pFile;
|
||||||
|
|
||||||
size_t result;
|
long fSize;
|
||||||
|
|
||||||
TYPENAME* fileData;
|
size_t result;
|
||||||
|
|
||||||
std::string realFileName = fileName;
|
TYPENAME* fileData;
|
||||||
|
|
||||||
pFile = fopen ( realFileName.c_str(), "rb" );
|
std::string realFileName = fileName;
|
||||||
if (pFile == NULL)
|
|
||||||
{
|
pFile = fopen ( realFileName.c_str(), "rb" );
|
||||||
throw ErrorToLog("File not loaded: " + fileName);
|
if (pFile == NULL)
|
||||||
}
|
{
|
||||||
|
throw ErrorToLog("File not loaded: " + fileName);
|
||||||
// obtain file size:
|
}
|
||||||
fseek (pFile , 0 , SEEK_END);
|
|
||||||
fSize = ftell (pFile);
|
// obtain file size:
|
||||||
rewind (pFile);
|
fseek (pFile , 0 , SEEK_END);
|
||||||
|
fSize = ftell (pFile);
|
||||||
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
rewind (pFile);
|
||||||
|
|
||||||
result = fread (&fileData[0], 1, fSize, pFile);
|
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
||||||
|
|
||||||
if (result != fSize)
|
result = fread (&fileData[0], 1, fSize, pFile);
|
||||||
{
|
|
||||||
throw ErrorToLog("File not loaded: " + fileName);
|
if (result != fSize)
|
||||||
}
|
{
|
||||||
|
throw ErrorToLog("File not loaded: " + fileName);
|
||||||
// terminate
|
}
|
||||||
fclose (pFile);
|
|
||||||
|
// terminate
|
||||||
intCount = fSize;
|
fclose (pFile);
|
||||||
|
|
||||||
return boost::shared_array<TYPENAME>(fileData);
|
intCount = fSize;
|
||||||
}
|
|
||||||
|
return boost::shared_array<TYPENAME>(fileData);
|
||||||
*Console<<"File is in resources - "+fileName;
|
}
|
||||||
|
|
||||||
return JniCreateMemFromFile<TYPENAME>(fileName, intCount);
|
*Console<<"File is in resources - "+fileName;
|
||||||
}
|
|
||||||
|
return JniCreateMemFromFile<TYPENAME>(fileName, intCount);
|
||||||
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TARGET_IOS
|
#endif
|
||||||
|
|
||||||
template<typename TYPENAME>
|
#ifdef TARGET_IOS
|
||||||
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
|
||||||
{
|
template<typename TYPENAME>
|
||||||
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
boost::shared_array<TYPENAME> CreateMemFromFile(const std::string& fileName, cardinal& intCount)
|
||||||
|
{
|
||||||
FILE * pFile;
|
cardinal SIZEOF_TYPENAME = sizeof(TYPENAME);
|
||||||
|
|
||||||
long fSize;
|
FILE * pFile;
|
||||||
|
|
||||||
size_t result;
|
long fSize;
|
||||||
|
|
||||||
TYPENAME* fileData;
|
size_t result;
|
||||||
|
|
||||||
std::string realFileName = IosGetFileReadPath(fileName);
|
TYPENAME* fileData;
|
||||||
|
|
||||||
pFile = fopen ( realFileName.c_str(), "rb" );
|
std::string realFileName = IosGetFileReadPath(fileName);
|
||||||
if (pFile == NULL)
|
|
||||||
{
|
pFile = fopen ( realFileName.c_str(), "rb" );
|
||||||
throw ErrorToLog("File not loaded: " + fileName);
|
if (pFile == NULL)
|
||||||
}
|
{
|
||||||
|
throw ErrorToLog("File not loaded: " + fileName);
|
||||||
// obtain file size:
|
}
|
||||||
fseek (pFile , 0 , SEEK_END);
|
|
||||||
fSize = ftell (pFile);
|
// obtain file size:
|
||||||
rewind (pFile);
|
fseek (pFile , 0 , SEEK_END);
|
||||||
|
fSize = ftell (pFile);
|
||||||
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
rewind (pFile);
|
||||||
|
|
||||||
result = fread (&fileData[0], 1, fSize, pFile);
|
fileData = new TYPENAME [fSize % SIZEOF_TYPENAME == 0 ? fSize/SIZEOF_TYPENAME : fSize/SIZEOF_TYPENAME + 1];
|
||||||
|
|
||||||
if (result != fSize)
|
result = fread (&fileData[0], 1, fSize, pFile);
|
||||||
{
|
|
||||||
throw ErrorToLog("File not loaded: " + fileName);
|
if (result != fSize)
|
||||||
}
|
{
|
||||||
|
throw ErrorToLog("File not loaded: " + fileName);
|
||||||
// terminate
|
}
|
||||||
fclose (pFile);
|
|
||||||
|
// terminate
|
||||||
intCount = fSize;
|
fclose (pFile);
|
||||||
|
|
||||||
return boost::shared_array<TYPENAME>(fileData);
|
intCount = fSize;
|
||||||
|
|
||||||
}
|
return boost::shared_array<TYPENAME>(fileData);
|
||||||
|
|
||||||
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TARGET_IOS
|
#endif
|
||||||
|
|
||||||
//Special for IOS, because Foundation.h conflicts with sq_plus.h
|
#ifdef TARGET_IOS
|
||||||
|
|
||||||
// Obviously, this returns ST::PathToResources
|
//Special for IOS, because Foundation.h conflicts with sq_plus.h
|
||||||
|
|
||||||
std::string GetPathToResources();
|
// Obviously, this returns ST::PathToResources
|
||||||
#endif
|
|
||||||
|
std::string GetPathToResources();
|
||||||
} //namespace SE
|
#endif
|
||||||
|
|
||||||
|
} //namespace SE
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,62 +1,63 @@
|
|||||||
#ifndef SERIALIZE_INTERFACE_H_INCLUDED
|
#ifndef SERIALIZE_INTERFACE_H_INCLUDED
|
||||||
#define SERIALIZE_INTERFACE_H_INCLUDED
|
#define SERIALIZE_INTERFACE_H_INCLUDED
|
||||||
|
|
||||||
#include "include/Utils/DataTypes/DataTypes.h"
|
#include "include/Utils/DataTypes/DataTypes.h"
|
||||||
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
||||||
#include "boost/property_tree/ptree.hpp"
|
#include "boost/property_tree/ptree.hpp"
|
||||||
#include "boost/property_tree/xml_parser.hpp"
|
#include "boost/property_tree/xml_parser.hpp"
|
||||||
#include "boost/shared_array.hpp"
|
#include "boost/shared_array.hpp"
|
||||||
|
|
||||||
#include "boost/foreach.hpp"
|
#include "boost/foreach.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
namespace SE
|
|
||||||
{
|
namespace SE
|
||||||
|
{
|
||||||
std::shared_ptr<boost::property_tree::ptree> StringToPropertyTree(std::string xmlCode, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
|
||||||
|
std::shared_ptr<boost::property_tree::ptree> StringToPropertyTree(std::string xmlCode, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
||||||
std::shared_ptr<boost::property_tree::ptree> FileToPropertyTree(boost::shared_array<char> xmlFileArr, cardinal xmlFileSize, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
|
||||||
|
std::shared_ptr<boost::property_tree::ptree> FileToPropertyTree(boost::shared_array<char> xmlFileArr, cardinal xmlFileSize, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
||||||
std::shared_ptr<boost::property_tree::ptree> FileToPropertyTree(const std::string& fileName, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
|
||||||
|
std::shared_ptr<boost::property_tree::ptree> FileToPropertyTree(const std::string& fileName, std::map<std::string, std::string> replaceMap = std::map<std::string, std::string>());
|
||||||
|
|
||||||
class TSerializeInterface
|
|
||||||
{
|
class TSerializeInterface
|
||||||
public:
|
{
|
||||||
virtual void Serialize(boost::property_tree::ptree& propertyTree)
|
public:
|
||||||
{
|
virtual void Serialize(boost::property_tree::ptree& propertyTree)
|
||||||
}
|
{
|
||||||
|
}
|
||||||
};
|
|
||||||
|
};
|
||||||
|
|
||||||
template <typename TKEY, typename TVALUE>
|
|
||||||
class TMapParser : public TSerializeInterface
|
template <typename TKEY, typename TVALUE>
|
||||||
{
|
class TMapParser : public TSerializeInterface
|
||||||
public:
|
{
|
||||||
std::map<TKEY, TVALUE> Map;
|
public:
|
||||||
|
std::map<TKEY, TVALUE> Map;
|
||||||
virtual void Serialize(boost::property_tree::ptree& propertyTree)
|
|
||||||
{
|
virtual void Serialize(boost::property_tree::ptree& propertyTree)
|
||||||
|
{
|
||||||
BOOST_FOREACH(boost::property_tree::ptree::value_type& subTree, propertyTree)
|
|
||||||
{
|
BOOST_FOREACH(boost::property_tree::ptree::value_type& subTree, propertyTree)
|
||||||
TKEY key = subTree.second.get<TKEY>("<xmlattr>.key");
|
{
|
||||||
TVALUE value = subTree.second.get<TVALUE>("<xmlattr>.value");
|
TKEY key = subTree.second.get<TKEY>("<xmlattr>.key");
|
||||||
|
TVALUE value = subTree.second.get<TVALUE>("<xmlattr>.value");
|
||||||
Map[key] = value;
|
|
||||||
}
|
Map[key] = value;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
};
|
||||||
template <typename TKEY, typename TVALUE>
|
|
||||||
std::map<TKEY, TVALUE> SerializeToMap(boost::property_tree::ptree& propertyTree)
|
template <typename TKEY, typename TVALUE>
|
||||||
{
|
std::map<TKEY, TVALUE> SerializeToMap(boost::property_tree::ptree& propertyTree)
|
||||||
TMapParser<TKEY, TVALUE> mapParser;
|
{
|
||||||
mapParser.Serialize(propertyTree);
|
TMapParser<TKEY, TVALUE> mapParser;
|
||||||
return mapParser.Map;
|
mapParser.Serialize(propertyTree);
|
||||||
}
|
return mapParser.Map;
|
||||||
|
}
|
||||||
} //namespace SE
|
|
||||||
|
} //namespace SE
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,45 +1,45 @@
|
|||||||
#ifndef UTILS_H_INCLUDED
|
#ifndef UTILS_H_INCLUDED
|
||||||
#define UTILS_H_INCLUDED
|
#define UTILS_H_INCLUDED
|
||||||
/*
|
/*
|
||||||
This code combines additional routines (such as console/log, exceptions, math utils, file utils) for engine to use
|
This code combines additional routines (such as console/log, exceptions, math utils, file utils) for engine to use
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include "boost/shared_array.hpp"
|
#include "boost/shared_array.hpp"
|
||||||
#include "boost/property_tree/ptree.hpp"
|
#include "boost/property_tree/ptree.hpp"
|
||||||
#include "boost/foreach.hpp"
|
#include "boost/foreach.hpp"
|
||||||
|
|
||||||
#include "boost/asio.hpp"
|
#include "boost/asio.hpp"
|
||||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||||
#include "boost/signal.hpp"
|
#include "boost/signal.hpp"
|
||||||
|
|
||||||
|
|
||||||
#include "include/Utils/Console/Console.h"
|
#include "include/Utils/Console/Console.h"
|
||||||
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
#include "include/Utils/ErrorTypes/ErrorTypes.h"
|
||||||
#include "../GlobalConst.h"
|
#include "../GlobalConst.h"
|
||||||
#include "include/Utils/FileUtils/FileUtils.h"
|
#include "include/Utils/FileUtils/FileUtils.h"
|
||||||
#include "include/Utils/SerializeInterface/SerializeInterface.h"
|
#include "include/Utils/SerializeInterface/SerializeInterface.h"
|
||||||
|
|
||||||
#include "include/Utils/BindableVar.h"
|
#include "include/Utils/BindableVar.h"
|
||||||
#include "include/Utils/SimpleTimer.h"
|
#include "include/Utils/SimpleTimer.h"
|
||||||
#include "include/Utils/ThreadUtils.h"
|
#include "include/Utils/ThreadUtils.h"
|
||||||
#include "include/Utils/Network/Network.h"
|
#include "include/Utils/Network/Network.h"
|
||||||
#include "include/Utils/Network/Server.h"
|
#include "include/Utils/Network/Server.h"
|
||||||
|
|
||||||
#ifdef TARGET_WIN32
|
#ifdef TARGET_WIN32
|
||||||
#include "WinApi/WinApi.h"
|
#include "WinApi/WinApi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TARGET_ANDROID
|
#ifdef TARGET_ANDROID
|
||||||
#include "JniApi/JniApi.h"
|
#include "JniApi/JniApi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TARGET_IOS
|
#ifdef TARGET_IOS
|
||||||
#include "IosApi/IosApi.h"
|
#include "IosApi/IosApi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user