forked from University/epr24pr5-ojanssen2
fix: fixed issues with Task in & output
This commit is contained in:
parent
12a6ef8adb
commit
f803d604a0
1 changed files with 49 additions and 19 deletions
66
Task.cpp
66
Task.cpp
|
@ -7,10 +7,16 @@ using err::Error;
|
||||||
using util::Util;
|
using util::Util;
|
||||||
using util::Manager;
|
using util::Manager;
|
||||||
|
|
||||||
namespace models {
|
namespace models
|
||||||
Task::Task(const int& id, const string& name, const string& description, const vector<int>& children): id(id), name(name), description(description), children(children) {}
|
{
|
||||||
|
Task::Task(const int& id, const string& name, const string& description, const vector<int>& children):
|
||||||
|
id(id), name(name), description(description), children(children)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Task::Task(): id(0), name(""), description(""), children({}) {}
|
Task::Task(): id(0), name(""), description(""), children({})
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ostream& Task::write(ostream& stream) const
|
ostream& Task::write(ostream& stream) const
|
||||||
{
|
{
|
||||||
|
@ -18,65 +24,89 @@ namespace models {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Task::get_id() const {
|
int Task::get_id() const
|
||||||
|
{
|
||||||
return this->id;
|
return this->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Task::get_name() const {
|
string Task::get_name() const
|
||||||
|
{
|
||||||
return this->name;
|
return this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Task::get_description() const {
|
string Task::get_description() const
|
||||||
|
{
|
||||||
return this->description;
|
return this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int> Task::get_children() const {
|
vector<int> Task::get_children() const
|
||||||
|
{
|
||||||
return this->children;
|
return this->children;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddTask::AddTask(): Task() {}
|
AddTask::AddTask(): Task()
|
||||||
AddTask::AddTask(Task& t): Task(t) {}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
ostream& operator<<(ostream& os, const Task& t) {
|
AddTask::AddTask(Task& t): Task(t)
|
||||||
os << t.get_id() << " %" << t.get_name() << "% %" << t.get_description() << "%\n";
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& os, const Task& t)
|
||||||
|
{
|
||||||
|
os << t.get_id() << " %" << t.get_name() << "% %" << t.get_description();
|
||||||
|
for (const int id : t.children)
|
||||||
|
os << " " << id << " ";
|
||||||
|
os << "\n";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
istream& operator>>(istream& is, Task& t) {
|
istream& operator>>(istream& is, Task& t)
|
||||||
|
{
|
||||||
int id;
|
int id;
|
||||||
is >> id;
|
is >> id;
|
||||||
if (!is)
|
if (!is)
|
||||||
throw Error(602, "Datei hat ein unbekanntes Format.");
|
throw Error(602, "Datei hat ein unbekanntes Format.");
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
string name = Util::read_string_between_percent(is);
|
string name = Util::read_string_between_percent(is);
|
||||||
string description = Util::read_string_between_percent(is);
|
string description = Util::read_string_between_percent(is);
|
||||||
vector<int> children = Util::read_numbers(is);
|
vector<int> children = Util::read_numbers(is);
|
||||||
t = {id, name, description, children};
|
t = {id, name, description, children};
|
||||||
return is;
|
return is;
|
||||||
} catch (Error& _) {
|
}
|
||||||
|
catch (Error& _)
|
||||||
|
{
|
||||||
throw Error(602, "Datei hat ein unbekanntes Format.");
|
throw Error(602, "Datei hat ein unbekanntes Format.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream& operator<<(ostream& os, const AddTask& t) {
|
ostream& operator<<(ostream& os, const AddTask& t)
|
||||||
|
{
|
||||||
os << t.get_name() << " " << t.get_description() << "\n";
|
os << t.get_name() << " " << t.get_description() << "\n";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
istream& operator>>(istream& is, AddTask& t) {
|
istream& operator>>(istream& is, AddTask& t)
|
||||||
|
{
|
||||||
Manager& mgr = Manager::get_instance();
|
Manager& mgr = Manager::get_instance();
|
||||||
int id = mgr.get_task_id();
|
int id = mgr.get_task_id();
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
const string name = Util::read_string_between_percent(is);
|
const string name = Util::read_string_between_percent(is);
|
||||||
|
if (name == "")
|
||||||
|
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
|
||||||
const string description = Util::read_string_between_percent(is);
|
const string description = Util::read_string_between_percent(is);
|
||||||
const vector<int> children = Util::read_numbers(is);
|
const vector<int> children = Util::read_numbers(is);
|
||||||
Task ft = {id, name, description, children};
|
Task ft = {id, name, description, children};
|
||||||
|
|
||||||
t = {ft};
|
t = {ft};
|
||||||
return is;
|
return is;
|
||||||
} catch (Error& _) {
|
}
|
||||||
|
catch (Error& _)
|
||||||
|
{
|
||||||
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
|
throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue