line endings

This commit is contained in:
vrd
2022-10-21 20:01:34 +03:00
parent f69d0cbc2f
commit 30e6480343
9 changed files with 699 additions and 683 deletions
+4 -1
View File
@@ -1,4 +1,7 @@
build bin
.codelite .codelite
*.workspace *.workspace
GPATH
GRTAGS
GTAGS
+1 -1
View File
@@ -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
View File
@@ -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
+69 -69
View File
@@ -1,69 +1,69 @@
#include"help.h" #include"help.h"
#include"tree.h" #include"tree.h"
unsigned strLen(const char* str) unsigned strLen(const char* str)
{ {
unsigned len = 0; unsigned len = 0;
for (; str[len] != '\0'; ++len) for (; str[len] != '\0'; ++len)
; ;
return len; return len;
} }
void strCopy(char *to, const char* from) void strCopy(char *to, const char* from)
{ {
unsigned i = 0; unsigned i = 0;
for (; from[i] != '\0'; ++i) for (; from[i] != '\0'; ++i)
to[i] = from[i]; to[i] = from[i];
to[i] = '\0'; to[i] = '\0';
} }
bool strComp(const char* first, const char* second) bool strComp(const char* first, const char* second)
{ {
for (unsigned i = 0; first[i] != '\0' || second[i] != '\0'; ++i) for (unsigned i = 0; first[i] != '\0' || second[i] != '\0'; ++i)
{ {
if (first[i] != second[i]) if (first[i] != second[i])
return 0; return 0;
} }
return 1; return 1;
} }
char* mergeStr(const char* first, const char* second) //Create new string from 2 existing and return it char* mergeStr(const char* first, const char* second) //Create new string from 2 existing and return it
{ {
char *result = new char[strLen(first) + strLen(second) + 1]; char *result = new char[strLen(first) + strLen(second) + 1];
unsigned j = 0; unsigned j = 0;
for (unsigned i = 0; first[i] != '\0'; ++i, ++j) for (unsigned i = 0; first[i] != '\0'; ++i, ++j)
result[j] = first[i]; result[j] = first[i];
for (unsigned i = 0; second[i] != '\0'; ++i, ++j) for (unsigned i = 0; second[i] != '\0'; ++i, ++j)
result[j] = second[i]; result[j] = second[i];
result[j] = '\0'; result[j] = '\0';
return result; return result;
} }
Relation strToRel(const char* str) Relation strToRel(const char* str)
{ {
if (strComp(str, "Father")) if (strComp(str, "Father"))
return Father; return Father;
else if (strComp(str, "Mother")) else if (strComp(str, "Mother"))
return Mother; return Mother;
else if (strComp(str, "Son")) else if (strComp(str, "Son"))
return Son; return Son;
else if (strComp(str, "Daughter")) else if (strComp(str, "Daughter"))
return Daughter; return Daughter;
else if (strComp(str, "Brother")) else if (strComp(str, "Brother"))
return Brother; return Brother;
else if (strComp(str, "Sister")) else if (strComp(str, "Sister"))
return Sister; return Sister;
else if (strComp(str, "HalfBrother")) else if (strComp(str, "HalfBrother"))
return HalfBrother; return HalfBrother;
else if (strComp(str, "HalfSister")) else if (strComp(str, "HalfSister"))
return HalfSister; return HalfSister;
else if (strComp(str, "Wife")) else if (strComp(str, "Wife"))
return Wife; return Wife;
else if (strComp(str, "Husband")) else if (strComp(str, "Husband"))
return Husband; return Husband;
else if (strComp(str, "ExWife")) else if (strComp(str, "ExWife"))
return ExWife; return ExWife;
else if (strComp(str, "ExHusband")) else if (strComp(str, "ExHusband"))
return ExHusband; return ExHusband;
return Invalid; return Invalid;
} }
+12 -7
View File
@@ -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,18 +37,22 @@ 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;
+83 -76
View File
@@ -1,11 +1,11 @@
#include <iostream> #include <iostream>
#include <assert.h> #include <assert.h>
#include"person.h" #include"person.h"
#include "help.h" #include "help.h"
using std::cout; using std::cout;
EventTime::EventTime(I16 Year, U8 Month, U16 Day, I8 Hour, I8 Minute) EventTime::EventTime(I16 Year, U8 Month, U16 Day, I8 Hour, I8 Minute)
: year(Year) : year(Year)
, month(Month) , month(Month)
@@ -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
@@ -37,76 +36,84 @@ void EventTime::print() const
cout << "????"; cout << "????";
cout << '\n'; cout << '\n';
} }
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)
} {
}
/*Person& Person::operator=(const Person &other)
{ /*Person& Person::operator=(const Person &other)
if (&other!=this) {
{ if (&other!=this)
rename(other.name); {
numRel = other.numRel; rename(other.name);
isMale = other.isMale; numRel = other.numRel;
day = other.day; isMale = other.isMale;
month = other.month; day = other.day;
year = other.year; month = other.month;
} year = other.year;
return *this; }
}*/ return *this;
}*/
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(); //
file.write(reinterpret_cast<char*>(&nameLen), sizeof(nameLen)); char nameLen = name_.size();
file.write(name.data(), nameLen * sizeof(name[0])); file.write(reinterpret_cast<char*>(&nameLen), sizeof(nameLen));
file.write(reinterpret_cast<const char*>(&numRel), sizeof(numRel)); file.write(name_.data(), nameLen * sizeof(name_[0]));
file.write(reinterpret_cast<const char*>(&isMale), sizeof(isMale)); file.write(reinterpret_cast<const char*>(&numRel_), sizeof(numRel_));
//file.write(reinterpret_cast<const char*>(&day), sizeof(day)); TODO file.write(reinterpret_cast<const char*>(&isMale_), sizeof(isMale_));
//file.write(reinterpret_cast<const char*>(&month), sizeof(month)); //file.write(reinterpret_cast<const char*>(&day), sizeof(day)); TODO
//file.write(reinterpret_cast<const char*>(&year), sizeof(year)); //file.write(reinterpret_cast<const char*>(&month), sizeof(month));
} //file.write(reinterpret_cast<const char*>(&year), sizeof(year));
}
void Person::load(std::ifstream &file)
{ void Person::load(std::ifstream &file)
char nameLen; {
file.read((char*)&nameLen, sizeof(nameLen)); //Check len char nameLen;
file.read((char*)&nameLen, sizeof(nameLen)); //Check len
C8 nameBuf[128];
file.read(nameBuf, nameLen * sizeof(*nameBuf)); C8 nameBuf[128];
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));
} }
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';
}
+6 -6
View File
@@ -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_;
}; };
+522 -521
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -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