summaryrefslogtreecommitdiff
path: root/source/libs/asura-lib-utils/filesystem
diff options
context:
space:
mode:
Diffstat (limited to 'source/libs/asura-lib-utils/filesystem')
-rw-r--r--source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp68
-rw-r--r--source/libs/asura-lib-utils/filesystem/data_buffer.cpp29
-rw-r--r--source/libs/asura-lib-utils/filesystem/data_buffer.h45
-rw-r--r--source/libs/asura-lib-utils/filesystem/decoded_data.cpp20
-rw-r--r--source/libs/asura-lib-utils/filesystem/decoded_data.h42
-rw-r--r--source/libs/asura-lib-utils/filesystem/reloadable.h27
-rw-r--r--source/libs/asura-lib-utils/filesystem/resource_manager.cpp0
-rw-r--r--source/libs/asura-lib-utils/filesystem/resource_manager.h44
8 files changed, 275 insertions, 0 deletions
diff --git a/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp b/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp
new file mode 100644
index 0000000..a9113a7
--- /dev/null
+++ b/source/libs/asura-lib-utils/filesystem/binding/data_buffer.binding.cpp
@@ -0,0 +1,68 @@
+#include "../data_buffer.h"
+
+using namespace Luax;
+
+namespace AsuraEngine
+{
+ namespace Filesystem
+ {
+
+ LUAX_REGISTRY(DataBuffer)
+ {
+ luaL_Reg f[] = {
+ { "New", _New },
+ { "SetContent", _SetContent },
+ { "GetContent", _GetContent },
+ { "GetContentLength", _GetContentLength },
+ {0, 0}
+ };
+
+ state.RegisterMethods(f);
+ }
+
+ LUAX_POSTPROCESS(DataBuffer)
+ {
+
+ }
+
+ LUAX_IMPL_METHOD(DataBuffer, _New)
+ {
+
+ }
+
+ // SetContent(dataBuffer, lString)
+ LUAX_IMPL_METHOD(DataBuffer, _SetContent)
+ {
+ LUAX_SETUP(L, "US");
+ // params:
+ // 1: data buffer
+ // 2: lstring
+
+ DataBuffer* self = state.GetLuaUserdata<DataBuffer>(1);
+ size_t size = 0;
+ const char* str = lua_tolstring(L, 2, &size);
+ void* data = new char[size];
+ memcpy(data, str, size);
+ self->SetContent(data, size);
+ return 0;
+ }
+
+ LUAX_IMPL_METHOD(DataBuffer, _GetContent)
+ {
+ LUAX_SETUP(L, "U");
+
+ DataBuffer* self = state.GetLuaUserdata<DataBuffer>(1);
+ lua_pushlstring(L, (const char*)self->data, self->size);
+ return 1;
+ }
+
+ LUAX_IMPL_METHOD(DataBuffer, _GetContentLength)
+ {
+ LUAX_SETUP(L, "U");
+ DataBuffer* self = state.GetLuaUserdata<DataBuffer>(1);
+ lua_pushinteger(L, self->size);
+ return 1;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/filesystem/data_buffer.cpp b/source/libs/asura-lib-utils/filesystem/data_buffer.cpp
new file mode 100644
index 0000000..629dc92
--- /dev/null
+++ b/source/libs/asura-lib-utils/filesystem/data_buffer.cpp
@@ -0,0 +1,29 @@
+#include "data_buffer.h"
+
+namespace AsuraEngine
+{
+ namespace Filesystem
+ {
+
+ DataBuffer::DataBuffer(const void* data, std::size_t size)
+ {
+ this->data = (const byte*)data;
+ this->size = size;
+ }
+
+ DataBuffer::~DataBuffer()
+ {
+ delete[] data;
+ }
+
+ void DataBuffer::SetContent(const void* data, std::size_t siez)
+ {
+ if (this->data != nullptr)
+ delete[] this->data;
+
+ this->data = (const byte*)data;
+ this->size = size;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/filesystem/data_buffer.h b/source/libs/asura-lib-utils/filesystem/data_buffer.h
new file mode 100644
index 0000000..4b013ed
--- /dev/null
+++ b/source/libs/asura-lib-utils/filesystem/data_buffer.h
@@ -0,0 +1,45 @@
+#ifndef __ASURA_ENGINE_DATABUFFER_H__
+#define __ASURA_ENGINE_DATABUFFER_H__
+
+#include <cstdlib>
+
+#include "../scripting/Luax.hpp"
+#include "../scripting/portable.hpp"
+
+namespace AsuraEngine
+{
+ namespace Filesystem
+ {
+
+ ///
+ /// ڴݵķװеʹData bufferװֱʹconst void*ͨresource managerȡ
+ ///
+ class DataBuffer ASURA_FINAL
+ : public Scripting::Portable<DataBuffer>
+ {
+ public:
+
+ DataBuffer(const void* data, std::size_t size);
+
+ ~DataBuffer();
+
+ void SetContent(const void* data, std::size_t siez);
+
+ const byte* data;
+ size_t size;
+
+ //----------------------------------------------------------------------------------------------------------
+
+ LUAX_DECL_FACTORY(DataBuffer);
+
+ LUAX_DECL_METHOD(_New);
+ LUAX_DECL_METHOD(_SetContent);
+ LUAX_DECL_METHOD(_GetContent);
+ LUAX_DECL_METHOD(_GetContentLength);
+
+ };
+
+ }
+}
+
+#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/filesystem/decoded_data.cpp
new file mode 100644
index 0000000..125c652
--- /dev/null
+++ b/source/libs/asura-lib-utils/filesystem/decoded_data.cpp
@@ -0,0 +1,20 @@
+#include "DecodedData.h"
+#include "Exceptions/Exception.h"
+
+namespace AsuraEngine
+{
+ namespace Filesystem
+ {
+
+ DecodedData::DecodedData(const DataBuffer* databuffer)
+ {
+ Decode(databuffer);
+ }
+
+ DecodedData::~DecodedData()
+ {
+
+ }
+
+ }
+}
diff --git a/source/libs/asura-lib-utils/filesystem/decoded_data.h b/source/libs/asura-lib-utils/filesystem/decoded_data.h
new file mode 100644
index 0000000..49b5815
--- /dev/null
+++ b/source/libs/asura-lib-utils/filesystem/decoded_data.h
@@ -0,0 +1,42 @@
+#ifndef __ASURA_ENGINE_DATA_H__
+#define __ASURA_ENGINE_DATA_H__
+
+#include <cstdlib>
+
+#include "../scripting/portable.hpp"
+
+#include "data_buffer.h"
+
+namespace AsuraEngine
+{
+ namespace Filesystem
+ {
+
+ ///
+ /// һ̹߳data̳дࡣͼƬݡƵݵȣһ߳нԭļڲݸʽ
+ /// ȡ
+ ///
+ ASURA_ABSTRACT class DecodedData
+ {
+ public:
+
+ ///
+ /// ڴйdataԷһ߳棬Դϵͳء
+ ///
+ DecodedData(const DataBuffer& databuffer);
+
+ virtual ~DecodedData();
+
+ protected:
+
+ ///
+ /// ڴеݡ
+ ///
+ virtual void Decode(const DataBuffer& buffer) = 0;
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/source/libs/asura-lib-utils/filesystem/reloadable.h b/source/libs/asura-lib-utils/filesystem/reloadable.h
new file mode 100644
index 0000000..7c4ea52
--- /dev/null
+++ b/source/libs/asura-lib-utils/filesystem/reloadable.h
@@ -0,0 +1,27 @@
+#ifndef __ASURA_ENGINE_RELOADABLE_H__
+#define __ASURA_ENGINE_RELOADABLE_H__
+
+#include "../scripting/portable.hpp"
+
+namespace AsuraEngine
+{
+ namespace Filesystem
+ {
+
+ ///
+ /// ¹ݽṹͼƬƵ֣ⲿݿֱӹڱ༭¹ڲıhandleԴ
+ ///
+ ASURA_ABSTRACT class Reloadable
+ {
+ public:
+ Reloadable();
+ virtual ~Reloadable();
+
+ // ̳ReloadableҪṩһload
+
+ };
+
+ }
+}
+
+#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/filesystem/resource_manager.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/libs/asura-lib-utils/filesystem/resource_manager.cpp
diff --git a/source/libs/asura-lib-utils/filesystem/resource_manager.h b/source/libs/asura-lib-utils/filesystem/resource_manager.h
new file mode 100644
index 0000000..c5d8f06
--- /dev/null
+++ b/source/libs/asura-lib-utils/filesystem/resource_manager.h
@@ -0,0 +1,44 @@
+#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);
+
+ };
+
+ }
+}
+
+#endif \ No newline at end of file