upd: ready to write the database and engine

This commit is contained in:
2023-12-12 15:46:43 +00:00
parent 824145ec39
commit d9d32c5e24
8 changed files with 65 additions and 64 deletions

View File

@ -12,6 +12,12 @@
#include <string>
#include <thread>
#include <vector>
namespace BookStore_ZYM {
extern std::mutex debug_Print_Mutex;
extern bool shut_down;
} // namespace BookStore_ZYM
class FatalError : public std::exception {
public:
FatalError(const char *__message, int __code)
@ -94,10 +100,7 @@ class SessionClass {
std::string SessionToken;
std::string OuthorizationKey;
};
namespace BookStore_ZYM {
extern std::mutex debug_Print_Mutex;
extern bool shut_down;
} // namespace BookStore_ZYM
void debugPrint();
template <typename... Args>
void debugPrint(Args... args) {
@ -110,4 +113,10 @@ void debugPrint(Args... args) {
void Respond(BlockingStringStream *output_ptr, std::string SessionToken,
std::string OperationToken, std::string AuthenticationKey,
const std::vector<std::string> &ret);
class UserItemClass {
public:
char user_id[31], password[31], user_name[31];
unsigned char privilege;
};
#endif // PROTECTOR_UTILITY_H

View File

@ -0,0 +1,28 @@
#ifndef PROTECTOR_DATABASE_HPP
#define PROTECTOR_DATABASE_HPP
#include <string>
#include <vector>
#include "bs-utility.h"
#include "drivearray.hpp"
#include "key2index.hpp"
class UserDataBase {
DriveArray<UserItemClass> full_user_data;
String2Index user_name2index;
public:
UserDataBase() = default;
void Open(std::string file_name);
bool PAM(const std::string &user_id, const std::string &password);
};
class BookDataBase {
;
};
class FinanceDataBase {
;
};
class OperationLogDataBase {
;
};
#endif // PROTECTOR_DATABASE_HPP

View File

@ -1,53 +0,0 @@
#ifndef BPT_DATABASE_HPP
#define BPT_DATABASE_HPP
#include <string>
#include <vector>
#include "drivearray.hpp"
#include "key2index.hpp"
template <class StorageType>
class DriveMultiMap_string {
private:
String2Index Indexer;
DriveArray<StorageType, 2, 100> Storage;
bool is_open = false;
public:
DriveMultiMap_string() = default;
void OpenFile(const std::string __file_name) noexcept {
Indexer.OpenFile(__file_name + ".idx");
Storage.OpenFile(__file_name + ".dat");
is_open = true;
}
std::vector<StorageType> Find(const std::string &key) noexcept {
if (!is_open) return {};
std::vector<StorageType> ret;
std::vector<int> idxs = std::move(Indexer.Find(key));
for (auto idx : idxs) {
StorageType tmp;
Storage.read(tmp, idx);
ret.push_back(tmp);
}
return std::move(ret);
}
void Delete(const std::string &key, const StorageType &value) noexcept {
if (!is_open) return;
std::vector<int> idxs = std::move(Indexer.Find(key));
for (auto idx : idxs) {
StorageType tmp;
Storage.read(tmp, idx);
if (tmp == value) {
Storage.Delete(idx);
Indexer.Delete(key, idx);
return;
}
}
}
void Insert(const std::string &key, StorageType &value) noexcept {
if (!is_open) return;
int idx = Storage.write(value);
Indexer.Insert(key, idx);
}
};
#endif // BPT_DATABASE_HPP

View File

@ -3,12 +3,16 @@
#include <stack>
#include <string>
#include <vector>
#include "database.h"
class BookStoreEngineClass {
std::string config_dir;
UserDataBase user_data_base;
public:
BookStoreEngineClass() = delete;
BookStoreEngineClass(std::string config_dir) : config_dir(config_dir) {}
std::vector<std::string> Execute(const std::string &cmd, std::stack<std::string> &login_stack);
BookStoreEngineClass(std::string __config_dir);
std::vector<std::string> Execute(const std::string &cmd,
std::stack<std::string> &login_stack);
};
#endif // PROTECTOR_ENGINE_H