forked from University/epr24pr5-ojanssen2
44 lines
1 KiB
C++
44 lines
1 KiB
C++
#include "User.h"
|
|
|
|
namespace models {
|
|
User::User(const int& id, const string& name, const string& surname): id(id), name(name), surname(surname) {}
|
|
|
|
User::User(): id(0), name(""), surname("") {}
|
|
|
|
ostream& User::write(ostream& stream) {
|
|
stream << this;
|
|
return stream;
|
|
}
|
|
|
|
int User::get_id() const {
|
|
return this->id;
|
|
}
|
|
|
|
string User::get_name() const {
|
|
return this->name;
|
|
}
|
|
|
|
string User::get_surname() const {
|
|
return this->surname;
|
|
}
|
|
|
|
ostream& operator<<(ostream& os, const User& u)
|
|
{
|
|
os << u.get_id() << " " << u.get_name() << " " << u.get_surname();
|
|
return os;
|
|
}
|
|
|
|
istream& operator>>(istream& is, User& u)
|
|
{
|
|
int id;
|
|
is >> id;
|
|
if (!is)
|
|
throw FormatError("User id NaN.");
|
|
string name, surname;
|
|
is >> name >> surname;
|
|
if (!is)
|
|
throw FormatError("Could not read user name and surname");
|
|
u = {id, name, surname};
|
|
return is;
|
|
}
|
|
}
|