From bad78945ceba425f6a80e3b8dca2414d592970eb Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 2 Aug 2019 20:51:00 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8D=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/modules/asura-utils/IO/FileData.h | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 source/modules/asura-utils/IO/FileData.h (limited to 'source/modules/asura-utils/IO/FileData.h') diff --git a/source/modules/asura-utils/IO/FileData.h b/source/modules/asura-utils/IO/FileData.h new file mode 100644 index 0000000..f93040c --- /dev/null +++ b/source/modules/asura-utils/IO/FileData.h @@ -0,0 +1,69 @@ +#ifndef _ASURA_ENGINE_FILE_DATA_H_ +#define _ASURA_ENGINE_FILE_DATA_H_ + +#include + +#include + +#include "DataBuffer.h" + +namespace AsuraEngine +{ + namespace IO + { + + class Filesystem; + + /// + /// 当从filesystem直接读取整个文件时,返回FileData对象描述文件内容和其他信息。由Filesystem创建。 + /// + class FileData ASURA_FINAL + : public AEScripting::Portable + { + public: + + LUAX_DECL_FACTORY(FileData); + + ~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); + + /// + /// 绑定data buffer。 + /// + void BindData(ASURA_MOVE DataBuffer* buffer); + + /// + /// Data buffer不会再filedata析构时销毁,当lua引用计数为0时由lua调用GC销毁。创建mData时会添加一个成员引用。 + /// + ASURA_REF DataBuffer* m_Data; + Luax::LuaxMemberRef m_DataRef; + + std::string m_FileName; ///< 包含扩展名的文件名 + std::string m_Extension; ///< 不包含点的扩展名 + std::string m_Name; ///< 不包含点和后缀的文件名 + + LUAX_DECL_METHOD(_GetDataBuffer); + LUAX_DECL_METHOD(_GetFileName); + LUAX_DECL_METHOD(_GetExtension); + LUAX_DECL_METHOD(_GetName); + + }; + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0