diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..248ca2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build +.codelite +*.workspace + diff --git a/compile.sh b/compile.sh index 020e9bd..eac8adb 100755 --- a/compile.sh +++ b/compile.sh @@ -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 + diff --git a/compile_debug.sh b/compile_debug.sh index 7f74eb2..2e5dac8 100755 --- a/compile_debug.sh +++ b/compile_debug.sh @@ -1 +1,2 @@ -g++ -std=gnu++20 -g -Og -Wall *.cpp +g++ -o build/debug/famt -std=gnu++20 -g -Og -Wall *.cpp + diff --git a/main.cpp b/main.cpp index 8560b54..ec7b99f 100644 --- a/main.cpp +++ b/main.cpp @@ -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; diff --git a/person.cpp b/person.cpp index 7e3288f..c57d6df 100644 --- a/person.cpp +++ b/person.cpp @@ -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) diff --git a/person.h b/person.h index d2265ee..a5bdfc0 100644 --- a/person.h +++ b/person.h @@ -4,14 +4,19 @@ #include #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; - bool isMale; + unsigned numRel; //Number of close relatives - mother, father, brother, sister, wife/husband, child, ex-wife/husband + EventTime birth; + bool isMale; + EventTime death; }; diff --git a/tree.cpp b/tree.cpp index 37aa3c7..c2873ac 100644 --- a/tree.cpp +++ b/tree.cpp @@ -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); diff --git a/tree.h b/tree.h index ad920d1..b962083 100644 --- a/tree.h +++ b/tree.h @@ -30,23 +30,26 @@ public: template Tree(Str&& Name) : treeName(std::forward(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); Tree& operator+= (const Tree& other); Tree& operator-= (const Tree& other); - void rename(const char* newName); + 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 + 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); + bool loadTree(); + + 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);