metaforce/hecl/lib/database/CLooseDatabase.hpp

83 lines
1.6 KiB
C++
Raw Normal View History

2015-05-21 02:33:05 +00:00
#ifndef CLOOSEDATABASE_HPP
#define CLOOSEDATABASE_HPP
2015-05-17 04:55:29 +00:00
#include <stdio.h>
#include <blowfish/blowfish.h>
#include <zlib/zlib.h>
2015-05-17 04:55:29 +00:00
#include "HECLDatabase.hpp"
#include "CSQLite.hpp"
namespace HECLDatabase
{
class CLooseDatabase final : public IDatabase
{
CSQLite m_sql;
Access m_access;
2015-05-17 04:55:29 +00:00
public:
CLooseDatabase(const std::string& path, Access access)
2015-05-21 02:33:05 +00:00
: m_sql(path.c_str(), (access == A_READONLY) ? true : false),
m_access(access)
2015-05-17 04:55:29 +00:00
{
}
~CLooseDatabase()
{
}
Type getType() const
{
2015-05-21 02:33:05 +00:00
return T_LOOSE;
2015-05-17 04:55:29 +00:00
}
Access getAccess() const
{
return m_access;
}
const IDataObject* lookupObject(size_t id) const
2015-05-17 04:55:29 +00:00
{
}
const IDataObject* lookupObject(const std::string& name) const
{
}
const IDataObject* addDataBlob(const std::string& name, const void* data, size_t length)
2015-05-17 04:55:29 +00:00
{
/* Hash data */
2015-05-20 05:22:32 +00:00
HECL::ObjectHash hash(data, length);
/* Compress data into file */
FILE* fp = fopen("", "wb");
2015-05-20 05:22:32 +00:00
m_sql.insertObject(name, "DUMB", hash, length, length);
2015-05-17 04:55:29 +00:00
}
const IDataObject* addDataBlob(const void* data, size_t length)
2015-05-17 04:55:29 +00:00
{
return addDataBlob(std::string(), data, length);
2015-05-17 04:55:29 +00:00
}
bool writeDatabase(IDatabase::Type type, const std::string& path) const
{
2015-05-21 02:33:05 +00:00
if (type == T_PACKED)
{
size_t bufSz;
void* buf = m_sql.fillDBBuffer(bufSz);
FILE* fp = fopen(path.c_str(), "wb");
fwrite(buf, 1, bufSz, fp);
return true;
}
return false;
2015-05-17 04:55:29 +00:00
}
};
}
2015-05-21 02:33:05 +00:00
#endif // CLOOSEDATABASE_HPP