Data can now delete their associated file through deleteObject
This commit is contained in:
parent
cd45dd848f
commit
53ba7c9cc9
@ -18,6 +18,8 @@ public:
|
|||||||
explicit AccountData(const std::string &file, const std::string &name);
|
explicit AccountData(const std::string &file, const std::string &name);
|
||||||
|
|
||||||
Account *getAccount();
|
Account *getAccount();
|
||||||
|
|
||||||
|
using Data<Account>::deleteObject;
|
||||||
private:
|
private:
|
||||||
Account account;
|
Account account;
|
||||||
|
|
||||||
|
@ -24,10 +24,13 @@ public:
|
|||||||
std::string getFilePath();
|
std::string getFilePath();
|
||||||
|
|
||||||
void flushToFile();
|
void flushToFile();
|
||||||
|
|
||||||
|
void deleteObject();
|
||||||
private:
|
private:
|
||||||
const std::string fileName;
|
const std::string fileName;
|
||||||
const std::string homeDirectory = getpwuid(getuid())->pw_dir;
|
const std::string homeDirectory = getpwuid(getuid())->pw_dir;
|
||||||
std::string fileDirectory;
|
std::string fileDirectory;
|
||||||
|
bool flush = true;
|
||||||
|
|
||||||
virtual bool isJsonCorrect() = 0;
|
virtual bool isJsonCorrect() = 0;
|
||||||
};
|
};
|
||||||
|
@ -52,5 +52,13 @@ void Data<T>::flushToFile() {
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Data<T>::~Data() {
|
Data<T>::~Data() {
|
||||||
|
if (flush) {
|
||||||
flushToFile();
|
flushToFile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void Data<T>::deleteObject() {
|
||||||
|
remove(getFilePath().c_str());
|
||||||
|
flush = false;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace Budget;
|
using namespace Budget;
|
||||||
|
|
||||||
@ -56,7 +55,7 @@ int main(int argc, char *argv[]) {
|
|||||||
accountOptHandler.help();
|
accountOptHandler.help();
|
||||||
}
|
}
|
||||||
if (accountOptHandler.getSetOpts()->create) {
|
if (accountOptHandler.getSetOpts()->create) {
|
||||||
AccountData account(storageD + "accounts/" + accountOptHandler.getSetOpts()->createAccount + ".json", accountOptHandler.getSetOpts()->createAccount);
|
accounts.emplace_back(storageD + "accounts/" + accountOptHandler.getSetOpts()->createAccount + ".json", accountOptHandler.getSetOpts()->createAccount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user