Skip to content

Commit

Permalink
Update Data
Browse files Browse the repository at this point in the history
  • Loading branch information
Daynlight committed Oct 25, 2024
1 parent 7102432 commit cccab71
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Data.h → DATA/Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#include "File.h"
#include "Folder.h"
// [Feature] Change SQL to MySQL, PostgreSQL, SQLite
#include "SQLite.h"
// [Feature] Add SQLite
// [Feature] FtpServer (open remote folder)
35 changes: 35 additions & 0 deletions DATA/File.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <string>
#include <fstream>
#include <vector>
#include "Settings.h"
#include "Hash.h"

namespace Data {
class File {
public:
File(const std::string& path_to_file = DEFAULTPATHTOFILE, size_t size = 0);
size_t size();
bool isEmpty();
bool isDifferent(IHash* hash = nullptr); // [FEATURE] Optimize this function
// [FEATURE] Thread isDifferentAsync
void changePathToFile(const std::string& path_to_file);
void createFile();
void removeFile();
void push(const std::string& data);
std::string pop();
std::string pop(const size_t& index);
void remove(const size_t& index);
void save(IHash* hash = nullptr); // [FEATURE] simplify this function, optimize and hash whole file
// [FEATURE] Thread saveAsync
void read(IHash* hash = nullptr); // [FEATURE] simplify this function, optimize and un hash whole file
// [FEATURE] Thread readAsync
std::string& operator[](const size_t& index); // [FEATURE] Add for -> ptr variant
std::vector<std::string>::iterator begin();
std::vector<std::string>::iterator end();

private:
std::vector<std::string> content;
std::string path_to_file;
};
};
35 changes: 35 additions & 0 deletions DATA/Folder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include <filesystem>
#include <fstream>
#include <string>
#include <vector>
#include "File.h"

namespace Data {
class Folder {
public:
Folder(const std::filesystem::path& path_to_folder = DEFAULTPATHTOFOLDER);
size_t count();
bool exist();
bool isEmpty();
std::vector<std::string> filesList();
bool filesListIsDifferent(); // [FEATURE] Optimize this function
// [FEATURE] filesListIsDifferentAsync
void createFolder();
void removeFolder();
void createFile(const std::string& file_name);
void removeFile(const std::string& file_name);
void fetchFilesList(); // [FEATURE] Optimize this function
// [FEATURE] fetchFilesListAsync
void updateList();
bool fileExist(const std::string& file_name);
std::shared_ptr<Data::File> openFile(const std::string& file_name);
void clean();
std::vector<std::string>::iterator begin();
std::vector<std::string>::iterator end();

private:
std::vector<std::string> files;
std::filesystem::path path_to_folder;
};
};
23 changes: 23 additions & 0 deletions DATA/Hash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <string>

namespace Data {
class IHash {
public:
virtual std::string hash_function(std::string data) = 0;
virtual std::string un_hash_function(std::string data) = 0;
};

// [WARNING] No polish chars
class BaseHash : public IHash {
public:
BaseHash(const char* hash_key);
std::string hash_function(std::string data);
std::string un_hash_function(std::string data);

private:
const char* hash_key = "";
};

// [FEATURE] Add more hash functions
};
9 changes: 9 additions & 0 deletions DATA/Settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <string>
#include <filesystem>

const static inline std::string DATASEPERATOR = "sep;";
const static inline std::string DEFAULTPATHTOFILE = "data.txt";
const static inline std::filesystem::path DEFAULTPATHTOFOLDER = "";

#define DATAHASHBYPARTS false;
Binary file removed Data.lib
Binary file not shown.
Binary file added Main.exe
Binary file not shown.
Binary file added lib/DataDebug.lib
Binary file not shown.
Binary file added lib/DataRelease.lib
Binary file not shown.

0 comments on commit cccab71

Please sign in to comment.