diff --git a/Jupiter/Database.cpp b/Jupiter/Database.cpp index f305989..f95bdb5 100644 --- a/Jupiter/Database.cpp +++ b/Jupiter/Database.cpp @@ -11,7 +11,7 @@ struct Jupiter::Database::Data { static bool process_file(Jupiter::Database *db); - static bool create_database(FILE *file, Jupiter::DataBuffer *header); + static bool create_database(FILE *file, const Jupiter::DataBuffer *header); bool auto_create = true; Jupiter::CStringS file_name; @@ -54,6 +54,7 @@ bool Jupiter::Database::Data::process_file(Jupiter::Database *db) if (file != nullptr) { db->create_header(file); + fclose(file); return true; } } @@ -64,6 +65,16 @@ bool Jupiter::Database::Data::process_file(Jupiter::Database *db) return r; } +Jupiter::Database::Database() +{ + Jupiter::Database::data_ = new Jupiter::Database::Data(); +} + +Jupiter::Database::~Database() +{ + delete Jupiter::Database::data_; +} + bool Jupiter::Database::process_file(FILE *file) { /** @@ -134,7 +145,7 @@ bool Jupiter::Database::append(FILE *file, Jupiter::DataBuffer &data) return true; } -bool Jupiter::Database::create_database(Jupiter::ReadableString &file, Jupiter::DataBuffer *header) +bool Jupiter::Database::create_database(const Jupiter::ReadableString &file, const Jupiter::DataBuffer *header) { char *str = new char[file.size() + 1]; memcpy(str, file.ptr(), file.size() * sizeof(char)); @@ -144,12 +155,12 @@ bool Jupiter::Database::create_database(Jupiter::ReadableString &file, Jupiter:: return r; } -bool Jupiter::Database::create_database(Jupiter::CStringType &file, Jupiter::DataBuffer *header) +bool Jupiter::Database::create_database(const Jupiter::CStringType &file, const Jupiter::DataBuffer *header) { return Jupiter::Database::create_database(file.c_str(), header); } -bool Jupiter::Database::create_database(const char *file, Jupiter::DataBuffer *header) +bool Jupiter::Database::create_database(const char *file, const Jupiter::DataBuffer *header) { FILE *f = fopen(file, "wb"); if (file == nullptr) @@ -157,7 +168,7 @@ bool Jupiter::Database::create_database(const char *file, Jupiter::DataBuffer *h return Jupiter::Database::Data::create_database(f, header); } -bool Jupiter::Database::Data::create_database(FILE *file, Jupiter::DataBuffer *header) +bool Jupiter::Database::Data::create_database(FILE *file, const Jupiter::DataBuffer *header) { if (header != nullptr) fwrite(header->getHead(), sizeof(uint8_t), header->size(), file); diff --git a/Jupiter/Database.h b/Jupiter/Database.h index af515d3..e3f9c66 100644 --- a/Jupiter/Database.h +++ b/Jupiter/Database.h @@ -103,12 +103,12 @@ namespace Jupiter * @param flie Name of the Database to generate * @param header DataBuffer containing the header to write to the file */ - static bool create_database(Jupiter::ReadableString &file, Jupiter::DataBuffer *header = nullptr); - static bool create_database(Jupiter::CStringType &file, Jupiter::DataBuffer *header = nullptr); - static bool create_database(const char *file, Jupiter::DataBuffer *header = nullptr); + static bool create_database(const Jupiter::ReadableString &file, const Jupiter::DataBuffer *header = nullptr); + static bool create_database(const Jupiter::CStringType &file, const Jupiter::DataBuffer *header = nullptr); + static bool create_database(const char *file, const Jupiter::DataBuffer *header = nullptr); /** - * @brief When True, process_file() will automatically call create_header() if so such file exists. + * @brief When True, process_file() will automatically call create_header() if no such file exists. * Default: true * * @return True if databases should automatically be generated, false otherwise. @@ -122,6 +122,21 @@ namespace Jupiter */ void set_auto_create(bool auto_create); + /** + * @brief Default constructor for the Database class. + */ + Database(); + + /** + * @brief Copy constructor for the Database class. + */ + Database(const Database &) = delete; + + /** + * @brief Destructor for the Database class. + */ + ~Database(); + private: struct Data; Data *data_; diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index d7c3d90..75e2cac 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ