add death date

This commit is contained in:
vrd
2022-09-17 20:44:44 +03:00
parent 1bf0a7f6a4
commit f69d0cbc2f
8 changed files with 43 additions and 28 deletions
+4
View File
@@ -0,0 +1,4 @@
build
.codelite
*.workspace
+2 -1
View File
@@ -1 +1,2 @@
g++ -std=gnu++20 -Ofast -flto -fipa-pta -s -DNDEBUG *.cpp\
g++ -o build/release/famt -std=gnu++20 -Ofast -flto -fipa-pta -fallow-store-data-races -fgcse-sm -fgcse-las -s -DNDEBUG *.cpp
+2 -1
View File
@@ -1 +1,2 @@
g++ -std=gnu++20 -g -Og -Wall *.cpp
g++ -o build/debug/famt -std=gnu++20 -g -Og -Wall *.cpp
+2 -2
View File
@@ -127,11 +127,11 @@ int main()
break;
case 4: //addPerson
std::cin >> name >> day >> month >> year >> sex;
trees[curTree].addPerson(name, BirthTime(year, month, day) , sex);
trees[curTree].addPerson(name, EventTime(year, month, day) , sex);
break;
case 5: //addPersonWP
std::cin >> name >> day >> month >> year >> sex >> father >> mother;
trees[curTree].addPerson(name, BirthTime(year, month, day), sex, father, mother);
trees[curTree].addPerson(name, EventTime(year, month, day), sex, father, mother);
break;
case 6: //addRelation
std::cin >> name >> input >> secondName;
+8 -8
View File
@@ -6,40 +6,40 @@
using std::cout;
BirthTime::BirthTime(U16 Year, U8 Month, U8 Day, U8 Hour, U8 Minute)
EventTime::EventTime(I16 Year, U8 Month, U16 Day, I8 Hour, I8 Minute)
: year(Year)
, month(Month)
, day(Day)
, hour(Hour)
, minute(Minute)
{
assert(month <= 12 && day <= 31 && hour <= 23 && minute <= 59 && "Invalid BirthTime data");
assert(month <= 12 && day <= 31 && hour <= 23 && minute <= 59 && "Invalid EventTime data");
}
void BirthTime::print() const
void EventTime::print() const
{
cout << "Birth: ";
if (day != UNKNOWN)
if (day != UNKNOWN_DATE)
cout << (I32)day;
else
cout << "??";
cout << '.';
if (month != UNKNOWN)
if (month != UNKNOWN_DATE)
cout << (I32)month;
else
cout << "??";
cout << '.';
if (year != UNKNOWN)
cout << (I32)year;
if (year != UNKNOWN_DATE)
cout << year;
else
cout << "????";
cout << '\n';
}
Person::Person(const char* Name, BirthTime Birth, bool IsMale)
Person::Person(const char* Name, EventTime Birth, bool IsMale)
: name(Name)
, numRel(0)
, birth(Birth)
+14 -8
View File
@@ -4,14 +4,19 @@
#include <fstream>
#include "common/basicTypes.h"
struct BirthTime
struct EventTime
{
static const U16 UNKNOWN = 0;
/*explicit*/ BirthTime(U16 Year=UNKNOWN, U8 Month=UNKNOWN, U8 Day=UNKNOWN, U8 Hour=UNKNOWN, U8 Minute=UNKNOWN);
//enum { UNKNOWN_DATE=0, UNKNOWN_TIME=1};
static const I16 UNKNOWN_DATE = 0;
static const I8 UNKNOWN_TIME = -1;
/*explicit*/ EventTime(I16 Year=UNKNOWN_DATE, U8 Month=UNKNOWN_DATE, U16 Day=UNKNOWN_DATE, I8 Hour=UNKNOWN_TIME, I8 Minute=UNKNOWN_TIME);
void print() const;
U16 year;
U8 month, day, hour, minute;
I16 year; //The year in relation to Chritst's birth - 1 (AD) is the year He was born, -1 (BC) is the previous year. There is no year 0
U8 month;
U16 day;
I8 hour; //0-23
I8 minute; //0-59
};
class Person
@@ -19,7 +24,7 @@ class Person
public:
Person() = default;
Person(const char* Name, BirthTime Birth, bool Sex);
Person(const char* Name, EventTime Birth, bool Sex);
bool operator==(const Person &other)const;
@@ -32,7 +37,8 @@ public:
private:
std::string name;
unsigned numRel; //Number of close relatives - mother, father, brother, sister, wife/husband, child, ex-wife/husband
BirthTime birth;
unsigned numRel; //Number of close relatives - mother, father, brother, sister, wife/husband, child, ex-wife/husband
EventTime birth;
bool isMale;
EventTime death;
};
+1 -1
View File
@@ -269,7 +269,7 @@ bool Tree::loadTree()
return 1;
}
void Tree::addPerson(const char *name, BirthTime birth, bool isMale, unsigned father, unsigned mother)
void Tree::addPerson(const char *name, EventTime birth, bool isMale, unsigned father, unsigned mother)
{
Person newPerson(name, birth, isMale);
people.push(newPerson);
+6 -3
View File
@@ -30,8 +30,7 @@ public:
template <class Str>
Tree(Str&& Name) : treeName(std::forward<Str>(Name)), numPeople(0) {}
/*Tree(const Tree&);
Tree& operator= (const Tree& other);
~Tree();*/
Tree& operator= (const Tree& other);*/
Tree operator+ (const Tree& other);
Tree operator- (const Tree& other);
@@ -39,14 +38,18 @@ public:
Tree& operator-= (const Tree& other);
void rename(const char* newName);
unsigned findId(const char*, const short year=0, const unsigned char month=0, const unsigned char day=0)const;
unsigned findOldestAncestor(const unsigned &id, const bool &sex = 0)const;//
unsigned findCommonAncestor(const unsigned firstId, const unsigned secondId)const; //oldest common ancestor ID
void saveTree()const;//
bool loadTree();
void addPerson(const char *name, BirthTime birth, bool isMale, unsigned father = Nobody, unsigned mother = Nobody);
void addPerson(const char *name, EventTime birth, bool isMale, unsigned father = Nobody, unsigned mother = Nobody);
bool addRelation(const char* firstName, const Relation, const char* secondName); //Adds a new relation or edits an old one. 0 - failure 1 - success
bool addRelation(const unsigned firstId, const Relation, const unsigned secondId, bool opposite=0); //0 - failure 1 - success
void removePerson(const unsigned id); //Removes a member and the last one takes his ID
void removePerson(const char*, const short year = 0, const unsigned char month = 0, const unsigned char day = 0);
void removeRelation(const unsigned firstId, const unsigned secondId);