Fix für die ReadNumbers Util

This commit is contained in:
jbrass 2025-02-10 00:00:59 +01:00
parent eab4c106e0
commit 4dde8d2209
2 changed files with 22 additions and 6 deletions

View file

@ -46,10 +46,8 @@ namespace models
return this->description;
}
vector<int> Task::get_children() const
{
return this->children;
}
vector<int> 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<int> children = Util::read_numbers(is);
vector<int> 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<int> children = Util::read_numbers(is);
const vector<int> 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<int> Task::read_children(istream &is) {
vector<int> 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

1
Task.h
View file

@ -31,6 +31,7 @@ namespace models
string get_name() const;
string get_description() const;
vector<int> get_children() const;
static Vector<int> read_children(istream &is);
friend ostream& operator<<(ostream& os, const Task& t);