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);
|
||||
|
||||
Account *getAccount();
|
||||
|
||||
using Data<Account>::deleteObject;
|
||||
private:
|
||||
Account account;
|
||||
|
||||
|
@ -24,10 +24,13 @@ public:
|
||||
std::string getFilePath();
|
||||
|
||||
void flushToFile();
|
||||
|
||||
void deleteObject();
|
||||
private:
|
||||
const std::string fileName;
|
||||
const std::string homeDirectory = getpwuid(getuid())->pw_dir;
|
||||
std::string fileDirectory;
|
||||
bool flush = true;
|
||||
|
||||
virtual bool isJsonCorrect() = 0;
|
||||
};
|
||||
|
@ -52,5 +52,13 @@ void Data<T>::flushToFile() {
|
||||
|
||||
template<class T>
|
||||
Data<T>::~Data() {
|
||||
flushToFile();
|
||||
if (flush) {
|
||||
flushToFile();
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Data<T>::deleteObject() {
|
||||
remove(getFilePath().c_str());
|
||||
flush = false;
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Budget;
|
||||
|
||||
@ -56,7 +55,7 @@ int main(int argc, char *argv[]) {
|
||||
accountOptHandler.help();
|
||||
}
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user