fix save and load

This commit is contained in:
vrd
2023-01-21 19:10:32 +02:00
parent 9434edbe36
commit 5457b171e8
6 changed files with 85 additions and 226 deletions
+3 -6
View File
@@ -62,7 +62,6 @@ void EventTime::print() const
Person::Person(const char* name, EventTime birth, bool isMale, EventTime death)
: name_(name)
, numRel_(0)
, birth_(birth)
, isMale_(isMale)
, death_(death)
@@ -72,24 +71,23 @@ Person::Person(const char* name, EventTime birth, bool isMale, EventTime death)
bool Person::operator==(const Person &other)const
{
return name_ == other.name_ && isMale_ == other.isMale_; //TODO && day == other.day || !day || !other.day) && (month == other.month || !month || !other.month) && (year == other.year || !year || !other.year);
return name_ == other.name_; //&& isMale_ == other.isMale_; //TODO && day == other.day || !day || !other.day) && (month == other.month || !month || !other.month) && (year == other.year || !year || !other.year);
}
void Person::save(std::ofstream &file)const
void Person::write(std::ofstream &file)const
{
//
char nameLen = name_.size();
file.write(reinterpret_cast<char*>(&nameLen), sizeof(nameLen));
file.write(name_.data(), nameLen * sizeof(name_[0]));
file.write(reinterpret_cast<const char*>(&numRel_), sizeof(numRel_));
file.write(reinterpret_cast<const char*>(&isMale_), sizeof(isMale_));
//file.write(reinterpret_cast<const char*>(&day), sizeof(day)); TODO
//file.write(reinterpret_cast<const char*>(&month), sizeof(month));
//file.write(reinterpret_cast<const char*>(&year), sizeof(year));
}
void Person::load(std::ifstream &file)
void Person::read(std::ifstream &file)
{
U8 nameLen;
file.read((char*)&nameLen, sizeof(nameLen)); //Check len
@@ -99,7 +97,6 @@ void Person::load(std::ifstream &file)
nameBuf[nameLen] = '\0';
name_ = nameBuf;
file.read(reinterpret_cast<char*>(&numRel_), sizeof(numRel_));
file.read(reinterpret_cast<char*>(&isMale_), sizeof(isMale_));
//file.read(reinterpret_cast<char*>(&day), sizeof(day)); TODO
//file.read(reinterpret_cast<char*>(&month), sizeof(month));