2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 17:47:43 +00:00

tons of database interface work

This commit is contained in:
Jack Andersen
2015-05-20 16:33:05 -10:00
parent 880c9f6c95
commit f02aa1ca8f
20 changed files with 874 additions and 101 deletions

View File

@@ -1,6 +1,5 @@
#ifndef HECLDATABASE_CPP
#error This file must only be included from HECLDatabase.cpp
#endif
#ifndef CLOOSEDATABASE_HPP
#define CLOOSEDATABASE_HPP
#include <stdio.h>
#include <blowfish/blowfish.h>
@@ -18,7 +17,7 @@ class CLooseDatabase final : public IDatabase
Access m_access;
public:
CLooseDatabase(const std::string& path, Access access)
: m_sql(path.c_str(), (access == READONLY) ? true : false),
: m_sql(path.c_str(), (access == A_READONLY) ? true : false),
m_access(access)
{
@@ -31,7 +30,7 @@ public:
Type getType() const
{
return LOOSE;
return T_LOOSE;
}
Access getAccess() const
@@ -65,7 +64,7 @@ public:
bool writeDatabase(IDatabase::Type type, const std::string& path) const
{
if (type == PACKED)
if (type == T_PACKED)
{
size_t bufSz;
void* buf = m_sql.fillDBBuffer(bufSz);
@@ -79,3 +78,5 @@ public:
};
}
#endif // CLOOSEDATABASE_HPP

View File

@@ -1,6 +1,5 @@
#ifndef HECLDATABASE_CPP
#error This file must only be included from HECLDatabase.cpp
#endif
#ifndef CMEMORYDATABASE_HPP
#define CMEMORYDATABASE_HPP
#include "HECLDatabase.hpp"
#include "CSQLite.hpp"
@@ -14,7 +13,7 @@ class CMemoryDatabase final : public IDatabase
Access m_access;
public:
CMemoryDatabase(Access access)
: m_sql(":memory:", (m_access == READONLY) ? true : false), m_access(access)
: m_sql(":memory:", (m_access == A_READONLY) ? true : false), m_access(access)
{
}
@@ -26,7 +25,7 @@ public:
Type getType() const
{
return MEMORY;
return T_MEMORY;
}
Access getAccess() const
@@ -57,3 +56,5 @@ public:
};
}
#endif // CMEMORYDATABASE_HPP

View File

@@ -1,6 +1,5 @@
#ifndef HECLDATABASE_CPP
#error This file must only be included from HECLDatabase.cpp
#endif
#ifndef CPACKEDDATABASE_HPP
#define CPACKEDDATABASE_HPP
#include "HECLDatabase.hpp"
#include "CSQLite.hpp"
@@ -25,12 +24,12 @@ public:
Type getType() const
{
return PACKED;
return T_PACKED;
}
Access getAccess() const
{
return READONLY;
return A_READONLY;
}
const IDataObject* lookupObject(size_t id) const
@@ -56,3 +55,5 @@ public:
};
}
#endif // CPACKEDDATABASE_HPP

View File

@@ -0,0 +1,102 @@
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <system_error>
#include "HECLDatabase.hpp"
#include "CLooseDatabase.hpp"
namespace HECLDatabase
{
class CProject : public IProject
{
std::string m_rootPath;
IDatabase* m_mainDb;
IDatabase* m_cookedDb;
public:
CProject(const std::string& rootPath)
: m_rootPath(rootPath)
{
/* Stat for existing project directory (must already exist) */
struct stat myStat;
if (stat(m_rootPath.c_str(), &myStat))
throw std::error_code(errno, std::system_category());
if (!S_ISDIR(myStat.st_mode))
throw std::invalid_argument("provided path must be a directory; '" + m_rootPath + "' isn't");
/* Create project directory */
if (mkdir((m_rootPath + "/.hecl").c_str(), 0755))
{
if (errno != EEXIST)
throw std::error_code(errno, std::system_category());
}
/* Create or open databases */
m_mainDb = new CLooseDatabase(m_rootPath + "/.hecl/main.db", IDatabase::A_READWRITE);
m_cookedDb = new CLooseDatabase(m_rootPath + "/.hecl/cooked.db", IDatabase::A_READWRITE);
}
IDatabase* mainDatabase() const
{
}
IDatabase* cookedDatabase() const
{
}
void registerLogger(HECL::TLogger logger)
{
}
std::string getProjectRootPath(bool absolute) const
{
}
bool validateSubPath(const std::string& subpath) const
{
}
bool addPath(const std::string& path)
{
}
bool removePath(const std::string& path, bool recursive)
{
}
bool addGroup(const std::string& path)
{
}
bool removeGroup(const std::string& path)
{
}
bool cookPath(const std::string& path,
std::function<void(std::string&, Cost, unsigned)> feedbackCb,
bool recursive)
{
}
void interruptCook()
{
}
bool cleanPath(const std::string& path, bool recursive)
{
}
bool packagePath(const std::string& path, bool recursive)
{
}
};
IProject* NewProject(const std::string& rootPath)
{
return new CProject(rootPath);
}
}

View File

@@ -0,0 +1,11 @@
#include "HECLDatabase.hpp"
namespace HECLDatabase
{
class CRuntime : public IRuntime
{
};
}

View File

@@ -1,6 +1,7 @@
#include "HECLDatabase.hpp"
#define HECLDATABASE_CPP
#include "CLooseDatabase.hpp"
#include "CPackedDatabase.hpp"
#include "CMemoryDatabase.hpp"
@@ -12,13 +13,13 @@ IDatabase* NewDatabase(IDatabase::Type type, IDatabase::Access access, const std
{
switch (type)
{
case IDatabase::LOOSE:
case IDatabase::T_LOOSE:
return new CLooseDatabase(path, access);
case IDatabase::PACKED:
case IDatabase::T_PACKED:
return new CPackedDatabase(path);
case IDatabase::MEMORY:
case IDatabase::T_MEMORY:
return new CMemoryDatabase(access);
case IDatabase::UNKNOWN:
case IDatabase::T_UNKNOWN:
return nullptr;
}
return nullptr;

View File

@@ -7,4 +7,6 @@ HEADERS += \
SOURCES += \
$$PWD/HECLDatabase.cpp \
$$PWD/sqlite_hecl_mem_vfs.c
$$PWD/sqlite_hecl_mem_vfs.c \
$$PWD/CRuntime.cpp \
$$PWD/CProject.cpp