save tree to tft dir

This commit is contained in:
vrd
2023-02-21 09:38:09 +02:00
parent 16894e2983
commit ee152edbad
8 changed files with 59 additions and 28 deletions
+15
View File
@@ -0,0 +1,15 @@
#include <ncursesw/ncurses.h>
#include "tree.hpp"
#include "utils.hpp"
#include "user_tree.hpp"
int main()
{
init();
create_tree();
endwin(); /* stop ncursers */
return 0;
}
+2 -22
View File
@@ -3,28 +3,12 @@
#include "tree.hpp"
#include "utils.hpp"
#include "user_tree.hpp"
/* using std::cin; */
/* using std::cout; */
int main()
int main(int argc, char* argv[])
{
setlocale(LC_ALL, "en_US.UTF-8");
/* Init ncurses */
initscr(); /* Start curses mode */
curs_set(0); /* Hide cursor */
noecho();
cbreak(); /* get input instantly */
keypad(stdscr, true);
start_color();
use_default_colors();
/* init_pair(5, COLOR_BLACK, COLOR_BLACK); */
/* bkgd(COLOR_PAIR(5)); */
init_pair(COLOR_MALE, COLOR_CYAN, -1); /* -1 means use default */
init_pair(COLOR_FEMALE, COLOR_RED, -1);
init_pair(COLOR_SELECTED, COLOR_YELLOW, -1);
wnoutrefresh(stdscr); /* if not present the first real refresh is missed */
init();
Tree test1("Dechkovi");
test1.loadFromFile();
@@ -53,10 +37,6 @@ int main()
(test2 + test1).display();
create_tree();
/* Tree firstTree("firstTree"); */
/* firstTree.addPerson("Адам", true, Nobody, Nobody, {0, 1, 6}); */
/* firstTree.addPerson("Ева", false, Nobody, Nobody, {0, 1, 6}); */
+13 -2
View File
@@ -7,6 +7,7 @@
using std::ofstream;
using std::ifstream;
using std::vector;
using std::string;
Tree Tree::operator+ (const Tree& other) const
{
@@ -206,7 +207,13 @@ RelType Tree::findRelation(person_id first, person_id second) const
void Tree::saveToFile() const
{
ofstream file(treeName + ".tft", std::ios::binary);
const char* HOME = getenv("HOME");
string tftDir(HOME);
tftDir += "/.tft";
system(("mkdir " + tftDir).c_str());
ofstream file(tftDir + '/' + treeName + ".tftb", std::ios::binary);
file.write((const char*)(&numPeople), sizeof(numPeople));
for (const Person& p: people)
@@ -222,7 +229,11 @@ void Tree::saveToFile() const
bool Tree::loadFromFile()
{
ifstream file(treeName + ".tft", std::ios::binary);
const char* HOME = getenv("HOME");
string tftDir(HOME);
tftDir += "/.tft";
ifstream file(tftDir + '/' + treeName + ".tftb", std::ios::binary);
file.read((char*)(&numPeople), sizeof(numPeople));
+22
View File
@@ -1,4 +1,26 @@
#include "utils.hpp"
#include "person.hpp"
#include <clocale>
void init()
{
setlocale(LC_ALL, "en_US.UTF-8");
/* Init ncurses */
initscr(); /* Start curses mode */
curs_set(0); /* Hide cursor */
noecho();
cbreak(); /* get input instantly */
keypad(stdscr, true);
start_color();
use_default_colors();
/* init_pair(5, COLOR_BLACK, COLOR_BLACK); */
/* bkgd(COLOR_PAIR(5)); */
init_pair(COLOR_MALE, COLOR_CYAN, -1); /* -1 means use default */
init_pair(COLOR_FEMALE, COLOR_RED, -1);
init_pair(COLOR_SELECTED, COLOR_YELLOW, -1);
wnoutrefresh(stdscr); /* if not present the first real refresh is missed */
}
bool willBeVisible(I16 drawY, I16 drawX, U16 height, U16 width)
{
+2
View File
@@ -23,6 +23,8 @@
/* return lhs; */
/* } */
void init();
template <class Vec>
void remove(Vec& vec, size_t pos) /* Remove from vector by moving the last element in its place */
{