This commit is contained in:
vrd
2023-02-24 09:00:29 +02:00
parent 864d40cb81
commit e626470f71
5 changed files with 34 additions and 20 deletions
+8 -4
View File
@@ -215,7 +215,7 @@ namespace /* internal */
void state_person()
{
char* name_start = it_data;
pair<person_id, person_id> parents;
pair<person_id, person_id> parents(Nobody, Nobody);
person_id spouse;
EventTime birth{};
EventTime death{};
@@ -247,10 +247,12 @@ namespace /* internal */
break;
case 'p':
it_data += 2;
processParents();
parents = processParents();
break;
case 's':
it_data += 2;
parseSpouses();
break;
default:
unexpected_char(it_data[-1]);
}
@@ -278,8 +280,9 @@ namespace /* internal */
{
alloced res(file.len);
char* itres = res.data;
char* end = file.data + file.len;
for(char* it = file.data, * itres = res.data; it < end; ++it)
for(char* it = file.data; it < end; ++it)
{
switch(*it)
{
@@ -296,6 +299,7 @@ namespace /* internal */
++itres;
}
}
end_data = itres;
return res;
}
@@ -310,7 +314,7 @@ Tree parseTftFile(MappedFile file)
alloced preprocessed = preprocess(file);
it_data = preprocessed.data;
end_data = preprocessed.end;
/* end_data = preprocessed.end; */
state_neutral();
+13 -13
View File
@@ -60,8 +60,8 @@ void EventTime::print() const
}
Person::Person(const char* name, EventTime birth, Sex sex, EventTime death)
: name_(name)
Person::Person(const char* aName, EventTime birth, Sex aSex, EventTime death)
: name(aName)
, birth_(birth)
, sex(sex)
, death_(death)
@@ -71,16 +71,16 @@ Person::Person(const char* name, EventTime birth, Sex sex, EventTime death)
bool Person::operator==(const Person &other)const
{
return name_ == other.name_; //&& sex == other.sex; //TODO && day == other.day || !day || !other.day) && (month == other.month || !month || !other.month) && (year == other.year || !year || !other.year);
return name == other.name; //&& sex == other.sex; //TODO && day == other.day || !day || !other.day) && (month == other.month || !month || !other.month) && (year == other.year || !year || !other.year);
}
void Person::write(std::ofstream &file)const
{
//
char nameLen = name_.size();
char nameLen = name.size();
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*>(&sex), sizeof(sex));
//file.write(reinterpret_cast<const char*>(&day), sizeof(day)); TODO
//file.write(reinterpret_cast<const char*>(&month), sizeof(month));
@@ -95,7 +95,7 @@ void Person::read(std::ifstream &file)
char nameBuf[128];
file.read(nameBuf, nameLen * sizeof(*nameBuf));
nameBuf[nameLen] = '\0';
name_ = nameBuf;
name = nameBuf;
file.read(reinterpret_cast<char*>(&sex), sizeof(sex));
//file.read(reinterpret_cast<char*>(&day), sizeof(day)); TODO
@@ -105,14 +105,14 @@ void Person::read(std::ifstream &file)
void Person::rename(const char* newName)
{
name_ = newName;
name = newName;
}
void Person::displayInfo()const
{
info_tab = newwin(LINES, COLS, 0, 0);
waddstr(info_tab, name_.data());
waddstr(info_tab, name.data());
waddch(info_tab,'\n');
waddstr(info_tab, "Birth: ");
@@ -143,17 +143,17 @@ static U16 strUtf8Symbols(const std::string& str)
U16 Person::boxWidth() const
{
return strUtf8Symbols(name_) + 4;
return strUtf8Symbols(name) + 4;
}
/* WINDOW* Person::createPad()const */
/* { */
/* U16 width = name_.size() + 4; */
/* U16 width = name.size() + 4; */
/* WINDOW* pad = newpad(5, width); */
/* box(pad, 5, width); */
/* mvwaddstr(pad, 2, 2, name_.data()); */
/* mvwaddstr(pad, 2, 2, name.data()); */
/* return pad; */
/* } */
@@ -167,7 +167,7 @@ void Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpous
WINDOW* pad = newpad(BOX_HEIGHT, width);
auto color_pair = COLOR_PAIR( selected ? COLOR_SELECTED
: (sex ? COLOR_MALE : COLOR_FEMALE) );
: (sex==M ? COLOR_MALE : COLOR_FEMALE) );
wbkgd(pad, color_pair);
/* wattron(pad, color_pair); */
@@ -176,7 +176,7 @@ void Person::draw(const I16 drawY, const I16 drawX, bool selected, bool hasSpous
isSpouse ? ACS_TTEE : ACS_LTEE, hasSpouse ? ACS_TTEE : ACS_URCORNER,
hasKids ? ACS_LTEE : ACS_LLCORNER, ACS_LRCORNER );
mvwaddstr(pad, 2, 2, name_.data());
mvwaddstr(pad, 2, 2, name.data());
/* wattroff(pad, color_pair); */
+2 -2
View File
@@ -41,7 +41,7 @@ class Person
{
public:
Person() = default;
Person(const char* name, EventTime birth={}, Sex=M, EventTime death={});
Person(const char* aName, EventTime birth={}, Sex=M, EventTime death={});
/* Person(Person&&) = default; */
/* Person& operator=(Person&&) = default; */
/* Person& operator=(const Person&) = default; */
@@ -62,7 +62,7 @@ public:
returns the width of the box*/
void draw(I16 drawY, I16 drawX, bool selected, bool hasSpouse, bool isSpouse, bool hasChildren=false) const;
std::string name_;
std::string name;
EventTime birth_;
Sex sex;
EventTime death_;
+10
View File
@@ -102,6 +102,16 @@ void Tree::rename(const char* newName)
treeName = newName;
}
person_id Tree::findId(const char* name) const
{
for (person_id i = 0; i < numPeople; ++i)
{
if (name == people[i].name)
return i;
}
return Nobody;
}
person_id Tree::findId(const char* name, Sex s) const
{
Person sought(name, {}, s);
+1 -1
View File
@@ -44,7 +44,7 @@ public:
void rename(const char* newName);
person_id findId(const char* name) const{return Nobody;} /* todo */
person_id findId(const char* name) const;
person_id findId(const char* name, Sex) const;
person_id findOldestAncestor(person_id, Sex) const;//
//oldest common ancestor ID, a person is considerd an ancestor of himself