diff --git a/ActiveCommand.cpp b/ActiveCommand.cpp index 6a9a96b..021fb42 100644 --- a/ActiveCommand.cpp +++ b/ActiveCommand.cpp @@ -8,7 +8,7 @@ using err::Error; namespace commands { - ActiveCommand::ActiveCommand() : SubCommand("active", 100, false) + ActiveCommand::ActiveCommand() : SubCommand("active", false) { } @@ -19,10 +19,10 @@ namespace commands args >> user_id; if (!user_id) throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); - User* u = mgr.get_user(user_id); + const User* u = mgr.get_user(user_id); if (!u) throw Error(401, "Eine solche BenutzerIn existiert nicht."); - for (Assignment* a : mgr.get_assignments_for_user(user_id)) + for (const Assignment* a : mgr.get_assignments_for_user(user_id)) cout << a->get_task_id() << "\n"; } } // commands diff --git a/AddCommand.cpp b/AddCommand.cpp index db57d8a..6186ce8 100644 --- a/AddCommand.cpp +++ b/AddCommand.cpp @@ -10,7 +10,7 @@ using err::Error; namespace commands { - AddCommand::AddCommand() : SubCommand("add", 100, true) + AddCommand::AddCommand() : SubCommand("add", true) { } diff --git a/AssignCommand.cpp b/AssignCommand.cpp index edc211f..8ac62d2 100644 --- a/AssignCommand.cpp +++ b/AssignCommand.cpp @@ -8,7 +8,7 @@ using err::Error; namespace commands { - AssignCommand::AssignCommand() : SubCommand("assign", 100, true) + AssignCommand::AssignCommand() : SubCommand("assign", true) { } diff --git a/DelCommand.cpp b/DelCommand.cpp index f22e088..9e08e87 100644 --- a/DelCommand.cpp +++ b/DelCommand.cpp @@ -8,7 +8,7 @@ using err::Error; namespace commands { - DelCommand::DelCommand() : SubCommand("delete", 100, true) + DelCommand::DelCommand() : SubCommand("delete", true) { } diff --git a/HelpCommand.cpp b/HelpCommand.cpp index d1a1fda..359bd6d 100644 --- a/HelpCommand.cpp +++ b/HelpCommand.cpp @@ -1,10 +1,10 @@ #include "HelpCommand.h" namespace commands { - HelpCommand::HelpCommand(): SubCommand("help", 100, false) {} + HelpCommand::HelpCommand(): SubCommand("help", false) {} void HelpCommand::run(stringstream& args) { cout << "Projekt 5\n"; cout << "epr24pr5-ojanssen2 \n"; } -} +} // commands diff --git a/ListCommand.cpp b/ListCommand.cpp index 7d88bfc..d389355 100644 --- a/ListCommand.cpp +++ b/ListCommand.cpp @@ -11,7 +11,7 @@ using err::Error; namespace commands { - ListCommand::ListCommand() : SubCommand("list", 100, false) + ListCommand::ListCommand() : SubCommand("list", false) { } diff --git a/Manager.cpp b/Manager.cpp index b107a92..6dc3f2f 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -11,19 +11,18 @@ namespace util Manager::Manager(): users({}), tasks({}), assignments({}), user_id_index(0), task_id_index(0), filename("tasks") { //Open File - ifstream in(this->filename, ios_base::in); + ifstream in = ifstream(this->filename, ios_base::in); if (!in) { this->save(); in.clear(); - in.open(this->filename); + in.open(this->filename, ios_base::in); if (!in) throw Error(601, "Datei kann nicht geƶffnet werden."); } map> buffer; DataType current_type = DataType::INIT; string d; // dump - char c; string line, section; //Parse all Lines until EOF while (getline(in, line)) @@ -118,14 +117,14 @@ namespace util int Manager::get_user_id() { - int value = this->user_id_index; + const int value = this->user_id_index; ++this->user_id_index; return value; } int Manager::get_task_id() { - int value = this->task_id_index; + const int value = this->task_id_index; ++this->task_id_index; return value; } diff --git a/ShowCommand.cpp b/ShowCommand.cpp index 81ae198..2d6e944 100644 --- a/ShowCommand.cpp +++ b/ShowCommand.cpp @@ -12,7 +12,7 @@ using err::Error; namespace commands { - ShowCommand::ShowCommand() : SubCommand("show", 100, false) + ShowCommand::ShowCommand() : SubCommand("show", false) { } diff --git a/SubCommand.cpp b/SubCommand.cpp index be59e54..d99202b 100644 --- a/SubCommand.cpp +++ b/SubCommand.cpp @@ -2,7 +2,7 @@ #include namespace commands { - SubCommand::SubCommand(const string& name, const int& return_value, const bool show_result): name(name), return_value(return_value), show_result(show_result) {} + SubCommand::SubCommand(const string& name, const bool show_result): name(name), show_result(show_result) {} void SubCommand::run(stringstream& args) { cout << "Not impl!\n"; diff --git a/SubCommand.h b/SubCommand.h index b68b5cd..9d0e358 100644 --- a/SubCommand.h +++ b/SubCommand.h @@ -11,11 +11,8 @@ namespace commands string name; bool show_result; - protected: - int return_value; - public: - SubCommand(const string& indicator, const int& value, const bool show_result); + SubCommand(const string& indicator, const bool show_result); string get_name(); int get_value() const; bool should_display_result() const; diff --git a/Task.cpp b/Task.cpp index 47e3734..fbbc498 100644 --- a/Task.cpp +++ b/Task.cpp @@ -18,6 +18,13 @@ namespace models { } + Task::Task(const AddTask& t): id(0), name(t.get_name()), description(t.get_description()), children(t.get_children()) + { + Manager& mgr = Manager::get_instance(); + this->id = mgr.get_task_id(); + } + + ostream& Task::write(ostream& stream) const { stream << *this; @@ -44,9 +51,7 @@ namespace models return this->children; } - AddTask::AddTask(): Task() - { - } + AddTask::AddTask(): Task() {} AddTask::AddTask(Task& t): Task(t) { @@ -104,9 +109,6 @@ namespace models istream& operator>>(istream& is, AddTask& t) { - Manager& mgr = Manager::get_instance(); - int id = mgr.get_task_id(); - try { const string name = Util::read_string_between_percent(is); @@ -114,9 +116,8 @@ namespace models throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); const string description = Util::read_string_between_percent(is); const vector children = Util::read_numbers(is); - Task ft = {id, name, description, children}; - - t = {ft}; + Task at = {0, name, description, children}; + t = at; return is; } catch (Error& err) diff --git a/Task.h b/Task.h index 8fa5963..3637262 100644 --- a/Task.h +++ b/Task.h @@ -6,46 +6,53 @@ using util::Util; -namespace models { - class Task { - private: - int id; - string name; - string description; - vector children; - public: - Task(const int& id, const string& name, const string& description, const vector& children); +namespace models +{ + class AddTask; + class Task + { + private: + int id; + string name; + string description; + vector children; - Task(); + public: + Task(const int& id, const string& name, const string& description, const vector& children); - ostream& write(ostream& stream) const; - istream& read(istream&); + Task(); - int get_id() const; - string get_name() const; - string get_description() const; - vector get_children() const; + explicit Task(const AddTask& t); + + ostream& write(ostream& stream) const; + istream& read(istream&); + + int get_id() const; + string get_name() const; + string get_description() const; + vector get_children() const; - friend ostream& operator<<(ostream& os, const Task& t); - friend istream& operator>>(istream& is, Task& t); + friend ostream& operator<<(ostream& os, const Task& t); + friend istream& operator>>(istream& is, Task& t); }; - class AddTask : public Task{ - private: - public: - AddTask(); - AddTask(Task& t); + class AddTask : public Task + { + private: + public: + AddTask(); + AddTask(Task& t); - friend ostream& operator<<(ostream& os, const AddTask& t); - friend istream& operator>>(istream& is, AddTask& t); + friend ostream& operator<<(ostream& os, const AddTask& t); + friend istream& operator>>(istream& is, AddTask& t); }; + ostream& operator<<(ostream& os, const AddTask& t); istream& operator>>(istream& is, AddTask& t); ostream& operator<<(ostream& os, const Task& t); istream& operator>>(istream& is, Task& t); -} +} // models #endif // TASK_H - diff --git a/UnassignCommand.cpp b/UnassignCommand.cpp index 1d315d8..dc445f0 100644 --- a/UnassignCommand.cpp +++ b/UnassignCommand.cpp @@ -7,7 +7,7 @@ using err::Error; namespace commands { - UnassignCommand::UnassignCommand() : SubCommand("unassign", 100, true) + UnassignCommand::UnassignCommand() : SubCommand("unassign", true) { }