diff --git a/Task.cpp b/Task.cpp index 49dd17d..9966e45 100644 --- a/Task.cpp +++ b/Task.cpp @@ -46,10 +46,8 @@ namespace models return this->description; } - vector Task::get_children() const - { - return this->children; - } + vector Task::get_children() const { return this->children; } + AddTask::AddTask(): Task() {} @@ -89,7 +87,7 @@ namespace models if (name.empty()) throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); string description = Util::read_string_between_percent(is); - vector children = Util::read_numbers(is); + vector children = Task::read_children(is); t = {id, name, description, children}; return is; } @@ -115,7 +113,7 @@ namespace models if (name.empty()) 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); + const vector children = Task::read_children(is); Task at = {0, name, description, children}; t = at; return is; @@ -127,4 +125,21 @@ namespace models throw Error(102, "Ein Parameter eines Befehls konnte nicht gelesen werden"); } } + + vector Task::read_children(istream &is) { + vector nums; + int num; + + // Read integers directly from the stream until we hit an error (non-integer or EOF) + while (is >> num) { + nums.push_back(num); + } + // Stream wurde bad durch was anderes als EOF? + if (!is.eof()) { + is.clear(); + throw Error(703, "Could not convert input to integer."); + } + + return nums; + } } // models diff --git a/Task.h b/Task.h index 3637262..24cb492 100644 --- a/Task.h +++ b/Task.h @@ -31,6 +31,7 @@ namespace models string get_name() const; string get_description() const; vector get_children() const; + static Vector read_children(istream &is); friend ostream& operator<<(ostream& os, const Task& t);