line endings
This commit is contained in:
+4
-1
@@ -1,4 +1,7 @@
|
|||||||
build
|
bin
|
||||||
.codelite
|
.codelite
|
||||||
*.workspace
|
*.workspace
|
||||||
|
GPATH
|
||||||
|
GRTAGS
|
||||||
|
GTAGS
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
g++ -o build/release/famt -std=gnu++20 -Ofast -flto -fipa-pta -fallow-store-data-races -fgcse-sm -fgcse-las -s -DNDEBUG *.cpp
|
g++ -o bin/release/famt -std=gnu++20 -Ofast -flto -fipa-pta -fallow-store-data-races -fgcse-sm -fgcse-las -s -DNDEBUG *.cpp
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
g++ -o build/debug/famt -std=gnu++20 -g -Og -Wall *.cpp
|
g++ -o bin/debug/famt -std=gnu++20 -g -Og -Wall *.cpp -lncursesw
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <ncursesw/ncurses.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
#include "help.h"
|
#include "help.h"
|
||||||
@@ -36,19 +37,23 @@ int main()
|
|||||||
test2.saveTree();*/
|
test2.saveTree();*/
|
||||||
|
|
||||||
Tree firstTree("firstTree");
|
Tree firstTree("firstTree");
|
||||||
firstTree.addPerson("Адам,", {0, 1, 6}, true);
|
|
||||||
firstTree.addPerson("Ева", {0, 1, 6}, false);
|
firstTree.addPerson("Адам,", true, Nobody, Nobody, {0, 1, 6});
|
||||||
|
firstTree.addPerson("Ева", false, Nobody, Nobody, {0, 1, 6});
|
||||||
firstTree.addRelation(0, Husband, 1);
|
firstTree.addRelation(0, Husband, 1);
|
||||||
|
|
||||||
firstTree.addPerson("Кайн", {}, true, 0, 1);
|
firstTree.addPerson("Кайн", true, 0, 1);
|
||||||
firstTree.addPerson("Авел", {}, true, 0, 1);
|
firstTree.addPerson("Авел", true, 0, 1);
|
||||||
firstTree.addPerson("Сит", 230, true, 0, 1);
|
firstTree.addPerson("Сит", true, 0, 1, 230);
|
||||||
firstTree.addRelation(2, Brother, 3);
|
firstTree.addRelation(2, Brother, 3);
|
||||||
firstTree.addRelation(2, Brother, 4);
|
firstTree.addRelation(2, Brother, 4);
|
||||||
|
|
||||||
firstTree.print();
|
firstTree.print();
|
||||||
firstTree.saveTree();
|
firstTree.saveTree();
|
||||||
|
|
||||||
|
firstTree.printRel(3);
|
||||||
|
firstTree.printOldestAncestors(3);
|
||||||
|
|
||||||
|
|
||||||
Array<Tree> trees;
|
Array<Tree> trees;
|
||||||
|
|
||||||
@@ -127,11 +132,11 @@ int main()
|
|||||||
break;
|
break;
|
||||||
case 4: //addPerson
|
case 4: //addPerson
|
||||||
std::cin >> name >> day >> month >> year >> sex;
|
std::cin >> name >> day >> month >> year >> sex;
|
||||||
trees[curTree].addPerson(name, EventTime(year, month, day) , sex);
|
trees[curTree].addPerson(name, sex, Nobody, Nobody, EventTime(year, month, day));
|
||||||
break;
|
break;
|
||||||
case 5: //addPersonWP
|
case 5: //addPersonWP
|
||||||
std::cin >> name >> day >> month >> year >> sex >> father >> mother;
|
std::cin >> name >> day >> month >> year >> sex >> father >> mother;
|
||||||
trees[curTree].addPerson(name, EventTime(year, month, day), sex, father, mother);
|
trees[curTree].addPerson(name, sex, father, mother, EventTime(year, month, day));
|
||||||
break;
|
break;
|
||||||
case 6: //addRelation
|
case 6: //addRelation
|
||||||
std::cin >> name >> input >> secondName;
|
std::cin >> name >> input >> secondName;
|
||||||
|
|||||||
+25
-18
@@ -18,7 +18,6 @@ EventTime::EventTime(I16 Year, U8 Month, U16 Day, I8 Hour, I8 Minute)
|
|||||||
|
|
||||||
void EventTime::print() const
|
void EventTime::print() const
|
||||||
{
|
{
|
||||||
cout << "Birth: ";
|
|
||||||
if (day != UNKNOWN_DATE)
|
if (day != UNKNOWN_DATE)
|
||||||
cout << (I32)day;
|
cout << (I32)day;
|
||||||
else
|
else
|
||||||
@@ -39,11 +38,12 @@ void EventTime::print() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Person::Person(const char* Name, EventTime Birth, bool IsMale)
|
Person::Person(const char* name, EventTime birth, bool isMale, EventTime death)
|
||||||
: name(Name)
|
: name_(name)
|
||||||
, numRel(0)
|
, numRel_(0)
|
||||||
, birth(Birth)
|
, birth_(birth)
|
||||||
, isMale(IsMale)
|
, isMale_(isMale)
|
||||||
|
, death_(death)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,18 +65,18 @@ Person::Person(const char* Name, EventTime Birth, bool IsMale)
|
|||||||
|
|
||||||
bool Person::operator==(const Person &other)const
|
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::save(std::ofstream &file)const
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
char nameLen = name.size();
|
char nameLen = name_.size();
|
||||||
file.write(reinterpret_cast<char*>(&nameLen), sizeof(nameLen));
|
file.write(reinterpret_cast<char*>(&nameLen), sizeof(nameLen));
|
||||||
file.write(name.data(), nameLen * sizeof(name[0]));
|
file.write(name_.data(), nameLen * sizeof(name_[0]));
|
||||||
file.write(reinterpret_cast<const char*>(&numRel), sizeof(numRel));
|
file.write(reinterpret_cast<const char*>(&numRel_), sizeof(numRel_));
|
||||||
file.write(reinterpret_cast<const char*>(&isMale), sizeof(isMale));
|
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*>(&day), sizeof(day)); TODO
|
||||||
//file.write(reinterpret_cast<const char*>(&month), sizeof(month));
|
//file.write(reinterpret_cast<const char*>(&month), sizeof(month));
|
||||||
//file.write(reinterpret_cast<const char*>(&year), sizeof(year));
|
//file.write(reinterpret_cast<const char*>(&year), sizeof(year));
|
||||||
@@ -90,10 +90,10 @@ void Person::load(std::ifstream &file)
|
|||||||
C8 nameBuf[128];
|
C8 nameBuf[128];
|
||||||
file.read(nameBuf, nameLen * sizeof(*nameBuf));
|
file.read(nameBuf, nameLen * sizeof(*nameBuf));
|
||||||
nameBuf[nameLen] = '\0';
|
nameBuf[nameLen] = '\0';
|
||||||
name = nameBuf;
|
name_ = nameBuf;
|
||||||
|
|
||||||
file.read(reinterpret_cast<char*>(&numRel), sizeof(numRel));
|
file.read(reinterpret_cast<char*>(&numRel_), sizeof(numRel_));
|
||||||
file.read(reinterpret_cast<char*>(&isMale), sizeof(isMale));
|
file.read(reinterpret_cast<char*>(&isMale_), sizeof(isMale_));
|
||||||
//file.read(reinterpret_cast<char*>(&day), sizeof(day)); TODO
|
//file.read(reinterpret_cast<char*>(&day), sizeof(day)); TODO
|
||||||
//file.read(reinterpret_cast<char*>(&month), sizeof(month));
|
//file.read(reinterpret_cast<char*>(&month), sizeof(month));
|
||||||
//file.read(reinterpret_cast<char*>(&year), sizeof(year));
|
//file.read(reinterpret_cast<char*>(&year), sizeof(year));
|
||||||
@@ -101,12 +101,19 @@ void Person::load(std::ifstream &file)
|
|||||||
|
|
||||||
void Person::rename(const char* newName)
|
void Person::rename(const char* newName)
|
||||||
{
|
{
|
||||||
name = newName;
|
name_ = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Person::print()const
|
void Person::print()const
|
||||||
{
|
{
|
||||||
std::cout << name << '\n';
|
cout << name_ << '\n';
|
||||||
birth.print();
|
cout << (isMale_ ? "Male\n" : "Female\n");
|
||||||
std::cout << (isMale ? "Male\n\n" : "Female\n\n");
|
|
||||||
|
cout << "Birth: ";
|
||||||
|
birth_.print();
|
||||||
|
|
||||||
|
cout << "Death: "; //TODO: only print if known
|
||||||
|
death_.print();
|
||||||
|
|
||||||
|
cout << '\n';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class Person
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Person() = default;
|
Person() = default;
|
||||||
Person(const char* Name, EventTime Birth, bool Sex);
|
Person(const char* name, EventTime birth, bool sex, EventTime death);
|
||||||
|
|
||||||
bool operator==(const Person &other)const;
|
bool operator==(const Person &other)const;
|
||||||
|
|
||||||
@@ -36,9 +36,9 @@ public:
|
|||||||
friend class Tree;
|
friend class Tree;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name;
|
std::string name_;
|
||||||
unsigned numRel; //Number of close relatives - mother, father, brother, sister, wife/husband, child, ex-wife/husband
|
unsigned numRel_; //Number of close relatives - mother, father, brother, sister, wife/husband, child, ex-wife/husband
|
||||||
EventTime birth;
|
EventTime birth_;
|
||||||
bool isMale;
|
bool isMale_;
|
||||||
EventTime death;
|
EventTime death_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,14 +55,14 @@ Tree Tree::operator+ (const Tree& other)//
|
|||||||
}
|
}
|
||||||
else //If he's found in both
|
else //If he's found in both
|
||||||
{
|
{
|
||||||
for (unsigned j = 0; j < other.people[i].numRel; ++j) //Adds the number of relatives from the II to the number in the I
|
for (unsigned j = 0; j < other.people[i].numRel_; ++j) //Adds the number of relatives from the II to the number in the I
|
||||||
{
|
{
|
||||||
if(newId[other.relatives[i][j]] > numPeople)
|
if(newId[other.relatives[i][j]] > numPeople)
|
||||||
++result.people[newId[i]].numRel;
|
++result.people[newId[i]].numRel_;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.relatives[newId[i]].resize(result.people[newId[i]].numRel);
|
result.relatives[newId[i]].resize(result.people[newId[i]].numRel_);
|
||||||
result.relations[newId[i]].resize(result.people[newId[i]].numRel);
|
result.relations[newId[i]].resize(result.people[newId[i]].numRel_);
|
||||||
|
|
||||||
result.relatives[newId[i]] = relatives[newId[i]];
|
result.relatives[newId[i]] = relatives[newId[i]];
|
||||||
result.relations[newId[i]] = relations[newId[i]];
|
result.relations[newId[i]] = relations[newId[i]];
|
||||||
@@ -108,23 +108,23 @@ Tree& Tree::operator+=(const Tree& other)
|
|||||||
if (newId[i] >= numPeople)
|
if (newId[i] >= numPeople)
|
||||||
{
|
{
|
||||||
relatives.push(other.relatives[i]);
|
relatives.push(other.relatives[i]);
|
||||||
for (unsigned j = 0; j < other.people[i].numRel; ++j)
|
for (unsigned j = 0; j < other.people[i].numRel_; ++j)
|
||||||
relatives[newId[i]][j] = newId[ relatives[newId[i]][j] ];
|
relatives[newId[i]][j] = newId[ relatives[newId[i]][j] ];
|
||||||
relations.push(other.relations[i]);
|
relations.push(other.relations[i]);
|
||||||
}
|
}
|
||||||
else //If the member is present in both trees
|
else //If the member is present in both trees
|
||||||
{
|
{
|
||||||
for (unsigned j = 0; j < other.people[i].numRel; ++j) //Adds the number of relatives from the II to the number in the I
|
for (unsigned j = 0; j < other.people[i].numRel_; ++j) //Adds the number of relatives from the II to the number in the I
|
||||||
{
|
{
|
||||||
if (newId[other.relatives[i][j]] >= numPeople)
|
if (newId[other.relatives[i][j]] >= numPeople)
|
||||||
++people[newId[i]].numRel;
|
++people[newId[i]].numRel_;
|
||||||
}
|
}
|
||||||
relatives[newId[i]].resize(people[newId[i]].numRel);
|
relatives[newId[i]].resize(people[newId[i]].numRel_);
|
||||||
relations[newId[i]].resize(people[newId[i]].numRel);
|
relations[newId[i]].resize(people[newId[i]].numRel_);
|
||||||
for (unsigned j = 0; j < other.people[i].numRel; ++j)
|
for (unsigned j = 0; j < other.people[i].numRel_; ++j)
|
||||||
{
|
{
|
||||||
relatives[newId[i]][j + people[newId[i]].numRel - other.people[i].numRel] = newId[other.relatives[i][j]];
|
relatives[newId[i]][j + people[newId[i]].numRel_ - other.people[i].numRel_] = newId[other.relatives[i][j]];
|
||||||
relations[newId[i]][j + people[newId[i]].numRel - other.people[i].numRel] = other.relations[i][j];
|
relations[newId[i]][j + people[newId[i]].numRel_ - other.people[i].numRel_] = other.relations[i][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ unsigned Tree::findId(const char* name, const short year, const unsigned char mo
|
|||||||
//Person sought(name, day, month, year,)
|
//Person sought(name, day, month, year,)
|
||||||
for (unsigned i = 0; i < numPeople; ++i)
|
for (unsigned i = 0; i < numPeople; ++i)
|
||||||
{
|
{
|
||||||
if (name == people[i].name) //&& (year == people[i].year || !year || !people[i].year) && (month == people[i].month || !month || !people[i].month) && (day == people[i].day || !day || people[i].day))
|
if (name == people[i].name_) //&& (year == people[i].year || !year || !people[i].year) && (month == people[i].month || !month || !people[i].month) && (day == people[i].day || !day || people[i].day))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return Nobody;
|
return Nobody;
|
||||||
@@ -172,9 +172,9 @@ unsigned Tree::findId(const char* name, const short year, const unsigned char mo
|
|||||||
|
|
||||||
unsigned Tree::findOldestAncestor(const unsigned &id, const bool &isMale)const
|
unsigned Tree::findOldestAncestor(const unsigned &id, const bool &isMale)const
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < people[id].numRel; ++i)
|
for (unsigned i = 0; i < people[id].numRel_; ++i)
|
||||||
{
|
{
|
||||||
if (relations[id][i] == Son && people[ relatives[id][i] ].isMale == isMale)
|
if (relations[id][i] == Son && people[ relatives[id][i] ].isMale_ == isMale)
|
||||||
return findOldestAncestor(relatives[id][i], isMale);
|
return findOldestAncestor(relatives[id][i], isMale);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
@@ -192,9 +192,9 @@ unsigned Tree::findCommonAncestor(const unsigned firstId, const unsigned secondI
|
|||||||
U16 oldestBday = SHRT_MAX;
|
U16 oldestBday = SHRT_MAX;
|
||||||
for (unsigned i = 0; i < numPeople; ++i)
|
for (unsigned i = 0; i < numPeople; ++i)
|
||||||
{
|
{
|
||||||
if (visited[i] == 2 && people[i].birth.year<oldestBday)
|
if (visited[i] == 2 && people[i].birth_.year < oldestBday)
|
||||||
{
|
{
|
||||||
oldestBday = people[i].birth.year;
|
oldestBday = people[i].birth_.year;
|
||||||
oldestId = i;
|
oldestId = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,12 +217,12 @@ void Tree::saveTree() const
|
|||||||
relationFile.write((char*)&numPeople, sizeof(numPeople));*/
|
relationFile.write((char*)&numPeople, sizeof(numPeople));*/
|
||||||
for (unsigned i = 0; i < numPeople; ++i)
|
for (unsigned i = 0; i < numPeople; ++i)
|
||||||
{
|
{
|
||||||
//relativeFile.write((char*)&people[i].numRel, sizeof(people[i].numRel));
|
//relativeFile.write((char*)&people[i].numRel_, sizeof(people[i].numRel_));
|
||||||
for (unsigned j = 0; j < people[i].numRel; ++j)
|
for (unsigned j = 0; j < people[i].numRel_; ++j)
|
||||||
relativeFile.write(reinterpret_cast<char*>(&relatives[i][j]), sizeof(relatives[i][j]));
|
relativeFile.write(reinterpret_cast<char*>(&relatives[i][j]), sizeof(relatives[i][j]));
|
||||||
|
|
||||||
//relationFile.write((char*)&people[i].numRel, sizeof(people[i].numRel));
|
//relationFile.write((char*)&people[i].numRel_, sizeof(people[i].numRel_));
|
||||||
for (unsigned j = 0; j < people[i].numRel; ++j)
|
for (unsigned j = 0; j < people[i].numRel_; ++j)
|
||||||
relationFile.write(reinterpret_cast<char*>(&relations[i][j]), sizeof(relations[i][j]));
|
relationFile.write(reinterpret_cast<char*>(&relations[i][j]), sizeof(relations[i][j]));
|
||||||
}
|
}
|
||||||
relativeFile.close();
|
relativeFile.close();
|
||||||
@@ -252,15 +252,15 @@ bool Tree::loadTree()
|
|||||||
relations.resize(numPeople);
|
relations.resize(numPeople);
|
||||||
for (unsigned i = 0; i < numPeople; ++i)
|
for (unsigned i = 0; i < numPeople; ++i)
|
||||||
{
|
{
|
||||||
relatives[i].resize(people[i].numRel);
|
relatives[i].resize(people[i].numRel_);
|
||||||
for (unsigned j = 0; j < people[i].numRel; ++j)
|
for (unsigned j = 0; j < people[i].numRel_; ++j)
|
||||||
relativeFile.read(reinterpret_cast<char*>(&relatives[i][j]), sizeof(relatives[i][j]));
|
relativeFile.read(reinterpret_cast<char*>(&relatives[i][j]), sizeof(relatives[i][j]));
|
||||||
relatives[i].sNum(people[i].numRel);
|
relatives[i].sNum(people[i].numRel_);
|
||||||
|
|
||||||
relations[i].resize(people[i].numRel);
|
relations[i].resize(people[i].numRel_);
|
||||||
for (unsigned j = 0; j < people[i].numRel; ++j)
|
for (unsigned j = 0; j < people[i].numRel_; ++j)
|
||||||
relationFile.read(reinterpret_cast<char*>(&relations[i][j]), sizeof(relations[i][j]));
|
relationFile.read(reinterpret_cast<char*>(&relations[i][j]), sizeof(relations[i][j]));
|
||||||
relations[i].sNum(people[i].numRel);
|
relations[i].sNum(people[i].numRel_);
|
||||||
}
|
}
|
||||||
relatives.sNum(numPeople);
|
relatives.sNum(numPeople);
|
||||||
relations.sNum(numPeople);
|
relations.sNum(numPeople);
|
||||||
@@ -269,9 +269,9 @@ bool Tree::loadTree()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tree::addPerson(const char *name, EventTime birth, bool isMale, unsigned father, unsigned mother)
|
void Tree::addPerson(const char* name, bool isMale, unsigned father, unsigned mother, EventTime birth, EventTime death)
|
||||||
{
|
{
|
||||||
Person newPerson(name, birth, isMale);
|
Person newPerson(name, birth, isMale, death);
|
||||||
people.push(newPerson);
|
people.push(newPerson);
|
||||||
Array<unsigned> newRelative;
|
Array<unsigned> newRelative;
|
||||||
relatives.push(newRelative);
|
relatives.push(newRelative);
|
||||||
@@ -294,7 +294,7 @@ bool Tree::addRelation(const unsigned firstId, const Relation type, const unsign
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
for (; i < people[firstId].numRel; ++i) //If they are already relatives
|
for (; i < people[firstId].numRel_; ++i) //If they are already relatives
|
||||||
{
|
{
|
||||||
if (relatives[firstId][i] == secondId)
|
if (relatives[firstId][i] == secondId)
|
||||||
{
|
{
|
||||||
@@ -302,16 +302,16 @@ bool Tree::addRelation(const unsigned firstId, const Relation type, const unsign
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i >= people[firstId].numRel)
|
if (i >= people[firstId].numRel_)
|
||||||
{
|
{
|
||||||
relatives[firstId].push(secondId);
|
relatives[firstId].push(secondId);
|
||||||
relations[firstId].push(type);
|
relations[firstId].push(type);
|
||||||
++people[firstId].numRel;
|
++people[firstId].numRel_;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opposite)
|
if (!opposite)
|
||||||
{
|
{
|
||||||
if (people[secondId].isMale)
|
if (people[secondId].isMale_)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@@ -379,10 +379,10 @@ void Tree::removeRelation(const char* firstName, const char* secondName)
|
|||||||
void Tree::removePerson(const unsigned id)
|
void Tree::removePerson(const unsigned id)
|
||||||
{
|
{
|
||||||
unsigned relId; //Íoìåð íà òåêóùèÿ ðîäíèíàòà
|
unsigned relId; //Íoìåð íà òåêóùèÿ ðîäíèíàòà
|
||||||
for (unsigned i = 0; i < people[id].numRel; ++i) //Ïðåìàõâàò ñå âðúçêèòå íà ÷ëåíà çà ïðåìàõâàíå
|
for (unsigned i = 0; i < people[id].numRel_; ++i) //Ïðåìàõâàò ñå âðúçêèòå íà ÷ëåíà çà ïðåìàõâàíå
|
||||||
{
|
{
|
||||||
relId = relatives[id][i];
|
relId = relatives[id][i];
|
||||||
for (unsigned j = 0; j < people[relId].numRel; ++j)
|
for (unsigned j = 0; j < people[relId].numRel_; ++j)
|
||||||
{
|
{
|
||||||
if (relatives[relId][j] == id)
|
if (relatives[relId][j] == id)
|
||||||
{
|
{
|
||||||
@@ -391,12 +391,12 @@ void Tree::removePerson(const unsigned id)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
--people[relId].numRel;
|
--people[relId].numRel_;
|
||||||
}
|
}
|
||||||
for (unsigned i = 0; i < people[numPeople - 2].numRel; ++i) //Ïîñëåäíèÿò ÷ëåí âçåìà íîìåðà íà ïðåìàõíàòèÿ
|
for (unsigned i = 0; i < people[numPeople - 2].numRel_; ++i) //Ïîñëåäíèÿò ÷ëåí âçåìà íîìåðà íà ïðåìàõíàòèÿ
|
||||||
{
|
{
|
||||||
relId = relatives[numPeople - 1][i];
|
relId = relatives[numPeople - 1][i];
|
||||||
for (unsigned j = 0; j < people[relId].numRel; ++j)
|
for (unsigned j = 0; j < people[relId].numRel_; ++j)
|
||||||
{
|
{
|
||||||
if (relatives[relId][j] == numPeople - 1)
|
if (relatives[relId][j] == numPeople - 1)
|
||||||
{
|
{
|
||||||
@@ -418,23 +418,23 @@ void Tree::removePerson(const char* personName, const short year, const unsigned
|
|||||||
|
|
||||||
void Tree::removeRelation(const unsigned firstId, const unsigned secondId)
|
void Tree::removeRelation(const unsigned firstId, const unsigned secondId)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < people[firstId].numRel; ++i)
|
for (unsigned i = 0; i < people[firstId].numRel_; ++i)
|
||||||
{
|
{
|
||||||
if (relatives[firstId][i] == secondId)
|
if (relatives[firstId][i] == secondId)
|
||||||
{
|
{
|
||||||
relatives[firstId].remove(i);
|
relatives[firstId].remove(i);
|
||||||
relations[firstId].remove(i);
|
relations[firstId].remove(i);
|
||||||
--people[firstId].numRel;
|
--people[firstId].numRel_;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (unsigned i = 0; i < people[secondId].numRel; ++i)
|
for (unsigned i = 0; i < people[secondId].numRel_; ++i)
|
||||||
{
|
{
|
||||||
if (relatives[secondId][i] == firstId)
|
if (relatives[secondId][i] == firstId)
|
||||||
{
|
{
|
||||||
relatives[secondId].remove(i);
|
relatives[secondId].remove(i);
|
||||||
relations[secondId].remove(i);
|
relations[secondId].remove(i);
|
||||||
--people[secondId].numRel;
|
--people[secondId].numRel_;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,52 +451,53 @@ void Tree::print() const
|
|||||||
|
|
||||||
void Tree::printRel(const unsigned id)const
|
void Tree::printRel(const unsigned id)const
|
||||||
{
|
{
|
||||||
if (people[id].numRel == 0)
|
cout << people[id].name_;
|
||||||
|
if (people[id].numRel_ == 0)
|
||||||
|
cout << " has no known relatives";
|
||||||
|
else
|
||||||
{
|
{
|
||||||
std::cout << "No relatives";
|
unsigned relId;
|
||||||
return;
|
cout << "'s relatives:\n";
|
||||||
}
|
for (unsigned i = 0; i < people[id].numRel_; ++i)
|
||||||
|
|
||||||
unsigned relId;
|
|
||||||
std::cout <<people[id].name<< "'s relatives:\n";
|
|
||||||
for (unsigned i = 0; i < people[id].numRel; ++i)
|
|
||||||
{
|
|
||||||
relId = relatives[id][i];
|
|
||||||
std::cout << people[relId].name << " - ";
|
|
||||||
|
|
||||||
switch (relations[id][i])
|
|
||||||
{
|
{
|
||||||
case Father:
|
relId = relatives[id][i];
|
||||||
case Mother:
|
cout << people[relId].name_ << " - ";
|
||||||
std::cout << (people[relId].isMale ? "son" : "daughter");
|
|
||||||
break;
|
switch (relations[id][i])
|
||||||
case Son:
|
{
|
||||||
case Daughter:
|
case Father:
|
||||||
std::cout << (people[relId].isMale ? "father" : "mother");
|
case Mother:
|
||||||
break;
|
cout << (people[relId].isMale_ ? "son" : "daughter");
|
||||||
case Brother:
|
break;
|
||||||
case Sister:
|
case Son:
|
||||||
std::cout << (people[relId].isMale ? "brother" : "sister");
|
case Daughter:
|
||||||
break;
|
cout << (people[relId].isMale_ ? "father" : "mother");
|
||||||
case HalfBrother:
|
break;
|
||||||
case HalfSister:
|
case Brother:
|
||||||
std::cout << (people[relId].isMale ? "half brother" : "half sister");
|
case Sister:
|
||||||
break;
|
cout << (people[relId].isMale_ ? "brother" : "sister");
|
||||||
case Husband:
|
break;
|
||||||
std::cout << "wife";
|
case HalfBrother:
|
||||||
break;
|
case HalfSister:
|
||||||
case Wife:
|
cout << (people[relId].isMale_ ? "half brother" : "half sister");
|
||||||
std::cout << "husband";
|
break;
|
||||||
break;
|
case Husband:
|
||||||
case ExHusband:
|
cout << "wife";
|
||||||
std::cout << "ex-wife\n";
|
break;
|
||||||
break;
|
case Wife:
|
||||||
case ExWife:
|
cout << "husband";
|
||||||
std::cout << "ex-husband\n";
|
break;
|
||||||
break;
|
case ExHusband:
|
||||||
|
cout << "ex-wife\n";
|
||||||
|
break;
|
||||||
|
case ExWife:
|
||||||
|
cout << "ex-husband\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cout << '\n';
|
||||||
}
|
}
|
||||||
|
cout << '\n';
|
||||||
}
|
}
|
||||||
std::cout << "\n\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tree::printMember(const unsigned id)const
|
void Tree::printMember(const unsigned id)const
|
||||||
@@ -521,7 +522,7 @@ unsigned Tree::gNumP()const
|
|||||||
|
|
||||||
void Tree::commonAncestorRec(const unsigned &id, const Array<char> &visited)const
|
void Tree::commonAncestorRec(const unsigned &id, const Array<char> &visited)const
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < people[id].numRel; ++i)
|
for (unsigned i = 0; i < people[id].numRel_; ++i)
|
||||||
{
|
{
|
||||||
if (relations[id][i] == Son)
|
if (relations[id][i] == Son)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public:
|
|||||||
void saveTree()const;//
|
void saveTree()const;//
|
||||||
bool loadTree();
|
bool loadTree();
|
||||||
|
|
||||||
void addPerson(const char *name, EventTime birth, bool isMale, unsigned father = Nobody, unsigned mother = Nobody);
|
void addPerson(const char* name, bool isMale, unsigned father=Nobody, unsigned mother=Nobody, EventTime birth={}, EventTime death={});
|
||||||
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 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
|
bool addRelation(const unsigned firstId, const Relation, const unsigned secondId, bool opposite=0); //0 - failure 1 - success
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user