relation relative merge

This commit is contained in:
vrd
2022-12-28 14:19:44 +02:00
parent cc9b0ccc21
commit b3a2787fcd
6 changed files with 203 additions and 170 deletions
+68 -61
View File
@@ -4,7 +4,74 @@
#include "array.h"
#include "person.h"
enum Relation : U8
using person_id = U32;
enum RelType : U8;
struct Relation
{
person_id id;
RelType type;
};
static constexpr person_id Nobody = UINT_MAX;
class Tree
{
public:
Tree() = default;
template <class Str>
Tree(Str&& Name) : treeName(std::forward<Str>(Name)) {}
/*Tree(const Tree&);
Tree& operator= (const Tree& other);*/
Tree operator+ (const Tree& other);//doesnt work
Tree operator- (const Tree& other);
Tree& operator+= (const Tree& other);
Tree& operator-= (const Tree& other);
void rename(const char* newName);
person_id findId(const char*, short year=0, const unsigned char month=0, const unsigned char day=0)const;
person_id findOldestAncestor(person_id id, bool sex = 0)const;//
person_id findCommonAncestor(person_id firstId, person_id secondId)const; //oldest common ancestor ID
void saveTree()const;//
bool loadTree();
void addPerson(const char* name, bool isMale, person_id father=Nobody, person_id mother=Nobody, EventTime birth={}, EventTime death={});
bool addRelation(const char* firstName, RelType, const char* secondName); //Adds a new relation or edits an old one. 0 - failure 1 - success
bool addRelation(person_id firstId, RelType, person_id secondId, bool opposite=0); //0 - failure 1 - success
void removePerson(person_id id); //Removes a member and the last one takes his ID
void removePerson(const char*, short year = 0, const unsigned char month = 0, const unsigned char day = 0);
void removeRelation(person_id firstId, person_id secondId);
void removeRelation(const char* firstName, const char* secondName);
void draw(person_id focused=0) const;
void print()const;
void printRel(person_id id)const; //Prints out close relatives
void printMember(person_id id)const;
void printOldestAncestors(person_id id)const;//
private:
void commonAncestorRec(person_id id, const Array<char> &visited)const;
/* draw a line of people starting from person with id
return the farthest X that will be drawn */
I16 drawLine(person_id id, I16 drawY, I16 drawX) const;
I16 drawLineWithWives(person_id id, I16 drawY, I16 drawX) const;
std::string treeName = "Unnamed";
unsigned numPeople = 0;
Array<Person> people; //The data for each member
Array<Array<Relation>> relations; //The relatives of each member
U16 offset = 0;
U8 dist_between = 1;
//Search, ect.
};
enum RelType : U8
{
Invalid = 0,
Parent,
@@ -14,63 +81,3 @@ enum Relation : U8
Spouse,
ExSpouse
};
const U32 Nobody = UINT_MAX; //Òîçè íîìåð ùå áúäå çàïàçeí çà ëèïñà íà âðúçêà/÷îâåê
class Tree
{
public:
using person_id = U32;
Tree() = default;
template <class Str>
Tree(Str&& Name) : treeName(std::forward<Str>(Name)) {}
/*Tree(const 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);
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, 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 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);
void removeRelation(const char* firstName, const char* secondName);
void draw() const;
void print()const;
void printRel(const unsigned id)const; //Prints out close relatives
void printMember(const unsigned id)const;
void printOldestAncestors(const unsigned id)const;//
private:
void commonAncestorRec(const unsigned &id, const Array<char> &visited)const;
/* draw a line of people starting from person with id
return the farthest X that will be drawn */
I16 drawLineRec(person_id id, I16 drawY, I16 drawX) const;
std::string treeName = "Unnamed";
unsigned numPeople = 0;
Array<Person> people; //The data for each member
Array<Array<unsigned>> relatives; //The relatives of each member
Array<Array<Relation>> relations; //The type of relation each member has with his relatives
U16 offset = 0;
//Search, ect.
};