forked from University/epr24pr5-ojanssen2
Fix für die ReadNumbers Util
This commit is contained in:
parent
eab4c106e0
commit
4dde8d2209
2 changed files with 22 additions and 6 deletions
27
Task.cpp
27
Task.cpp
|
@ -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
1
Task.h
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue