Browse Source

Database:

* Improved const correctness
* Added missing constructors and destructor.
* Added missing fclose() in process_file
release/0.19
JustinAJ 10 years ago
parent
commit
5a45d44a50
  1. 21
      Jupiter/Database.cpp
  2. 23
      Jupiter/Database.h
  3. BIN
      Release/Jupiter.lib

21
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);

23
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_;

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save