whitespace

This commit is contained in:
vrd
2022-12-10 19:21:49 +02:00
parent 30e6480343
commit 489479fd32
3 changed files with 106 additions and 97 deletions
+16 -7
View File
@@ -8,6 +8,8 @@ using std::cout;
int main()
{
initscr(); /* Start curses mode */
/*Tree test1("Dechkovi"); //addTree Dechkovi addTree Karamanovi load 0 load 1 (to work with these example trees)
Tree test2("Karamanovi");
@@ -37,7 +39,7 @@ int main()
test2.saveTree();*/
Tree firstTree("firstTree");
firstTree.addPerson("Адам,", true, Nobody, Nobody, {0, 1, 6});
firstTree.addPerson("Ева", false, Nobody, Nobody, {0, 1, 6});
firstTree.addRelation(0, Husband, 1);
@@ -50,11 +52,15 @@ int main()
firstTree.print();
firstTree.saveTree();
firstTree.printRel(3);
firstTree.printOldestAncestors(3);
/* ====================================================== */
refresh(); /* Print it on to the real screen */
Array<Tree> trees;
bool quit = false;
@@ -90,13 +96,13 @@ int main()
};
unsigned curTree = 0, //Currently selected tree ID
id, secondId; //Indexes
Tree *newTree;
id, secondId; // Person IDs
Tree* newTree;
char name[128], secondName[128];
U8 day, month; //TODO add h m
U16 year;
bool sex;
unsigned father, mother;
unsigned father, mother; // IDs
do
{
@@ -122,8 +128,8 @@ int main()
trees[curTree].rename(name);
break;
case 2: //load
cin >> input;
trees.push(Tree(input));
cin >> input;
trees.push(Tree(input));
if (!trees[trees.gNum() - 1].loadTree())
std::cout << "File doesnt exist or is empty.\n\n";
break;
@@ -262,5 +268,8 @@ int main()
} while (!quit);
endwin(); /* stop ncursers */
return 0;
}
+24 -24
View File
@@ -1,38 +1,38 @@
#pragma once
#include <string>
#include <string>
#include <fstream>
#include "common/basicTypes.h"
struct EventTime
{
//enum { UNKNOWN_DATE=0, UNKNOWN_TIME=1};
static const I16 UNKNOWN_DATE = 0;
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;
/*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;
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;
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 hour; //0-23
I8 minute; //0-59
};
class Person
{
public:
Person() = default;
Person(const char* name, EventTime birth, bool sex, EventTime death);
bool operator==(const Person &other)const;
void save(std::ofstream &file)const;//
void load(std::ifstream &file);
void rename(const char* newName);
void print()const;
};
class Person
{
public:
Person() = default;
Person(const char* name, EventTime birth, bool sex, EventTime death);
bool operator==(const Person &other)const;
void save(std::ofstream &file)const;//
void load(std::ifstream &file);
void rename(const char* newName);
void print()const;
friend class Tree;
private:
@@ -40,5 +40,5 @@ private:
unsigned numRel_; //Number of close relatives - mother, father, brother, sister, wife/husband, child, ex-wife/husband
EventTime birth_;
bool isMale_;
EventTime death_;
EventTime death_;
};
+66 -66
View File
@@ -1,75 +1,75 @@
#pragma once
#include <climits>
#include "array.h"
#include "person.h"
enum Relation : U8
{
Invalid = 0,
Father,
Mother,
Son,
Daughter,
Brother,
Sister,
HalfBrother,
HalfSister,
Wife,
Husband,
ExWife,
ExHusband
};
const unsigned Nobody = UINT_MAX; //Òîçè íîìåð ùå áúäå çàïàçeí çà ëèïñà íà âðúçêà/÷îâåê
class Tree
{
public:
Tree();
template <class Str>
Tree(Str&& Name) : treeName(std::forward<Str>(Name)), numPeople(0) {}
/*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 print()const;
void printRel(const unsigned id)const; //Prints out close relatives
void printMember(const unsigned id)const;
void printOldestAncestors(const unsigned id)const;//
unsigned gNumP()const;
private:
void commonAncestorRec(const unsigned &id, const Array<char> &visited)const;
#include <climits>
#include "array.h"
#include "person.h"
enum Relation : U8
{
Invalid = 0,
Father,
Mother,
Son,
Daughter,
Brother,
Sister,
HalfBrother,
HalfSister,
Wife,
Husband,
ExWife,
ExHusband
};
const unsigned Nobody = UINT_MAX; //Òîçè íîìåð ùå áúäå çàïàçeí çà ëèïñà íà âðúçêà/÷îâåê
class Tree
{
public:
Tree();
template <class Str>
Tree(Str&& Name) : treeName(std::forward<Str>(Name)), numPeople(0) {}
/*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 print()const;
void printRel(const unsigned id)const; //Prints out close relatives
void printMember(const unsigned id)const;
void printOldestAncestors(const unsigned id)const;//
unsigned gNumP()const;
private:
void commonAncestorRec(const unsigned &id, const Array<char> &visited)const;
std::string treeName;
unsigned numPeople;
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
//Search, ect.
//Search, ect.
};