From 7d5f055547e70fa93ee9ac944e62f8d657b9dc55 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 19 Oct 2018 08:36:44 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/Filesystem/Buffer.h | 67 -------------------------------- src/libjin/Filesystem/Filesystem.cpp | 67 -------------------------------- src/libjin/Filesystem/Filesystem.h | 31 --------------- src/libjin/Filesystem/je_buffer.h | 67 ++++++++++++++++++++++++++++++++ src/libjin/Filesystem/je_filesystem.cpp | 68 +++++++++++++++++++++++++++++++++ src/libjin/Filesystem/je_filesystem.h | 31 +++++++++++++++ 6 files changed, 166 insertions(+), 165 deletions(-) delete mode 100644 src/libjin/Filesystem/Buffer.h delete mode 100644 src/libjin/Filesystem/Filesystem.cpp delete mode 100644 src/libjin/Filesystem/Filesystem.h create mode 100644 src/libjin/Filesystem/je_buffer.h create mode 100644 src/libjin/Filesystem/je_filesystem.cpp create mode 100644 src/libjin/Filesystem/je_filesystem.h (limited to 'src/libjin/Filesystem') diff --git a/src/libjin/Filesystem/Buffer.h b/src/libjin/Filesystem/Buffer.h deleted file mode 100644 index f0d987a..0000000 --- a/src/libjin/Filesystem/Buffer.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef __LIBJIN_BUFFER_H -#define __LIBJIN_BUFFER_H - -#include -#include - -namespace jin -{ - namespace filesystem - { - - /** - * 在堆上分配指定空间的buffer - */ - class Buffer - { - public: - Buffer() : data(0), size(0) {} - Buffer(const Buffer& src) - { - delete[] data; - size = src.size; - data = new char[size]; - memcpy(data, src.data, size); - } - Buffer(void* d, int s) - { - data = new char[size]; - memcpy(data, d, size); - size = s; - } - Buffer(size_t s) - { - data = new char[s]; - memset(data, 0, s); - size = s; - } - ~Buffer() - { - delete[] data; - size = 0; - } - void operator = (const Buffer& buffer) - { - delete[] data; - size = buffer.size; - data = new char[size]; - memcpy(data, buffer.data, size); - } - - void clear() - { - if (data == nullptr) - return; - free(data); - data = nullptr; - } - - void* data; - unsigned int size; - - }; - - } // namespace filesystem -} // namespace jin - -#endif \ No newline at end of file diff --git a/src/libjin/Filesystem/Filesystem.cpp b/src/libjin/Filesystem/Filesystem.cpp deleted file mode 100644 index 8dce5a3..0000000 --- a/src/libjin/Filesystem/Filesystem.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "filesystem.h" -#include -#include -#include /* defines FILENAME_MAX */ - -namespace jin -{ - namespace filesystem - { - - Filesystem* Filesystem::fs = 0; - - Filesystem::Filesystem() - { - S = smtnewshared(); - } - - Filesystem* Filesystem::get() - { - return fs ? fs : (fs = new Filesystem()); - } - - void Filesystem::mount(const char * path) - { - int err = smtmount(S, path); - if (err) - { - printf("%s mounted path %s", smterrstr(err), path); - exit(1); - } - } - - int Filesystem::read(const char* path, Buffer* buffer) - { - buffer->data = smtread(S, path, &buffer->size); - if (buffer->data == 0) - return 0; - return 1; - } - - void* Filesystem::read(const char* path, unsigned int* len) - { - return smtread(S, path, len); - } - - const char* Filesystem::getFull(const char* path) - { - return smtfullpath(S, path); - } - - bool Filesystem::isDir(const char* path) - { - return smtisdir(S, path); - } - - bool Filesystem::isFile(const char* path) - { - return smtisreg(S, path); - } - - bool Filesystem::exists(const char* path) - { - return smtexists(S, path) == 0; - } - - } // namespace filesystem -} // namespace jin \ No newline at end of file diff --git a/src/libjin/Filesystem/Filesystem.h b/src/libjin/Filesystem/Filesystem.h deleted file mode 100644 index b13e207..0000000 --- a/src/libjin/Filesystem/Filesystem.h +++ /dev/null @@ -1,31 +0,0 @@ -#include "buffer.h" -#include "../3rdparty/smount/smount.h" - -namespace jin -{ - namespace filesystem - { - /* 资源管理 */ - class Filesystem - { - public: - static Filesystem* get(); - - Filesystem(); - - bool isDir(const char* path); - bool isFile(const char* path); - bool exists(const char* path); - int read(const char* path, Buffer* buffer); - void* read(const char* path, unsigned int* len); - void mount(const char* root); - const char* getFull(const char* path); - - private: - static Filesystem* fs; - smtShared* S; - - }; - - } // namespace filesystem -} // namespace jin \ No newline at end of file diff --git a/src/libjin/Filesystem/je_buffer.h b/src/libjin/Filesystem/je_buffer.h new file mode 100644 index 0000000..f0d987a --- /dev/null +++ b/src/libjin/Filesystem/je_buffer.h @@ -0,0 +1,67 @@ +#ifndef __LIBJIN_BUFFER_H +#define __LIBJIN_BUFFER_H + +#include +#include + +namespace jin +{ + namespace filesystem + { + + /** + * 在堆上分配指定空间的buffer + */ + class Buffer + { + public: + Buffer() : data(0), size(0) {} + Buffer(const Buffer& src) + { + delete[] data; + size = src.size; + data = new char[size]; + memcpy(data, src.data, size); + } + Buffer(void* d, int s) + { + data = new char[size]; + memcpy(data, d, size); + size = s; + } + Buffer(size_t s) + { + data = new char[s]; + memset(data, 0, s); + size = s; + } + ~Buffer() + { + delete[] data; + size = 0; + } + void operator = (const Buffer& buffer) + { + delete[] data; + size = buffer.size; + data = new char[size]; + memcpy(data, buffer.data, size); + } + + void clear() + { + if (data == nullptr) + return; + free(data); + data = nullptr; + } + + void* data; + unsigned int size; + + }; + + } // namespace filesystem +} // namespace jin + +#endif \ No newline at end of file diff --git a/src/libjin/Filesystem/je_filesystem.cpp b/src/libjin/Filesystem/je_filesystem.cpp new file mode 100644 index 0000000..339d470 --- /dev/null +++ b/src/libjin/Filesystem/je_filesystem.cpp @@ -0,0 +1,68 @@ +#include +#include +#include /* defines FILENAME_MAX */ + +#include "je_filesystem.h" + +namespace jin +{ + namespace filesystem + { + + Filesystem* Filesystem::fs = 0; + + Filesystem::Filesystem() + { + S = smtnewshared(); + } + + Filesystem* Filesystem::get() + { + return fs ? fs : (fs = new Filesystem()); + } + + void Filesystem::mount(const char * path) + { + int err = smtmount(S, path); + if (err) + { + printf("%s mounted path %s", smterrstr(err), path); + exit(1); + } + } + + int Filesystem::read(const char* path, Buffer* buffer) + { + buffer->data = smtread(S, path, &buffer->size); + if (buffer->data == 0) + return 0; + return 1; + } + + void* Filesystem::read(const char* path, unsigned int* len) + { + return smtread(S, path, len); + } + + const char* Filesystem::getFull(const char* path) + { + return smtfullpath(S, path); + } + + bool Filesystem::isDir(const char* path) + { + return smtisdir(S, path); + } + + bool Filesystem::isFile(const char* path) + { + return smtisreg(S, path); + } + + bool Filesystem::exists(const char* path) + { + return smtexists(S, path) == 0; + } + + } // namespace filesystem +} // namespace jin \ No newline at end of file diff --git a/src/libjin/Filesystem/je_filesystem.h b/src/libjin/Filesystem/je_filesystem.h new file mode 100644 index 0000000..5d65fea --- /dev/null +++ b/src/libjin/Filesystem/je_filesystem.h @@ -0,0 +1,31 @@ +#include "je_buffer.h" +#include "../3rdparty/smount/smount.h" + +namespace jin +{ + namespace filesystem + { + /* 资源管理 */ + class Filesystem + { + public: + static Filesystem* get(); + + Filesystem(); + + bool isDir(const char* path); + bool isFile(const char* path); + bool exists(const char* path); + int read(const char* path, Buffer* buffer); + void* read(const char* path, unsigned int* len); + void mount(const char* root); + const char* getFull(const char* path); + + private: + static Filesystem* fs; + smtShared* S; + + }; + + } // namespace filesystem +} // namespace jin \ No newline at end of file -- cgit v1.1-26-g67d0