i'd say this is too easy but i know damn well implementing networking & multithreading is going to take my fucking soul
This commit is contained in:
parent
60afa6126f
commit
348c353dac
2 changed files with 13 additions and 7 deletions
|
|
@ -6,5 +6,5 @@ And also my first serious C++ project.
|
||||||
## Roadmap
|
## Roadmap
|
||||||
- [X] Basic K/V store
|
- [X] Basic K/V store
|
||||||
- [X] Remove/add entries
|
- [X] Remove/add entries
|
||||||
- [ ] Serialisation and saving
|
- [X] Serialisation and saving
|
||||||
- [ ] Networking
|
- [ ] Networking
|
||||||
|
|
|
||||||
18
main.cpp
18
main.cpp
|
|
@ -14,6 +14,14 @@ void save_database(Db& database, std::string file_name) {
|
||||||
db_file.close();
|
db_file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void load_database(Db& database, std::string file_name) {
|
||||||
|
std::ifstream db_file(file_name);
|
||||||
|
std::string raw_file_text;
|
||||||
|
db_file >> raw_file_text;
|
||||||
|
db_file.close();
|
||||||
|
database = nlohmann::json::parse(raw_file_text);
|
||||||
|
}
|
||||||
|
|
||||||
void add_entry(Db& database, std::string key, std::string value) {
|
void add_entry(Db& database, std::string key, std::string value) {
|
||||||
database.push_back({key, value});
|
database.push_back({key, value});
|
||||||
}
|
}
|
||||||
|
|
@ -45,6 +53,10 @@ void prompt_user(Db& database) {
|
||||||
std::string file;
|
std::string file;
|
||||||
std::cin >> file;
|
std::cin >> file;
|
||||||
save_database(database, file);
|
save_database(database, file);
|
||||||
|
} else if (mode == "load") {
|
||||||
|
std::string file;
|
||||||
|
std::cin >> file;
|
||||||
|
load_database(database, file);
|
||||||
} else {
|
} else {
|
||||||
prompt_user(database);
|
prompt_user(database);
|
||||||
}
|
}
|
||||||
|
|
@ -53,12 +65,6 @@ void prompt_user(Db& database) {
|
||||||
int main() {
|
int main() {
|
||||||
Db database;
|
Db database;
|
||||||
|
|
||||||
database = {
|
|
||||||
{ "name", "username" },
|
|
||||||
{ "john", "unwanted_guest"},
|
|
||||||
{ "laith", "ducc" }
|
|
||||||
};
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
for (std::vector entry: database) {
|
for (std::vector entry: database) {
|
||||||
std::cout << entry[0] << " | " << entry[1] << std::endl;
|
std::cout << entry[0] << " | " << entry[1] << std::endl;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue