diff options
Diffstat (limited to 'core/src/Model/Project.cpp')
-rw-r--r-- | core/src/Model/Project.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/core/src/Model/Project.cpp b/core/src/Model/Project.cpp index e762efb..74e7142 100644 --- a/core/src/Model/Project.cpp +++ b/core/src/Model/Project.cpp @@ -11,7 +11,8 @@ namespace fs = std::filesystem; template <class T> -void ReadItemList(ItemList<T>& list, const fs::path& filePath) { +void ReadItemList(ItemList<T>& list, const fs::path& filePath) +{ std::ifstream ifs(filePath); if (ifs) { Json::Value root; @@ -24,7 +25,8 @@ void ReadItemList(ItemList<T>& list, const fs::path& filePath) { Project::Project(const fs::path& rootPath) : mRootPath{ rootPath } , mRootPathString{ mRootPath.string() } - , mDb(*this) { + , mDb(*this) +{ // TODO better diagnostic const char* kInvalidFormatErr = "Failed to load project: invalid format."; @@ -63,34 +65,42 @@ Project::Project(std::filesystem::path rootPath, std::string name) : mRootPath{ std::move(rootPath) } , mRootPathString{ mRootPath.string() } , mName{ std::move(name) } - , mDb(*this) { + , mDb(*this) +{ } -const fs::path& Project::GetPath() const { +const fs::path& Project::GetPath() const +{ return mRootPath; } -const std::string& Project::GetPathString() const { +const std::string& Project::GetPathString() const +{ return mRootPathString; } -const std::string& Project::GetName() const { +const std::string& Project::GetName() const +{ return mName; } -void Project::SetName(std::string name) { +void Project::SetName(std::string name) +{ mName = std::move(name); } -const TransactionModel& Project::GetTransactionsModel() const { +const TransactionModel& Project::GetTransactionsModel() const +{ return mDb; } -TransactionModel& Project::GetTransactionsModel() { +TransactionModel& Project::GetTransactionsModel() +{ return mDb; } -Json::Value Project::Serialize() { +Json::Value Project::Serialize() +{ Json::Value root(Json::objectValue); root["Name"] = mName; @@ -99,12 +109,14 @@ Json::Value Project::Serialize() { } template <class T> -static void WriteItemList(ItemList<T>& list, const fs::path& filePath) { +static void WriteItemList(ItemList<T>& list, const fs::path& filePath) +{ std::ofstream ofs(filePath); ofs << list.Serialize(); } -void Project::WriteToDisk() { +void Project::WriteToDisk() +{ std::ofstream ofs(mRootPath / "cplt_project.json"); ofs << this->Serialize(); |