From 8b00d67febf133e89f6a0bfabc41feed555dc4a9 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 12 Jan 2019 21:48:33 +0800 Subject: =?UTF-8?q?*=E5=8E=BB=E6=8E=89=E6=96=87=E4=BB=B6=E5=89=8D=E7=BC=80?= =?UTF-8?q?je=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/filesystem/asset_database.cpp | 85 ++++++++++++++ src/libjin/filesystem/asset_database.h | 114 +++++++++++++++++++ src/libjin/filesystem/buffer.h | 169 ++++++++++++++++++++++++++++ src/libjin/filesystem/je_asset_database.cpp | 85 -------------- src/libjin/filesystem/je_asset_database.h | 114 ------------------- src/libjin/filesystem/je_buffer.h | 169 ---------------------------- 6 files changed, 368 insertions(+), 368 deletions(-) create mode 100644 src/libjin/filesystem/asset_database.cpp create mode 100644 src/libjin/filesystem/asset_database.h create mode 100644 src/libjin/filesystem/buffer.h delete mode 100644 src/libjin/filesystem/je_asset_database.cpp delete mode 100644 src/libjin/filesystem/je_asset_database.h delete mode 100644 src/libjin/filesystem/je_buffer.h (limited to 'src/libjin/filesystem') diff --git a/src/libjin/filesystem/asset_database.cpp b/src/libjin/filesystem/asset_database.cpp new file mode 100644 index 0000000..e532f41 --- /dev/null +++ b/src/libjin/filesystem/asset_database.cpp @@ -0,0 +1,85 @@ +#include "../core/configuration.h" +#if defined(jin_filesystem) + +#include +#include +#include /* defines FILENAME_MAX */ + +#include "../common/exception.h" + +#include "asset_database.h" + +namespace JinEngine +{ + namespace Filesystem + { + + AssetDatabase* AssetDatabase::mAssetDatabase = 0; + + AssetDatabase::AssetDatabase() + { + mSmt = smtnewshared(); + } + + AssetDatabase* AssetDatabase::get() + { + return mAssetDatabase ? mAssetDatabase : (mAssetDatabase = new AssetDatabase()); + } + + void AssetDatabase::mount(const char * path) + { + int err = smtmount(mSmt, path); + if (err) + { + printf("%s mounted path %s", smterrstr(err), path); + exit(1); + } + } + + void AssetDatabase::read(const char* path, Buffer& buffer) + { + size_t size; + byte* data = (byte*)smtread(mSmt, path, &size); + if (data == nullptr) + throw Exception("Could not read file %s.", path); + buffer.bind(data, size); + } + + Buffer* read(const char* path) + { + return nullptr; + } + + void* AssetDatabase::read(const char* path, unsigned int* len) + { + return smtread(mSmt, path, len); + } + + const char* AssetDatabase::getFull(const char* path) + { + return smtfullpath(mSmt, path); + } + + bool AssetDatabase::isDir(const char* path) + { + return smtisdir(mSmt, path); + } + + bool AssetDatabase::isFile(const char* path) + { + return smtisreg(mSmt, path); + } + + bool AssetDatabase::exists(const char* path) + { + return smtexists(mSmt, path) == 0; + } +/* + std::vector AssetDatabase::getFiles(const char* path, bool recursive) + { + } +*/ + } // namespace Filesystem +} // namespace JinEngine + +#endif // jin_filesystem \ No newline at end of file diff --git a/src/libjin/filesystem/asset_database.h b/src/libjin/filesystem/asset_database.h new file mode 100644 index 0000000..2d7d5a3 --- /dev/null +++ b/src/libjin/filesystem/asset_database.h @@ -0,0 +1,114 @@ +#ifndef __JE_ASSET_DATABASE_H__ +#define __JE_ASSET_DATABASE_H__ + +#include "../core/configuration.h" +#if defined(jin_filesystem) + +#include + +#include "smount/smount.h" + +#include "buffer.h" + +namespace JinEngine +{ + namespace Filesystem + { + + /// + /// Assets managment. + /// + class AssetDatabase : public Object + { + public: + /// + /// Get asset database singleton. + /// + /// @param Singleton of asset database. + /// + static AssetDatabase* get(); + + /// + /// Asset database constructor. + /// + AssetDatabase(); + + /// + /// Set asset root folder. + /// + /// @param root Root folder of assets. + /// + void mount(const char* root); + + /// + /// Check if the path is directory. + /// + /// @param path Path under asset folder. + /// @return True if the given path is directory, otherwise return false. + /// + bool isDir(const char* path); + + /// + /// Check if the path is file. + /// + /// @param path Path under asset folder. + /// @return True if the given path is file, otherwise return false. + /// + bool isFile(const char* path); + + /// + /// Check if the path exists. + /// @param path Given path. + /// @return True if path exists, otherwise return false. + /// + bool exists(const char* path); + + /// + /// Read file into a buffer. + /// + /// @param path Path of file. + /// @param buffer Buffer to fill. + /// @return True if read sucessful, otherwise return false. + /// + void read(const char* path, Buffer& buffer); + + /// + /// Read file and return data content. + /// + /// @param path Path of file. + /// @param length Length of data. + /// @return Data if read sucessful, otherwise return null. + /// + void* read(const char* path, unsigned int* length); + + /// + /// Get files under given directory. + /// + /// @param path Path of directory. + /// @param recursive Recursivily search folder. + /// @return File list under given directory. + /// + std::vector getFiles(const char* directory, bool recursive = false); + + /// + /// Get full path of asset. + /// + /// @param path Path of asset. + /// @return Full path of asset. + /// + const char* getFull(const char* path); + + private: + static AssetDatabase* mAssetDatabase; +#if jin_filesystem == jin_filesystem_smount + smtShared* mSmt; +#endif + + }; + + } // namespace Filesystem +} // namespace JinEngine + +#endif // jin_filesystem + +#endif \ No newline at end of file diff --git a/src/libjin/filesystem/buffer.h b/src/libjin/filesystem/buffer.h new file mode 100644 index 0000000..2b5be6a --- /dev/null +++ b/src/libjin/filesystem/buffer.h @@ -0,0 +1,169 @@ +#ifndef __JE_BUFFER_H__ +#define __JE_BUFFER_H__ + +#include "../core/configuration.h" +#if defined(jin_filesystem) + +#include +#include + +#include "../common/temporary.h" +#include "../common/types.h" + +namespace JinEngine +{ + namespace Filesystem + { + + /// + /// Data buffer allocated on heap. + /// + class Buffer : public Temporary + { + public: + /// + /// Buffer constructor. + /// + Buffer() + : mData(0) + , mSize(0) + { + } + + /// + /// Copy constructor. + /// + /// @param src Buffer source. + /// + Buffer(const Buffer& src) + { + delete[] mData; + mSize = src.mSize; + mData = new byte[mSize]; + memcpy(mData, src.mData, mSize); + } + + /// + /// Buffer constructor. + /// + /// @param data Buffer data. + /// @param size Size of buffer. + /// + Buffer(void* data, int size) + { + mSize = size; + mData = new byte[mSize]; + memcpy(mData, data, mSize); + } + + /// + /// Buffer constructor. + /// + /// @param size Size of data. + /// + Buffer(size_t size) + { + mData = new byte[size]; + memset(mData, 0, size); + mSize = size; + } + + /// + /// Buffer destructor. + /// + ~Buffer() + { + delete[] mData; + mSize = 0; + } + + /// + /// Set buffer data. + /// + /// @param data Buffer data. + /// @param size Size of data. + /// + void set(byte* data, size_t size) + { + if (data == nullptr) + return; + if (mSize != size) + { + delete mData; + mData = new byte[size]; + } + mSize = size; + memcpy(mData, data, size); + } + + /// + /// Bind buffer data. + /// + /// @param data Buffer data. + /// @param size Size of buffer. + /// + void bind(byte* data, size_t size) + { + if (mData != nullptr) + delete mData; + mSize = size; + mData = data; + } + + /// + /// Buffer assignment. + /// + /// @param buffer Buffer to copy. + /// + void operator = (const Buffer& buffer) + { + delete[] mData; + mSize = buffer.mSize; + mData = new byte[mSize]; + memcpy(mData, buffer.mData, mSize); + } + + /// + /// Get data addresss. + /// + /// @return Data address. + /// + const byte* operator &() + { + return mData; + } + + /// + /// Get data size. + /// + /// @return Size of data. + /// + const inline size_t size() + { + return mSize; + } + + /// + /// Clear data. + /// + void clear() + { + if (mData == nullptr) + return; + delete mData; + mData = nullptr; + mSize = 0; + } + + private: + byte* mData; + size_t mSize; + + }; + + } // namespace Filesystem +} // namespace JinEngine + +#endif // jin_filesystem + +#endif \ No newline at end of file diff --git a/src/libjin/filesystem/je_asset_database.cpp b/src/libjin/filesystem/je_asset_database.cpp deleted file mode 100644 index 1203643..0000000 --- a/src/libjin/filesystem/je_asset_database.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "../core/je_configuration.h" -#if defined(jin_filesystem) - -#include -#include -#include /* defines FILENAME_MAX */ - -#include "../common/je_exception.h" - -#include "je_asset_database.h" - -namespace JinEngine -{ - namespace Filesystem - { - - AssetDatabase* AssetDatabase::mAssetDatabase = 0; - - AssetDatabase::AssetDatabase() - { - mSmt = smtnewshared(); - } - - AssetDatabase* AssetDatabase::get() - { - return mAssetDatabase ? mAssetDatabase : (mAssetDatabase = new AssetDatabase()); - } - - void AssetDatabase::mount(const char * path) - { - int err = smtmount(mSmt, path); - if (err) - { - printf("%s mounted path %s", smterrstr(err), path); - exit(1); - } - } - - void AssetDatabase::read(const char* path, Buffer& buffer) - { - size_t size; - byte* data = (byte*)smtread(mSmt, path, &size); - if (data == nullptr) - throw Exception("Could not read file %s.", path); - buffer.bind(data, size); - } - - Buffer* read(const char* path) - { - return nullptr; - } - - void* AssetDatabase::read(const char* path, unsigned int* len) - { - return smtread(mSmt, path, len); - } - - const char* AssetDatabase::getFull(const char* path) - { - return smtfullpath(mSmt, path); - } - - bool AssetDatabase::isDir(const char* path) - { - return smtisdir(mSmt, path); - } - - bool AssetDatabase::isFile(const char* path) - { - return smtisreg(mSmt, path); - } - - bool AssetDatabase::exists(const char* path) - { - return smtexists(mSmt, path) == 0; - } -/* - std::vector AssetDatabase::getFiles(const char* path, bool recursive) - { - } -*/ - } // namespace Filesystem -} // namespace JinEngine - -#endif // jin_filesystem \ No newline at end of file diff --git a/src/libjin/filesystem/je_asset_database.h b/src/libjin/filesystem/je_asset_database.h deleted file mode 100644 index 82d5ab4..0000000 --- a/src/libjin/filesystem/je_asset_database.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef __JE_ASSET_DATABASE_H__ -#define __JE_ASSET_DATABASE_H__ - -#include "../core/je_configuration.h" -#if defined(jin_filesystem) - -#include - -#include "smount/smount.h" - -#include "je_buffer.h" - -namespace JinEngine -{ - namespace Filesystem - { - - /// - /// Assets managment. - /// - class AssetDatabase : public Object - { - public: - /// - /// Get asset database singleton. - /// - /// @param Singleton of asset database. - /// - static AssetDatabase* get(); - - /// - /// Asset database constructor. - /// - AssetDatabase(); - - /// - /// Set asset root folder. - /// - /// @param root Root folder of assets. - /// - void mount(const char* root); - - /// - /// Check if the path is directory. - /// - /// @param path Path under asset folder. - /// @return True if the given path is directory, otherwise return false. - /// - bool isDir(const char* path); - - /// - /// Check if the path is file. - /// - /// @param path Path under asset folder. - /// @return True if the given path is file, otherwise return false. - /// - bool isFile(const char* path); - - /// - /// Check if the path exists. - /// @param path Given path. - /// @return True if path exists, otherwise return false. - /// - bool exists(const char* path); - - /// - /// Read file into a buffer. - /// - /// @param path Path of file. - /// @param buffer Buffer to fill. - /// @return True if read sucessful, otherwise return false. - /// - void read(const char* path, Buffer& buffer); - - /// - /// Read file and return data content. - /// - /// @param path Path of file. - /// @param length Length of data. - /// @return Data if read sucessful, otherwise return null. - /// - void* read(const char* path, unsigned int* length); - - /// - /// Get files under given directory. - /// - /// @param path Path of directory. - /// @param recursive Recursivily search folder. - /// @return File list under given directory. - /// - std::vector getFiles(const char* directory, bool recursive = false); - - /// - /// Get full path of asset. - /// - /// @param path Path of asset. - /// @return Full path of asset. - /// - const char* getFull(const char* path); - - private: - static AssetDatabase* mAssetDatabase; -#if jin_filesystem == jin_filesystem_smount - smtShared* mSmt; -#endif - - }; - - } // namespace Filesystem -} // namespace JinEngine - -#endif // jin_filesystem - -#endif \ No newline at end of file diff --git a/src/libjin/filesystem/je_buffer.h b/src/libjin/filesystem/je_buffer.h deleted file mode 100644 index b3c6612..0000000 --- a/src/libjin/filesystem/je_buffer.h +++ /dev/null @@ -1,169 +0,0 @@ -#ifndef __JE_BUFFER_H__ -#define __JE_BUFFER_H__ - -#include "../core/je_configuration.h" -#if defined(jin_filesystem) - -#include -#include - -#include "../common/je_temporary.h" -#include "../common/je_types.h" - -namespace JinEngine -{ - namespace Filesystem - { - - /// - /// Data buffer allocated on heap. - /// - class Buffer : public Temporary - { - public: - /// - /// Buffer constructor. - /// - Buffer() - : mData(0) - , mSize(0) - { - } - - /// - /// Copy constructor. - /// - /// @param src Buffer source. - /// - Buffer(const Buffer& src) - { - delete[] mData; - mSize = src.mSize; - mData = new byte[mSize]; - memcpy(mData, src.mData, mSize); - } - - /// - /// Buffer constructor. - /// - /// @param data Buffer data. - /// @param size Size of buffer. - /// - Buffer(void* data, int size) - { - mSize = size; - mData = new byte[mSize]; - memcpy(mData, data, mSize); - } - - /// - /// Buffer constructor. - /// - /// @param size Size of data. - /// - Buffer(size_t size) - { - mData = new byte[size]; - memset(mData, 0, size); - mSize = size; - } - - /// - /// Buffer destructor. - /// - ~Buffer() - { - delete[] mData; - mSize = 0; - } - - /// - /// Set buffer data. - /// - /// @param data Buffer data. - /// @param size Size of data. - /// - void set(byte* data, size_t size) - { - if (data == nullptr) - return; - if (mSize != size) - { - delete mData; - mData = new byte[size]; - } - mSize = size; - memcpy(mData, data, size); - } - - /// - /// Bind buffer data. - /// - /// @param data Buffer data. - /// @param size Size of buffer. - /// - void bind(byte* data, size_t size) - { - if (mData != nullptr) - delete mData; - mSize = size; - mData = data; - } - - /// - /// Buffer assignment. - /// - /// @param buffer Buffer to copy. - /// - void operator = (const Buffer& buffer) - { - delete[] mData; - mSize = buffer.mSize; - mData = new byte[mSize]; - memcpy(mData, buffer.mData, mSize); - } - - /// - /// Get data addresss. - /// - /// @return Data address. - /// - const byte* operator &() - { - return mData; - } - - /// - /// Get data size. - /// - /// @return Size of data. - /// - const inline size_t size() - { - return mSize; - } - - /// - /// Clear data. - /// - void clear() - { - if (mData == nullptr) - return; - delete mData; - mData = nullptr; - mSize = 0; - } - - private: - byte* mData; - size_t mSize; - - }; - - } // namespace Filesystem -} // namespace JinEngine - -#endif // jin_filesystem - -#endif \ No newline at end of file -- cgit v1.1-26-g67d0