diff options
Diffstat (limited to 'source/libs/asura-lib-utils')
27 files changed, 1582 insertions, 74 deletions
diff --git a/source/libs/asura-lib-utils/filesystem/resource_manager.h b/source/libs/asura-lib-utils/filesystem/resource_manager.h deleted file mode 100644 index 36d46cf..0000000 --- a/source/libs/asura-lib-utils/filesystem/resource_manager.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef __ASURA_ENGINE_RESOURCE_MANAGER_H__ -#define __ASURA_ENGINE_RESOURCE_MANAGER_H__ - -#include <string> - -#include "../scripting/portable.hpp" -#include "data_buffer.h" - -namespace AsuraEngine -{ - namespace Filesystem - { - - /// - /// Դء洢ԴָĿ¼ȡ - /// - class ResourceManager ASURA_FINAL - { - public: - - ResourceManager(); - ~ResourceManager(); - - /// - /// װظĿ¼ - /// - void Mount(const std::string& root); - - /// - /// ȡļһdata bufferעҪȷȷڴ棬ڵôʹunique_ptr - /// - DataBuffer* LoadFile(const std::string& path); - - /// - /// data buffer - /// - void SaveFile(const std::string& path, const DataBuffer* buffer); - - //---------------------------------------------------------------------------------------------------------- - - LUAX_DECL_SINGLETON(ResourceManager); - - }; - - } -} - -#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/filesystem/resource_manager.cpp b/source/libs/asura-lib-utils/io/binding/_compressor.cpp index e69de29..e69de29 100644 --- a/source/libs/asura-lib-utils/filesystem/resource_manager.cpp +++ b/source/libs/asura-lib-utils/io/binding/_compressor.cpp diff --git a/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp index 8e92eee..d9eca36 100644 --- a/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp +++ b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp @@ -4,17 +4,17 @@ using namespace Luax; namespace AsuraEngine { - namespace Filesystem + namespace IO { LUAX_REGISTRY(DataBuffer) { LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "GetBuffer", _GetBuffer }, - { "GetSize", _GetSize }, - { "Load", _Load }, - { "Clear", _Clear } + { "New", _New }, + { "GetBuffer", _GetData }, + { "GetSize", _GetSize }, + { "Load", _Load }, + { "Clear", _Clear } ); } @@ -50,12 +50,12 @@ namespace AsuraEngine } // lsting, len = databuffer:GetBuffer() - LUAX_IMPL_METHOD(DataBuffer, _GetBuffer) + LUAX_IMPL_METHOD(DataBuffer, _GetData) { LUAX_SETUP(L, "U"); DataBuffer* self = state.GetUserdata<DataBuffer>(1); - lua_pushlstring(L, self->GetBuffer(), self->GetSize()); + lua_pushlstring(L, self->GetData(), self->GetSize()); return 2; } diff --git a/source/libs/asura-lib-utils/io/binding/_file.cpp b/source/libs/asura-lib-utils/io/binding/_file.cpp new file mode 100644 index 0000000..4120258 --- /dev/null +++ b/source/libs/asura-lib-utils/io/binding/_file.cpp @@ -0,0 +1,186 @@ +#include "../file.h" + +namespace AsuraEngine +{ + namespace IO + { + + LUAX_REGISTRY(File) + { + } + + LUAX_POSTPROCESS(File) + { + LUAX_REGISTER_ENUM(state, "EFileMode", + { "CLOSED", FILE_MODE_CLOSED }, + { "READ", FILE_MODE_READ }, + { "WRITE", FILE_MODE_WRITE }, + { "APPEND", FILE_MODE_APPEND } + ); + + LUAX_REGISTER_ENUM(state, "EBufferMode", + { "NONE", BUFFER_MODE_NONE}, + { "LINE", BUFFER_MODE_LINE}, + { "FULL", BUFFER_MODE_FULL} + ); + } + + // file = File.New(name) + LUAX_IMPL_METHOD(File, _New) + { + LUAX_STATE(L); + + cc8* name = state.CheckParam<cc8*>(1); + File* file = new File(name); + file->PushLuaxUserdata(state); + return 1; + } + + // successsed = file:Open(mode) + LUAX_IMPL_METHOD(File, _Open) + { + LUAX_PREPARE(L, File); + + File::FileMode mode = (File::FileMode)state.CheckParam<int>(2); + state.Push(self->Open(mode)); + return 1; + } + + // successed = file:Close() + LUAX_IMPL_METHOD(File, _Close) + { + LUAX_PREPARE(L, File); + + state.Push(self->Close()); + return 1; + } + + // opened = file:IsOpen() + LUAX_IMPL_METHOD(File, _IsOpen) + { + LUAX_PREPARE(L, File); + + state.Push(self->IsOpen()); + return 1; + } + + // mode = file:GetMode() + LUAX_IMPL_METHOD(File, _GetMode) + { + LUAX_PREPARE(L, File); + + File::FileMode mode = self->GetMode(); + state.Push((int)mode); + return 1; + } + + // size = file:GetSize() + LUAX_IMPL_METHOD(File, _GetSize) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetSize()); + return 1; + } + + // size = file:Read(dst, len) + // returns: + // size ʵʶĴС + // params: + // self ļ + // dst Ŀ껺 + // len ĴС + LUAX_IMPL_METHOD(File, _Read) + { + LUAX_PREPARE(L, File); + + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + if (!db) return state.ErrorType(2, "DataBuffer"); + int len = state.CheckParam<int>(3); + int size = self->Read(db, len); + state.Push(size); + return 1; + } + + // isEOF = file:IsEOF() + LUAX_IMPL_METHOD(File, _IsEOF) + { + LUAX_PREPARE(L, File); + + state.Push(self->IsEOF()); + return 1; + } + + // isWrite = file:Write(data buffer) + LUAX_IMPL_METHOD(File, _Write) + { + LUAX_PREPARE(L, File); + + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + if (!db) return state.ErrorType(2, "DataBuffer"); + state.Push(self->Write(db)); + return 1; + } + + // isFlushed = file:Flush() + LUAX_IMPL_METHOD(File, _Flush) + { + LUAX_PREPARE(L, File); + + state.Push(self->Flush()); + return 1; + } + + // pos = file:Tell() + LUAX_IMPL_METHOD(File, _Tell) + { + LUAX_PREPARE(L, File); + + state.Push(self->Tell()); + return 1; + } + + // isSeek = file:Seek(pos) + LUAX_IMPL_METHOD(File, _Seek) + { + LUAX_PREPARE(L, File); + + int pos = state.CheckParam<int>(2); + state.Push(self->Seek(pos)); + return 1; + } + + // isSetted = file:SetBuffer(mode, size) + LUAX_IMPL_METHOD(File, _SetBuffer) + { + LUAX_PREPARE(L, File); + + BufferMode mode = (BufferMode)state.CheckParam<int>(2); + int size = state.CheckParam<int>(3); + state.Push(self->SetBuffer(mode, size)); + return 1; + } + + // size, mode = file:GetBuffer() + LUAX_IMPL_METHOD(File, _GetBuffer) + { + LUAX_PREPARE(L, File); + + size_t size = 0; + BufferMode mode = self->GetBuffer(ASURA_OUT size); + state.Push((int)size); + state.Push((int)mode); + return 2; + } + + // name = file:GetFileName() + LUAX_IMPL_METHOD(File, _GetFileName) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetFileName()); + return 1; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/binding/_file_data.cpp b/source/libs/asura-lib-utils/io/binding/_file_data.cpp new file mode 100644 index 0000000..56f65f7 --- /dev/null +++ b/source/libs/asura-lib-utils/io/binding/_file_data.cpp @@ -0,0 +1,64 @@ +#include "../file_data.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace IO + { + +#define PREPARE(L) \ + LUAX_STATE(L); \ + FileData* self = state.GetUserdata<FileData>(1); + + LUAX_REGISTRY(FileData) + { + LUAX_REGISTER_METHODS(state, + { "GetFileName", _GetFileName }, + { "GetExtension", _GetExtension }, + { "GetName", _GetName }, + { "GetDataBuffer", _GetDataBuffer } + ); + } + + LUAX_POSTPROCESS(FileData) + { + } + + // filename = filedata:GetFileName() + LUAX_IMPL_METHOD(FileData, _GetFileName) + { + PREPARE(L); + string filename = self->GetFileName(); + state.Push(filename); + return 1; + } + + // extension = filedata:GetExtension() + LUAX_IMPL_METHOD(FileData, _GetExtension) + { + PREPARE(L); + string extension = self->GetExtension(); + state.Push(extension); + return 1; + } + + // name = filedata:GetName() + LUAX_IMPL_METHOD(FileData, _GetName) + { + PREPARE(L); + string extension = self->GetName(); + state.Push(extension); + return 1; + } + + // databuffer = filedata:GetDataBuffer() + LUAX_IMPL_METHOD(FileData, _GetDataBuffer) + { + PREPARE(L); + self->PushLuaxMemberRef(state, self->mDataRef); + return 1; + } + + } +} diff --git a/source/libs/asura-lib-utils/io/binding/_file_system.cpp b/source/libs/asura-lib-utils/io/binding/_file_system.cpp new file mode 100644 index 0000000..8cb60bc --- /dev/null +++ b/source/libs/asura-lib-utils/io/binding/_file_system.cpp @@ -0,0 +1,267 @@ +#include "../file_system.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace IO + { + +#define PREPARE(l) \ + LUAX_STATE(l); \ + Filesystem* fs = Filesystem::Get(); + + LUAX_REGISTRY(Filesystem) + { + LUAX_REGISTER_METHODS(state, + { "Init", _Init }, + { "Mount", _Mount }, + { "Unmount", _Unmount }, + { "GetMountPoint", _GetMountPoint }, + { "SetWriteDirectory", _SetWriteDirectory }, + { "GetWriteDirectory", _GetWriteDirectory }, + { "CreateFile", _CreateFile }, + { "CreateDirectory", _CreateDirectory }, + { "Write", _Write }, + { "Append", _Append }, + { "Remove", _Remove }, + { "Read", _Read }, + { "GetFileInfo", _GetFileInfo }, + { "GetDirectoryItems", _GetDirectoryItems } + ); + } + + LUAX_POSTPROCESS(Filesystem) + { + LUAX_REGISTER_ENUM(state, "EFileType", + { "FILE", FILE_TYPE_FILE }, + { "DIRECTORY", FILE_TYPE_DIRECTORY }, + { "SYMLINK", FILE_TYPE_SYMLINK }, + { "OTHER", FILE_TYPE_OTHER } + ); + } + + // Filesystem.Init(arg0) + LUAX_IMPL_METHOD(Filesystem, _Init) + { + PREPARE(L); + + const char* arg0 = state.CheckParam<const char*>(1); + fs->Init(arg0); + return 0; + } + + // successed = Filesystem.Mount(path, mountpoint, prepend) + // successed = Filesystem.Mount(data buffer, archievename, mountpoint, prepend) + LUAX_IMPL_METHOD(Filesystem, _Mount) + { + PREPARE(L); + bool mounted = false; + + if (state.IsType(1, LUA_TSTRING)) + { + cc8* path = state.GetValue<cc8*>(1, ""); + cc8* moutpoint = state.GetValue<cc8*>(2, "/"); + bool prepend = state.GetValue<bool>(3, false); + mounted = fs->Mount(path, moutpoint, prepend); + } + else if (state.IsType(1, LUA_TUSERDATA)) + { + DataBuffer* db = state.CheckUserdata<DataBuffer>(1); + if (!db) + return state.ErrorType(1, "Data Buffer"); + cc8* arcname = state.GetValue<cc8*>(2, ""); + cc8* mountpoint = state.GetValue<cc8*>(3, "/"); + bool prepend = state.GetValue<bool>(4, false); + mounted = fs->Mount(db, arcname, mountpoint, prepend); + // retain + fs->LuaxRetain<DataBuffer>(state, db); + } + state.Push(mounted); + return 1; + } + + // successed = Filesystem.Unmount(path) + // successed = Filesystem.Unmount(data buffer) + LUAX_IMPL_METHOD(Filesystem, _Unmount) + { + PREPARE(L); + bool unmounted = false; + + if (state.IsType(1, LUA_TSTRING)) + { + cc8* path = state.GetValue<cc8*>(1, ""); + unmounted = fs->Unmount(path); + } + else if (state.IsType(1, LUA_TUSERDATA)) + { + DataBuffer* db = state.CheckUserdata<DataBuffer>(1); + if (!db) + return state.ErrorType(1, "Data Buffer"); + unmounted = fs->Unmount(db); + if (unmounted) + fs->LuaxRelease<DataBuffer>(state, db); + } + state.Push(unmounted); + return 1; + } + + // moutpoint = Filesystem.GetMountPoint(path) + LUAX_IMPL_METHOD(Filesystem, _GetMountPoint) + { + PREPARE(L); + + cc8* path = state.CheckParam<cc8*>(1); + std::string mp; + if (fs->GetMountPoint(path, ASURA_OUT mp)) + state.Push(mp); + else + state.PushNil(); + + return 1; + } + + // Filesystem.SetWriteDirectory(dir) + LUAX_IMPL_METHOD(Filesystem, _SetWriteDirectory) + { + PREPARE(L); + + cc8* dir = state.CheckParam<cc8*>(1); + fs->SetWriteDirectory(dir); + return 0; + } + + // dir = Filesystem.GetWriteDirectory() + LUAX_IMPL_METHOD(Filesystem, _GetWriteDirectory) + { + PREPARE(L); + + std::string dir = fs->GetWriteDirectory(); + state.Push(dir); + return 1; + } + + // file = Filesystem.CreateFile(name) + LUAX_IMPL_METHOD(Filesystem, _CreateFile) + { + PREPARE(L); + + cc8* name = state.CheckParam<cc8*>(1); + File* file = fs->NewFile(name); + if (file) + file->PushLuaxUserdata(state); + else + state.PushNil(); + return 1; + } + + // successed = Filesystem.CreateDirectory(name) + LUAX_IMPL_METHOD(Filesystem, _CreateDirectory) + { + PREPARE(L); + + cc8* path = state.CheckParam<cc8*>(1); + state.Push(fs->NewDirectory(path)); + return 1; + } + + // successed = Filesystem.Write(path, data buffer) + LUAX_IMPL_METHOD(Filesystem, _Write) + { + PREPARE(L); + + cc8* path = state.CheckParam<cc8*>(1); + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + state.Push(fs->Write(path, db)); + return 1; + } + + // successed = Filesystem.Append(path, data buffer) + LUAX_IMPL_METHOD(Filesystem, _Write) + { + PREPARE(L); + + cc8* path = state.CheckParam<cc8*>(1); + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + state.Push(fs->Append(path, db)); + return 1; + } + + // successed = Filesystem.Remove(path) + LUAX_IMPL_METHOD(Filesystem, _Remove) + { + PREPARE(L); + + cc8* path = state.CheckParam<cc8*>(1); + state.Push(fs->Remove(path)); + return 1; + } + + // filedata = Filesystem.Read(path) + LUAX_IMPL_METHOD(Filesystem, _Read) + { + PREPARE(L); + + cc8* path = state.CheckParam<cc8*>(1); + FileData* fd = fs->Read(path); + if (fd) + { + fd->mData->PushLuaxUserdata(state); + fd->SetLuaxMemberRef(state, fd->mDataRef, -1); // fd->mDataRef = data buffer + state.Pop(1); // data buffer + fd->PushLuaxUserdata(state); + } + else + { + state.PushNil(); + } + return 1; + } + + // fileinfo = Filesystem.GetFileInfo(path) + // fileinfoĸʽ: + // {size = , modtime = , type =} + LUAX_IMPL_METHOD(Filesystem, _GetFileInfo) + { + PREPARE(L); + + cc8* path = state.CheckParam<cc8*>(1); + FileInfo info; + if (fs->GetFileInfo(path, &info)) + { + lua_newtable(L); // info table + state.SetField(-1, "size", info.size); + state.SetField(-1, "modetime", info.modtime); + state.SetField(-1, "type", info.type); + } + else + { + state.PushNil(); + } + return 1; + } + + // items = Filesystem.GetDirectoryItems(path) + LUAX_IMPL_METHOD(Filesystem, _GetDirectoryItems) + { + PREPARE(L); + + cc8* path = state.CheckParam<cc8*>(1); + std::vector<std::string> items; + if(fs->GetDirectoryItems(path, ASURA_OUT items)) + { + lua_newtable(L); // item list + for (int i = 0; i < items.size(); ++i) + { + state.SetFieldByIndex(-1, i + 1, items[i]); + } + } + else + { + state.PushNil(); + } + return 1; + } + + } +} diff --git a/source/libs/asura-lib-utils/io/compressor.cpp b/source/libs/asura-lib-utils/io/compressor.cpp new file mode 100644 index 0000000..095eff4 --- /dev/null +++ b/source/libs/asura-lib-utils/io/compressor.cpp @@ -0,0 +1,11 @@ +#include "compressor.h" + +namespace AsuraEngine +{ + namespace IO + { + + + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/compressor.h b/source/libs/asura-lib-utils/io/compressor.h new file mode 100644 index 0000000..30a074c --- /dev/null +++ b/source/libs/asura-lib-utils/io/compressor.h @@ -0,0 +1,30 @@ +#ifndef __ASURA_COMPRESSOR_H__ +#define __ASURA_COMPRESSOR_H__ + +#include "../scripting/portable.hpp" + +namespace AsuraEngine +{ + namespace IO + { + + class Compressor ASURA_FINAL + : public AEScripting::Portable<Compressor> + { + public: + + LUAX_DECL_SINGLETON(Compressor); + + private: + + LUAX_DECL_METHOD(_Compress); + LUAX_DECL_METHOD(_Decompress); + + + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/filesystem/data_buffer.cpp b/source/libs/asura-lib-utils/io/data_buffer.cpp index 32a123f..98675e9 100644 --- a/source/libs/asura-lib-utils/filesystem/data_buffer.cpp +++ b/source/libs/asura-lib-utils/io/data_buffer.cpp @@ -4,7 +4,7 @@ namespace AsuraEngine { - namespace Filesystem + namespace IO { DataBuffer::DataBuffer(DataBuffer& src) @@ -34,7 +34,7 @@ namespace AsuraEngine void DataBuffer::Load(DataBuffer& db) { - Load(db.GetBuffer(), db.GetSize()); + Load(db.GetData(), db.GetSize()); } void DataBuffer::Load(const void* data, std::size_t size) @@ -47,7 +47,17 @@ namespace AsuraEngine memcpy(mBytes, data, size); } - byte* DataBuffer::GetBuffer() + void DataBuffer::Move(void* bytes, std::size_t size) + { + if (!mBytes) + { + delete[] mBytes; + } + mBytes = (byte*)bytes; + mSize = size; + } + + byte* DataBuffer::GetData() { return mBytes; } diff --git a/source/libs/asura-lib-utils/filesystem/data_buffer.h b/source/libs/asura-lib-utils/io/data_buffer.h index 5c80efb..c7383fa 100644 --- a/source/libs/asura-lib-utils/filesystem/data_buffer.h +++ b/source/libs/asura-lib-utils/io/data_buffer.h @@ -7,42 +7,39 @@ namespace AsuraEngine { - namespace Filesystem + namespace IO { /// /// ڴݵķװеʹData bufferװֱʹconst void*ͨresource managerȡ /// class DataBuffer ASURA_FINAL - : public Scripting::Portable<DataBuffer> + : public AEScripting::Portable<DataBuffer> { public: + LUAX_DECL_FACTORY(DataBuffer); + DataBuffer(DataBuffer& src); DataBuffer(std::size_t size); DataBuffer(const void* bytes, std::size_t size); ~DataBuffer(); - byte* GetBuffer(); + byte* GetData(); size_t GetSize(); void Load(DataBuffer& db); void Load(const void* bytes, std::size_t size); + void Move(void* bytes, std::size_t size); void Clear(); private: byte* mBytes; size_t mSize; - - //------------------------------------------------------------------------------------------------------------ - - public: - - LUAX_DECL_FACTORY(DataBuffer); LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_GetBuffer); + LUAX_DECL_METHOD(_GetData); LUAX_DECL_METHOD(_GetSize); LUAX_DECL_METHOD(_Load); LUAX_DECL_METHOD(_Clear); @@ -52,4 +49,6 @@ namespace AsuraEngine } } +namespace AEIO = AsuraEngine::IO; + #endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/filesystem/decoded_data.cpp b/source/libs/asura-lib-utils/io/decoded_data.cpp index 125c652..b208455 100644 --- a/source/libs/asura-lib-utils/filesystem/decoded_data.cpp +++ b/source/libs/asura-lib-utils/io/decoded_data.cpp @@ -3,7 +3,7 @@ namespace AsuraEngine { - namespace Filesystem + namespace IO { DecodedData::DecodedData(const DataBuffer* databuffer) diff --git a/source/libs/asura-lib-utils/filesystem/decoded_data.h b/source/libs/asura-lib-utils/io/decoded_data.h index 49b5815..e201e91 100644 --- a/source/libs/asura-lib-utils/filesystem/decoded_data.h +++ b/source/libs/asura-lib-utils/io/decoded_data.h @@ -9,7 +9,7 @@ namespace AsuraEngine { - namespace Filesystem + namespace IO { /// diff --git a/source/libs/asura-lib-utils/io/file.cpp b/source/libs/asura-lib-utils/io/file.cpp new file mode 100644 index 0000000..092a90d --- /dev/null +++ b/source/libs/asura-lib-utils/io/file.cpp @@ -0,0 +1,286 @@ +#include <physfs/physfs.h> + +#include <asura-lib-utils/exceptions/exception.h> + +#include "file.h" + +namespace AsuraEngine +{ + namespace IO + { + + File::File(const std::string& filename) + : mFileName(filename) + , mFileHandle(nullptr) + , mMode(FILE_MODE_CLOSED) + , mBufferMode(BUFFER_MODE_NONE) + , mBufferSize(0) + { + size_t dot = filename.rfind('.'); + if (dot != std::string::npos) + { + mExtension = filename.substr(dot + 1); + mName = filename.substr(0, dot); + } + else + mName = filename; + } + + File::~File() + { + if (mMode != FILE_MODE_CLOSED) + Close(); + } + + bool File::Open(FileMode mode) + { + if (!PHYSFS_isInit()) + throw Exception("Physfs is NOT initialized."); + + if (mode == FILE_MODE_CLOSED) + return; + + if (mode == FILE_MODE_READ && !PHYSFS_exists(mFileName.c_str())) + throw Exception("Could NOT open file %s. Does not exist.", mFileName.c_str()); + + if (mode == FILE_MODE_APPEND || mode == FILE_MODE_WRITE) + { + if (!PHYSFS_getWriteDir()) + { + throw Exception("Could NOT set write directory."); + } + } + + // Ѿ֮ǰͲٴµhandle + if (mFileHandle != nullptr) + return; + + PHYSFS_getLastErrorCode(); + + PHYSFS_File* handle = nullptr; + + switch (mode) + { + case FILE_MODE_READ: + handle = PHYSFS_openRead(mFileName.c_str()); + break; + case FILE_MODE_APPEND: + handle = PHYSFS_openAppend(mFileName.c_str()); + break; + case FILE_MODE_WRITE: + handle = PHYSFS_openWrite(mFileName.c_str()); + break; + } + + if (handle == nullptr) + { + const char *err = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()); + if (err == nullptr) + err = "unknown error"; + throw Exception("Could not open file %s (%s)", mFileName.c_str(), err); + } + + mFileHandle = handle; + mMode = mode; + + if (mFileHandle != nullptr && !SetBuffer(mBufferMode,mBufferSize)) + { + mBufferMode = BUFFER_MODE_NONE; + mBufferSize = 0; + } + + return mFileHandle != nullptr; + } + + bool File::Close() + { + if (mFileHandle == nullptr || !PHYSFS_close(mFileHandle)) + return false; + mMode = FILE_MODE_CLOSED; + mFileHandle = nullptr; + return true; + } + + bool File::IsOpen() + { + return mMode != FILE_MODE_CLOSED && mFileHandle != nullptr; + } + + size_t File::GetSize() + { + if (mFileHandle == nullptr) + { + Open(FILE_MODE_READ); + size_t size = PHYSFS_fileLength(mFileHandle); + Close(); + return size; + } + return PHYSFS_fileLength(mFileHandle); + } + + size_t File::Read(ASURA_OUT DataBuffer* dst, size_t length) + { + ASSERT(dst); + + if (dst->GetSize() < length) + throw Exception("Data buffer is too small compares to read length."); + + if (!mFileHandle || mMode != FILE_MODE_READ) + throw Exception("File \"%s\" is not opened for reading", mFileName); + + size_t max = PHYSFS_fileLength(mFileHandle); + length = (length > max) ? max : length; + + if (length < 0) + throw Exception("Invalid read size."); + + return PHYSFS_readBytes(mFileHandle, dst->GetData(), length); + } + + size_t File::ReadAll(ASURA_OUT DataBuffer* dst) + { + ASSERT(dst); + + if (!mFileHandle || mMode != FILE_MODE_READ) + throw Exception("File \"%s\" is not opened for reading", mFileName); + + size_t length = PHYSFS_fileLength(mFileHandle); + + if (dst->GetSize() < length) + throw Exception("Data buffer is too small compares to file length."); + + return PHYSFS_readBytes(mFileHandle, dst->GetData(), length); + } + +#ifdef ASURA_WINDOWS + inline bool test_eof(File *that, PHYSFS_File *) + { + int64 pos = that->Tell(); + int64 size = that->GetSize(); + return pos == -1 || size == -1 || pos >= size; + } +#else + inline bool test_eof(File *, PHYSFS_File *file) + { + return PHYSFS_eof(file); + } +#endif + + bool File::IsEOF() + { + return mFileHandle == nullptr || test_eof(this, mFileHandle); + } + + size_t File::Tell() + { + if (!mFileHandle) + return - 1; + + return PHYSFS_tell(mFileHandle); + } + + bool File::Seek(size_t pos) + { + return mFileHandle != nullptr && PHYSFS_seek(mFileHandle, pos) != 0; + } + + bool File::Write(ASURA_REF DataBuffer* src) + { + if (!mFileHandle || (mMode != FILE_MODE_APPEND && mMode != FILE_MODE_WRITE)) + throw Exception("File is not opened for writing."); + + byte* data = src->GetData(); + int size = src->GetSize(); + + if (size < 0) + throw Exception("Invalid write size."); + + size_t written = PHYSFS_writeBytes(mFileHandle, data, size); + + if (written != src->GetSize()) + return false; + + // л + if (mBufferSize == BUFFER_MODE_LINE && mBufferSize > size) + { + if (memchr(data, '\n', size) != nullptr) + Flush(); + } + + return true; + } + + bool File::Flush() + { + if (!mFileHandle || (mMode != FILE_MODE_WRITE && mMode != FILE_MODE_APPEND)) + throw Exception("File is not opened for writing."); + + return PHYSFS_flush(mFileHandle) != 0; + } + + bool File::SetBuffer(BufferMode mode, size_t size) + { + if (size < 0) + return false; + + // If the file isn't open, we'll make sure the buffer values are set in + // File::open. + if (!IsOpen()) + { + mBufferMode = mode; + mBufferSize = size; + return true; + } + + int ret = 1; + + switch (mode) + { + case BUFFER_MODE_NONE: + default: + ret = PHYSFS_setBuffer(mFileHandle, 0); + size = 0; + break; + case BUFFER_MODE_LINE: + case BUFFER_MODE_FULL: + ret = PHYSFS_setBuffer(mFileHandle, size); + break; + } + + if (ret == 0) + return false; + + mBufferMode = mode; + mBufferSize = size; + + return true; + } + + File::BufferMode File::GetBuffer(ASURA_OUT size_t& size) + { + size = mBufferSize; + return mBufferMode; + } + + const std::string& File::GetFileName() + { + return mFileName; + } + + const std::string& File::GetName() + { + return mName; + } + + const std::string& File::GetExtension() + { + return mExtension; + } + + File::FileMode File::GetMode() + { + return mMode; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file.h b/source/libs/asura-lib-utils/io/file.h new file mode 100644 index 0000000..e8f676e --- /dev/null +++ b/source/libs/asura-lib-utils/io/file.h @@ -0,0 +1,132 @@ +#ifndef __ASURA_ENGINE_FILE_H__ +#define __ASURA_ENGINE_FILE_H__ + +#include "physfs/physfs.h" + +#include "../scripting/portable.hpp" + +#include "file_data.h" + +namespace AsuraEngine +{ + namespace IO + { + + /// + /// ʽļָд㡢Сʹȡʱʹñ࣬ʹFilesystem.read()ֱӶȡļȫ + /// ݣһFileData + /// + class File ASURA_FINAL + : public AEScripting::Portable<File> + { + public: + + LUAX_DECL_FACTORY(File); + + /// + /// ļдģʽ + /// + enum FileMode + { + FILE_MODE_CLOSED, + FILE_MODE_READ, + FILE_MODE_WRITE, + FILE_MODE_APPEND, + }; + + /// + /// ļдʱΪ + /// + enum BufferMode + { + BUFFER_MODE_NONE, ///< ʹû壬дļ + BUFFER_MODE_LINE, ///< л壬зߴﵽСʱдļ + BUFFER_MODE_FULL, ///< ȫ壬ʱдļ + }; + + File(const std::string& filename); + ~File(); + + bool Open(FileMode mode); + bool Close(); + bool IsOpen(); + FileMode GetMode(); + size_t GetSize(); + + /// + /// ȡdata bufferض + /// + size_t Read(ASURA_OUT DataBuffer* dst, size_t length); + size_t ReadAll(ASURA_OUT DataBuffer* dst); + + /// + /// Ƿļβ + /// + bool IsEOF(); + + /// + /// data bufferед룬Ƿɹ + /// + bool Write(ASURA_REF DataBuffer* src); + + /// + /// ˻壬ǿջдļ + /// + bool Flush(); + + /// + /// صǰдλ + /// + size_t Tell(); + + /// + /// Ӧλ + /// + bool Seek(size_t pos); + + /// + /// ûСģʽ + /// + bool SetBuffer(BufferMode mode, size_t size); + + /// + /// ȡСģʽ + /// + BufferMode GetBuffer(ASURA_OUT size_t& size); + + const std::string& GetFileName(); + const std::string& GetName(); + const std::string& GetExtension(); + + private: + + PHYSFS_File* mFileHandle; ///< physfs ļ + std::string mFileName; ///< ļ + std::string mExtension; ///< չ + std::string mName; ///< չļ + FileMode mMode; ///< ļģʽ + BufferMode mBufferMode; ///< д뻺ģʽ + size_t mBufferSize; ///< д뻺С + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Open); + LUAX_DECL_METHOD(_Close); + LUAX_DECL_METHOD(_IsOpen); + LUAX_DECL_METHOD(_GetMode); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_Read); + LUAX_DECL_METHOD(_IsEOF); + LUAX_DECL_METHOD(_Write); + LUAX_DECL_METHOD(_Flush); + LUAX_DECL_METHOD(_Tell); + LUAX_DECL_METHOD(_Seek); + LUAX_DECL_METHOD(_SetBuffer); + LUAX_DECL_METHOD(_GetBuffer); + LUAX_DECL_METHOD(_GetFileName); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file_data.cpp b/source/libs/asura-lib-utils/io/file_data.cpp new file mode 100644 index 0000000..47d9095 --- /dev/null +++ b/source/libs/asura-lib-utils/io/file_data.cpp @@ -0,0 +1,57 @@ +#include "file_data.h" + +namespace AsuraEngine +{ + namespace IO + { + + FileData::FileData(const std::string& filename) + : mData(nullptr) + , mFileName(filename) + { + size_t dot = filename.rfind('.'); + if (dot != std::string::npos) + { + mExtension = filename.substr(dot + 1); + mName = filename.substr(0, dot); + } + else + mName = filename; + } + + FileData::~FileData() + { + } + + void FileData::BindData(DataBuffer* buffer) + { + mData = buffer; + } + + const std::string& FileData::GetFileName() + { + return mFileName; + } + + const std::string& FileData::GetExtension() + { + return mExtension; + } + + const std::string& FileData::GetName() + { + return mName; + } + + void FileData::BindData(ASURA_MOVE DataBuffer* buffer) + { + mData = buffer; + } + + DataBuffer* FileData::GetDataBuffer() + { + return mData; + } + + } +} diff --git a/source/libs/asura-lib-utils/io/file_data.h b/source/libs/asura-lib-utils/io/file_data.h new file mode 100644 index 0000000..e20f41b --- /dev/null +++ b/source/libs/asura-lib-utils/io/file_data.h @@ -0,0 +1,68 @@ +#ifndef __ASURA_ENGINE_FILE_DATA_H__ +#define __ASURA_ENGINE_FILE_DATA_H__ + +#include <string> + +#include <asura-lib-utils/scripting/portable.hpp> + +#include "data_buffer.h" + +namespace AsuraEngine +{ + namespace IO + { + + class Filesystem; + + /// + /// filesystemֱӶȡļʱFileDataļݺϢFilesystem + /// + class FileData ASURA_FINAL + : public AEScripting::Portable<FileData> + { + public: + + LUAX_DECL_FACTORY(FileData); + + /// + /// ļݣͨDatabufferݺʹСڲӿڶData bufferΪҲdata buffer + /// + DataBuffer* GetDataBuffer(); + + const std::string& GetFileName(); + const std::string& GetExtension(); + const std::string& GetName(); + + private: + + friend class Filesystem; + + FileData(const std::string& name); + ~FileData(); + + /// + /// data buffer + /// + void BindData(ASURA_MOVE DataBuffer* buffer); + + /// + /// Data bufferfiledataʱ٣luaüΪ0ʱluaGC١mDataʱһԱá + /// + ASURA_REF DataBuffer* mData; + Luax::LuaxMemberRef mDataRef; + + std::string mFileName; ///< չļ + std::string mExtension; ///< չ + std::string mName; ///< ͺļ + + LUAX_DECL_METHOD(_GetFileName); + LUAX_DECL_METHOD(_GetExtension); + LUAX_DECL_METHOD(_GetName); + LUAX_DECL_METHOD(_GetDataBuffer); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file_system.cpp b/source/libs/asura-lib-utils/io/file_system.cpp new file mode 100644 index 0000000..20f3cb2 --- /dev/null +++ b/source/libs/asura-lib-utils/io/file_system.cpp @@ -0,0 +1,198 @@ +#include <physfs/physfs.h> + +#include "../exceptions/exception.h" + +#include "file.h" +#include "file_data.h" +#include "file_system.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace IO + { + +#ifdef ASURA_WINDOWS + #include <windows.h> + #include <direct.h> +#else + #include <sys/param.h> + #include <unistd.h> +#endif + + Filesystem::~Filesystem() + { + if (mInited) //PHYSFS_isInit + PHYSFS_deinit(); + } + + void Filesystem::Init(const char* arg0) + { + if (!PHYSFS_init(arg0)) + throw Exception("Failed to initialize filesystem: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + + mInited = true; + } + + bool Filesystem::Mount(const std::string& locpath, const std::string& montpoint/* = "/"*/, bool prepend /*= false*/) + { + if (!mInited) + return false; + + return PHYSFS_mount(locpath.c_str(), montpoint.c_str(), !prepend); + } + + bool Filesystem::Mount(DataBuffer* db, const std::string& archivename, const std::string& mountpoint /*= "/"*/, bool prepend /*= false*/) + { + if (!mInited) + return false; + if (PHYSFS_mountMemory(db->GetData(), db->GetSize(), nullptr, archivename.c_str(), mountpoint.c_str(), !prepend)) + { + mMountData[archivename] = db; + return true; + } + return false; + } + + bool Filesystem::Unmount(const std::string& locpath) + { + if (!mInited) + return false; + + // ǹ鵵ӳɾ + auto datait = mMountData.find(locpath); + if (datait != mMountData.end() && PHYSFS_unmount(locpath.c_str()) != 0) + { + mMountData.erase(datait); + return true; + } + + return PHYSFS_unmount(locpath.c_str()); + } + + bool Filesystem::Unmount(DataBuffer* db) + { + for (const auto& dp : mMountData) + { + if (dp.second == db) + { + std::string archive = dp.first; + return Unmount(archive); + } + } + } + + bool Filesystem::GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint) + { + if (!mInited) + return false; + const char* point = PHYSFS_getMountPoint(locpath.c_str()); + if (point != nullptr) + { + mountpoint = point; + return true; + } + return false; + } + + void Filesystem::SetWriteDirectory(const std::string locpath) + { + if (!mInited) + return; + if (!PHYSFS_setWriteDir(locpath.c_str())) + throw Exception("Failed to set write directory %s", locpath.c_str()); + } + + std::string Filesystem::GetWriteDirectory() + { + return PHYSFS_getWriteDir(); + } + + File* Filesystem::NewFile(const std::string& name) + { + return new File(name); + } + + bool Filesystem::NewDirectory(const std::string& path) + { + if (!mInited) + return false; + if (!PHYSFS_getWriteDir()) + return false; + if (!PHYSFS_mkdir(path.c_str())) + return false; + return true; + } + + bool Filesystem::Write(const std::string& name, ASURA_REF DataBuffer* buffer) + { + File file(name); + file.Open(File::FILE_MODE_WRITE); + if (!file.Write(buffer)) + throw Exception("Data could not be written."); + } + + bool Filesystem::Append(const std::string& name, ASURA_REF DataBuffer* buffer) + { + File file(name); + file.Open(File::FILE_MODE_APPEND); + if (!file.Write(buffer)) + throw Exception("Data could not be append."); + } + + FileData* Filesystem::Read(const std::string& name) + { + File file = File(name); + file.Open(File::FILE_MODE_READ); + int size = file.GetSize(); + DataBuffer* db = new DataBuffer(size); + if (db) + { + file.ReadAll(db); + FileData* fd = new FileData(name); + fd->BindData(db); + return fd; + } + return nullptr; + } + + bool Filesystem::Remove(const std::string& path) + { + if (!mInited) + return false; + if (PHYSFS_getWriteDir() == 0) + return false; + + if (!PHYSFS_delete(path.c_str())) + return false; + + return true; + } + + bool Filesystem::GetFileInfo(const std::string& filepath, ASURA_OUT FileInfo* info) + { + if (!mInited) + return false; + + PHYSFS_Stat stat = {}; + if (!PHYSFS_stat(filepath.c_str(), &stat)) + return false; + + info->size = (int64)stat.filesize; + info->modtime = (int64)stat.modtime; + + if (stat.filetype == PHYSFS_FILETYPE_REGULAR) + info->type = FILE_TYPE_FILE; + else if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY) + info->type = FILE_TYPE_DIRECTORY; + else if (stat.filetype == PHYSFS_FILETYPE_SYMLINK) + info->type = FILE_TYPE_SYMLINK; + else + info->type = FILE_TYPE_OTHER; + + return true; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file_system.h b/source/libs/asura-lib-utils/io/file_system.h new file mode 100644 index 0000000..1af0292 --- /dev/null +++ b/source/libs/asura-lib-utils/io/file_system.h @@ -0,0 +1,110 @@ +#ifndef __ASURA_ENGINE_FILESYSTEM_H__ +#define __ASURA_ENGINE_FILESYSTEM_H__ + +#include <map> +#include <string> + +#include "../scripting/portable.hpp" +#include "../singleton.hpp" +#include "../type.h" + +#include "file_data.h" +#include "file.h" + +namespace AsuraEngine +{ + namespace IO + { + + enum FileType + { + FILE_TYPE_FILE, ///< ļ + FILE_TYPE_DIRECTORY, ///< ļ + FILE_TYPE_SYMLINK, ///< + FILE_TYPE_OTHER, ///< + }; + + struct FileInfo + { + int64 size; + int64 modtime; + FileType type; + }; + + /// + /// Դء洢ԴָĿ¼ȡ۱༭ʱҪƷʵĻƣûIJϷĿ¼ + /// £file systemµġFilesystemʱͱ༭õ࣬AssetDatabaseԴ࣬framework + /// ʵ֣дFilesystemʵ֣AssetDatabaseṩļݴӦԴķ + /// + class Filesystem ASURA_FINAL + : public Singleton<Filesystem> + , public AEScripting::Portable<Filesystem> + { + public: + + LUAX_DECL_SINGLETON(Filesystem); + + void Init(const char* arg0); + + /// + /// ǰִļļ + /// + std::string GetWorkingDirectory(); + + bool Mount(const std::string& locpath, const std::string& montpoint = "/", bool prepend = false); + bool Mount(DataBuffer* db, const std::string& archivename, const std::string& mountpoint = "/", bool prepend = false); + + bool Unmount(const std::string& locpath); + bool Unmount(DataBuffer* db); + + bool GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint); + + void SetWriteDirectory(const std::string locpath); + std::string GetWriteDirectory(); + File* NewFile(const std::string& name); + bool NewDirectory(const std::string& path); + bool Write(const std::string& path, ASURA_REF DataBuffer* buffer); + bool Append(const std::string& path, ASURA_REF DataBuffer* buffer); + bool Remove(const std::string& path); + + FileData* Read(const std::string& path); + bool GetFileInfo(const std::string& path, ASURA_OUT FileInfo* info); + + bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector<std::string>& items); + + private: + + typedef std::map<std::string, DataBuffer*> MountDataMap; + + bool mInited; ///< Ƿʼɹ + std::string mCwd; ///< ǰִļĹĿ¼ + MountDataMap mMountData; ///< ·ѹĵӳ + + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_Mount); + LUAX_DECL_METHOD(_Unmount); + LUAX_DECL_METHOD(_GetMountPoint); + + LUAX_DECL_METHOD(_SetWriteDirectory); + LUAX_DECL_METHOD(_GetWriteDirectory); + LUAX_DECL_METHOD(_CreateFile); + LUAX_DECL_METHOD(_CreateDirectory); + + LUAX_DECL_METHOD(_Write); + LUAX_DECL_METHOD(_Append); + LUAX_DECL_METHOD(_Remove); + + LUAX_DECL_METHOD(_Read); + + LUAX_DECL_METHOD(_GetFileInfo); + + LUAX_DECL_METHOD(_GetDirectoryItems); + + }; + + } +} + +namespace AEIO = AsuraEngine::IO; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/filesystem/reloadable.h b/source/libs/asura-lib-utils/io/reloadable.h index 7c4ea52..cf30296 100644 --- a/source/libs/asura-lib-utils/filesystem/reloadable.h +++ b/source/libs/asura-lib-utils/io/reloadable.h @@ -5,7 +5,7 @@ namespace AsuraEngine { - namespace Filesystem + namespace IO { /// diff --git a/source/libs/asura-lib-utils/manager.hpp b/source/libs/asura-lib-utils/manager.hpp new file mode 100644 index 0000000..7b4e272 --- /dev/null +++ b/source/libs/asura-lib-utils/manager.hpp @@ -0,0 +1,14 @@ +#ifndef __ASURA_ENGINE_MANAGER_H__ +#define __ASURA_ENGINE_MANAGER_H__ + +namespace AsuraEngine +{ + + class Manager + { + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/rect.hpp b/source/libs/asura-lib-utils/math/rect.hpp index f635007..1751634 100644 --- a/source/libs/asura-lib-utils/math/rect.hpp +++ b/source/libs/asura-lib-utils/math/rect.hpp @@ -13,8 +13,20 @@ namespace AsuraEngine Rect(); ~Rect(T x, T y, T w, T h); - template <typename U> - explicit Rect(const Rect<U>& rect); + /// + /// x,yǷrectڡ + /// + bool Contain(T x, T y); + + /// + /// Ƿཻཻľ + /// + bool Intersect(const Rect& src, Rect& intersection); + + /// + /// Ƿཻཻľ + /// + static bool Intersect(const Rect<T>& src1, const Rect<T>& src2, Rect<T>& intersection); T x, y, w, h; }; @@ -25,8 +37,11 @@ namespace AsuraEngine typedef Rect<int> Recti; typedef Rect<unsigned int> Rectu; typedef Rect<float> Rectf; + typedef Rect<long> Reftl; } } +namespace AEMath = AsuraEngine::Math; + #endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/scripting/portable.hpp b/source/libs/asura-lib-utils/scripting/portable.hpp index 00ede90..097a9fe 100644 --- a/source/libs/asura-lib-utils/scripting/portable.hpp +++ b/source/libs/asura-lib-utils/scripting/portable.hpp @@ -21,7 +21,14 @@ namespace AsuraEngine template<typename T> using Portable = Luax::LuaxNativeClass<T>; + /// + /// ҪΪ࣬userdatamember ref̳д࣬ע̳С + /// + using NativeAccessor = Luax::ILuaxNativeAccessor; + } } +namespace AEScripting = AsuraEngine::Scripting; + #endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/singleton.hpp b/source/libs/asura-lib-utils/singleton.hpp new file mode 100644 index 0000000..756209a --- /dev/null +++ b/source/libs/asura-lib-utils/singleton.hpp @@ -0,0 +1,59 @@ +#ifndef __ASURA_SINGLETON_H__ +#define __ASURA_SINGLETON_H__ + +#include "Config.h" + +namespace AsuraEngine +{ + + /// + /// ̳Singletonڵһʵʱʵ֮ٴʵᱨ + /// + template<class T> + class Singleton + { + public: + + static T* Get() + { + // ֮ǰûдһ + if (!instance) instance = new T; + // ʵ + return instance; + } + + static void Destroy() + { + delete instance; + instance = nullptr; + } + + protected: + + Singleton() + { + // instanceζִһʵǴġ + ASSERT(!instance); + // ʵΪʵ + instance = static_cast<T*>(this); + }; + + virtual ~Singleton() {}; + + static T* instance; + + private: + + Singleton(const Singleton& singleton); + + Singleton& operator = (const Singleton& singleton); + + }; + + // ʵʼΪ + template<class T> + T* Singleton<T>::instance = nullptr; + +} + +#endif // __ASURA_SINGLETON_H__
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/stringmap.cpp b/source/libs/asura-lib-utils/stringmap.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/stringmap.cpp diff --git a/source/libs/asura-lib-utils/stringmap.hpp b/source/libs/asura-lib-utils/stringmap.hpp new file mode 100644 index 0000000..ddba128 --- /dev/null +++ b/source/libs/asura-lib-utils/stringmap.hpp @@ -0,0 +1,29 @@ +#ifndef __ASURA_ENGINE_STRINGMAP_H__ +#define __ASURA_ENGINE_STRINGMAP_H__ + +#include <string> + +namespace AsuraEngine +{ + + /// + /// һ˫һһӦӳ䣬shader uniformsstatemathine state parameterID + /// + template<typename key_type> + class StringMap + { + public: + + bool ContainsKey(const key_type& key); + + bool ContainsString(const String& str); + + std::string GetStringByKey(const key_type& key); + + key_type GetKeyByString(const String& str); + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/type.h b/source/libs/asura-lib-utils/type.h index 72ed8cc..aa00108 100644 --- a/source/libs/asura-lib-utils/type.h +++ b/source/libs/asura-lib-utils/type.h @@ -25,6 +25,8 @@ namespace AsuraEngine typedef std::size_t size_t; + typedef const char cc8; + //---------------------------------------------------------------------------------------------------------------- #ifndef ASSERT @@ -51,6 +53,8 @@ namespace AsuraEngine #define ASURA_ATTRIBUTE_USED #define ASURA_ABSTRACT #define ASURA_API ASURA_LIBRARY_EXPORT + + #define ASURA_WINDOWS 1 #else #define ASURA_FINAL final #define ASURA_LIBRARY_EXPORT __attribute__((visibility("default"))) @@ -61,6 +65,16 @@ namespace AsuraEngine #define ASURA_ABSTRACT #define ASURA_API ASURA_LIBRARY_EXPORT #endif + + /// + /// ò + /// +#define ASURA_OUT +#define ASURA_REF + /// + /// ƶָȨ + /// +#define ASURA_MOVE //---------------------------------------------------------------------------------------------------------------- diff --git a/source/libs/asura-lib-utils/utils_config.h b/source/libs/asura-lib-utils/utils_config.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/utils_config.h |