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