Files
Test/zlecenie.cpp

47 lines
1.2 KiB
C++
Raw Permalink Normal View History

2025-02-19 12:31:48 +01:00
#include "zlecenie.h"
Zlecenie::Zlecenie(int id, std::string nazwa, std::string opis, std::string przypisany)
: id(id), nazwa(nazwa), opis(opis), przypisany(przypisany) {}
int Zlecenie::GetId() const {
return id;
}
std::string Zlecenie::GetNazwa() const {
return nazwa;
}
std::string Zlecenie::GetOpis() const {
return opis;
}
std::string Zlecenie::GetPrzypisany() const {
return przypisany;
}
void Zlecenie::saveToFile(std::ofstream& outFile) const {
outFile << id << '\n';
outFile << nazwa << '\n';
outFile << opis << '\n';
outFile << przypisany << '\n';
}
Zlecenie Zlecenie::loadFromFile(std::ifstream& sourcefile) {
std::string nazwa, opis, przypisany;
int id;
if (!(sourcefile >> id)) {
throw std::runtime_error("Nieudany odczyt ID");
}
sourcefile.ignore(); // Ignoruj znak nowej linii po ID
if (!std::getline(sourcefile, nazwa)) {
throw std::runtime_error("Nieudany odczyt nazwy");
}
if (!std::getline(sourcefile, opis)) {
throw std::runtime_error("Nieudany odczyt opisu");
}
if (!std::getline(sourcefile, przypisany)) {
throw std::runtime_error("Nieudany odczyt przypisanego użytkownika");
}
return Zlecenie(id, nazwa, opis, przypisany);
}