Files
tft/tree.h
T
2023-01-21 19:10:32 +02:00

106 lines
3.1 KiB
C++

#pragma once
#include <climits>
#include <vector>
#include "person.h"
using person_id = U32;
enum RelType : U8
{
None = 0,
Parent,
Child,
Sibling,
HalfSibling,
Spouse,
ExSpouse,
Other
};
struct Relation
{
person_id id;
RelType type;
};
enum: person_id {
Nobody = UINT_MAX
};
class Tree
{
public:
Tree() = default;
template <class Str>
explicit Tree(Str&& Name) : treeName(std::forward<Str>(Name)) {}
/* Tree(const Tree&) = default; */
/* Tree& operator= (const Tree& other); */
Tree operator+ (const Tree& other) const;
Tree operator- (const Tree& other) const; /* todo */
Tree& operator+= (const Tree& other);
Tree& operator-= (const Tree& other);
void rename(const char* newName);
person_id findId(const char* name, bool=true) const;
person_id findOldestAncestor(person_id id, bool sex = 0) const;//
//oldest common ancestor ID, a person is considerd an ancestor of himself
person_id findCommonAncestor(person_id firstId, person_id secondId) const;
RelType findRelation(person_id first, person_id second) const;
person_id findParent(person_id child, bool isParentMale) const;
person_id findSpouse(person_id person) const;
std::vector<person_id> findChildren(person_id person) const;
void saveToFile()const;//
bool loadFromFile();
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 display();
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, std::vector<U8> &visited)const;
void draw() 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;
void selectLeft();
void selectDown();
void selectUp();
void selectRight();
void selectLeftSibSpouse(person_id person);
void selectRightSib(person_id person);
std::string treeName;
unsigned numPeople = 0;
std::vector<Person> people; //The data for each member
std::vector<std::vector<Relation>> relations; //The relatives of each member
person_id focused_ = 0; /* the tree was draw based on this person */
person_id selected_ = 0;
I16 offsetX_ = 0; /* offset of the tree in relation to the screen*/
I16 offsetY_ = 0;
U8 dist_between_ = 1; /* distance between people */
U8 spouse_dist_ = 0; /* distance between spouses */
//Search, ect.
};