save tree to tft dir
This commit is contained in:
+3
-2
@@ -1,8 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# cp tft_create /usr/local/bin
|
||||||
|
|
||||||
cd src
|
cd src
|
||||||
# mkdir -p bin/release
|
|
||||||
|
|
||||||
language='
|
language='
|
||||||
-std=c++17
|
-std=c++17
|
||||||
@@ -31,7 +32,7 @@ warnings='
|
|||||||
|
|
||||||
other='-fno-fat-lto-objects'
|
other='-fno-fat-lto-objects'
|
||||||
|
|
||||||
g++ -o tft $language $optimizations $warnings $other -DNDEBUG -pipe -s *.cpp -lncursesw
|
g++ -o tft $language $optimizations $warnings $other -DNDEBUG -pipe -s tft.cpp tree.cpp person.cpp utils.cpp -lncursesw
|
||||||
chmod 775 tft
|
chmod 775 tft
|
||||||
exec mv tft /usr/local/bin
|
exec mv tft /usr/local/bin
|
||||||
#-static -lncursesw -ltinfo
|
#-static -lncursesw -ltinfo
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -3,28 +3,12 @@
|
|||||||
#include "tree.hpp"
|
#include "tree.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
#include "user_tree.hpp"
|
|
||||||
|
|
||||||
/* using std::cin; */
|
/* using std::cin; */
|
||||||
/* using std::cout; */
|
/* using std::cout; */
|
||||||
int main()
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
setlocale(LC_ALL, "en_US.UTF-8");
|
init();
|
||||||
|
|
||||||
/* 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 */
|
|
||||||
|
|
||||||
Tree test1("Dechkovi");
|
Tree test1("Dechkovi");
|
||||||
test1.loadFromFile();
|
test1.loadFromFile();
|
||||||
@@ -53,10 +37,6 @@ int main()
|
|||||||
|
|
||||||
(test2 + test1).display();
|
(test2 + test1).display();
|
||||||
|
|
||||||
create_tree();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Tree firstTree("firstTree"); */
|
/* Tree firstTree("firstTree"); */
|
||||||
/* firstTree.addPerson("Адам", true, Nobody, Nobody, {0, 1, 6}); */
|
/* firstTree.addPerson("Адам", true, Nobody, Nobody, {0, 1, 6}); */
|
||||||
/* firstTree.addPerson("Ева", false, Nobody, Nobody, {0, 1, 6}); */
|
/* firstTree.addPerson("Ева", false, Nobody, Nobody, {0, 1, 6}); */
|
||||||
+13
-2
@@ -7,6 +7,7 @@
|
|||||||
using std::ofstream;
|
using std::ofstream;
|
||||||
using std::ifstream;
|
using std::ifstream;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
Tree Tree::operator+ (const Tree& other) const
|
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
|
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));
|
file.write((const char*)(&numPeople), sizeof(numPeople));
|
||||||
for (const Person& p: people)
|
for (const Person& p: people)
|
||||||
@@ -222,7 +229,11 @@ void Tree::saveToFile() const
|
|||||||
|
|
||||||
bool Tree::loadFromFile()
|
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));
|
file.read((char*)(&numPeople), sizeof(numPeople));
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,26 @@
|
|||||||
#include "utils.hpp"
|
#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)
|
bool willBeVisible(I16 drawY, I16 drawX, U16 height, U16 width)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
/* return lhs; */
|
/* return lhs; */
|
||||||
/* } */
|
/* } */
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
template <class Vec>
|
template <class Vec>
|
||||||
void remove(Vec& vec, size_t pos) /* Remove from vector by moving the last element in its place */
|
void remove(Vec& vec, size_t pos) /* Remove from vector by moving the last element in its place */
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ language='
|
|||||||
warnings='-Wall -Wextra -Wpedantic' #-fanalyzer
|
warnings='-Wall -Wextra -Wpedantic' #-fanalyzer
|
||||||
|
|
||||||
cp -f "$tree_file" user_tree.hpp
|
cp -f "$tree_file" user_tree.hpp
|
||||||
g++ -o "$start_dir/${1%.*}.tft" $language $warnings -march=native -DNDEBUG -pipe -g *.cpp -lncursesw
|
g++ -o "$start_dir/${1%.*}.tft" $language $warnings -march=native -DNDEBUG -pipe -g create_tree.cpp tree.cpp person.cpp utils.cpp -lncursesw
|
||||||
rm user_tree.hpp
|
rm user_tree.hpp
|
||||||
cd "$start_dir"
|
cd "$start_dir"
|
||||||
exec "./${1%.*}.tft"
|
exec "./${1%.*}.tft"
|
||||||
Reference in New Issue
Block a user