line endings

This commit is contained in:
vrd
2022-10-21 20:01:34 +03:00
parent f69d0cbc2f
commit 30e6480343
9 changed files with 699 additions and 683 deletions
+83 -76
View File
@@ -1,11 +1,11 @@
#include <iostream>
#include <assert.h>
#include"person.h"
#include"person.h"
#include "help.h"
using std::cout;
using std::cout;
EventTime::EventTime(I16 Year, U8 Month, U16 Day, I8 Hour, I8 Minute)
: year(Year)
, month(Month)
@@ -18,7 +18,6 @@ EventTime::EventTime(I16 Year, U8 Month, U16 Day, I8 Hour, I8 Minute)
void EventTime::print() const
{
cout << "Birth: ";
if (day != UNKNOWN_DATE)
cout << (I32)day;
else
@@ -37,76 +36,84 @@ void EventTime::print() const
cout << "????";
cout << '\n';
}
Person::Person(const char* Name, EventTime Birth, bool IsMale)
: name(Name)
, numRel(0)
, birth(Birth)
, isMale(IsMale)
{
}
/*Person& Person::operator=(const Person &other)
{
if (&other!=this)
{
rename(other.name);
numRel = other.numRel;
isMale = other.isMale;
day = other.day;
month = other.month;
year = other.year;
}
return *this;
}*/
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);
}
void Person::save(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)
{
char nameLen;
file.read((char*)&nameLen, sizeof(nameLen)); //Check len
C8 nameBuf[128];
file.read(nameBuf, nameLen * sizeof(*nameBuf));
Person::Person(const char* name, EventTime birth, bool isMale, EventTime death)
: name_(name)
, numRel_(0)
, birth_(birth)
, isMale_(isMale)
, death_(death)
{
}
/*Person& Person::operator=(const Person &other)
{
if (&other!=this)
{
rename(other.name);
numRel = other.numRel;
isMale = other.isMale;
day = other.day;
month = other.month;
year = other.year;
}
return *this;
}*/
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);
}
void Person::save(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)
{
char nameLen;
file.read((char*)&nameLen, sizeof(nameLen)); //Check len
C8 nameBuf[128];
file.read(nameBuf, nameLen * sizeof(*nameBuf));
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));
//file.read(reinterpret_cast<char*>(&year), sizeof(year));
}
void Person::rename(const char* newName)
{
name = newName;
}
void Person::print()const
{
std::cout << name << '\n';
birth.print();
std::cout << (isMale ? "Male\n\n" : "Female\n\n");
}
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));
//file.read(reinterpret_cast<char*>(&year), sizeof(year));
}
void Person::rename(const char* newName)
{
name_ = newName;
}
void Person::print()const
{
cout << name_ << '\n';
cout << (isMale_ ? "Male\n" : "Female\n");
cout << "Birth: ";
birth_.print();
cout << "Death: "; //TODO: only print if known
death_.print();
cout << '\n';
}