Muy molesto de programar y debuggear. Lo sigo graficamente.
+++ /dev/null
-TARGET=nviewer
-CXXFLAGS=-Wall -g -I../src
-OBJECTS=main.o window.o w_node_header.o w_btree.o w_ask.o
-
-all: $(TARGET)
-
-$(TARGET): $(OBJECTS)
- g++ -o $(TARGET) $(OBJECTS) ../src/libbtree.a -lcurses
-
-clean:
- rm -rf *.o $(TARGET)
-
-
+++ /dev/null
-
-#include "window.h"
-#include "w_btree.h"
-#include "w_node_header.h"
-#include "btree.h"
-#include "random.h"
-#include "w_ask.h"
-#include <signal.h>
-
-int main (int argc, char *argv[])
-{
- std::list<int> lst;
-
- BTree tree ("test.idx", 64);
-
- Random::Init ();
-
- Random::Ints (lst, 20);
-
- std::list<int>::iterator it = lst.begin ();
- while (it != lst.end ()) {
- ClaveFija c(*it);
-
- tree.AddKey (c);
- it++;
- }
- /* Inicio Curses */
- ///signal(SIGINT, finish);
- initscr();
- keypad(stdscr, TRUE);
- nonl();
- cbreak();
- noecho();
- curs_set (0);
-
- /* Si se soporta color, los inicializo */
- if (has_colors()) {
- start_color();
- /* Simple color assignment, often all we need. */
- init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); /* COLOR_PAIR(1) */
- init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
- init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
- init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
- init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
- init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
- init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
- init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
- init_pair(COLOR_PAIR (1), COLOR_RED, COLOR_RED);
- }
-
- /* Creo la ventana principal */
- Window *screen = new Window ("TreeMulator", 0, 0, 0, 0, true);
- wBTree *wb = new wBTree (screen);
- wAsk *ask = new wAsk (screen, "Proximo Nodo :");
-
- wb->SetTree (&tree);
- wb->ShowNode (0);
-
- screen->Show ();
- wb->Show ();
-
- int node;
- while ((node = ask->Node ()) != -1) {
- wb->ShowNode (node);
- }
-
- curs_set (1);
- endwin();
- return 0;
-}
-
+++ /dev/null
-
-#include "w_ask.h"
-
-wAsk::wAsk (Window *p, const std::string &s) : Window (p, s, p->Width ()-2, 3, 1, p->Height()-4)
-{
-}
-
-#define MAX_ 50
-
-uint wAsk::Node ()
-{
- uint pos = 0;
- char arr[MAX_];
- int c;
-
- c = GetChar ();
- while (c != 13) {
- switch (c) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '-':
- arr[pos++] = c;
- break;
- case 127:
- pos--;
- if (pos < 0) pos = 0;
- }
- SetText (1, 1, " ");
-
- mvwaddnstr (win, 1, 1, arr, pos);
- Show ();
- c = GetChar ();
- }
-
- arr[pos] = '\0';
- return atoi (arr);
-}
-
+++ /dev/null
-
-#ifndef _W_ASK_H_
-#define _W_ASK_H_
-
-#include "window.h"
-
-class wAsk : public Window {
- public:
- wAsk (Window *p, const std::string &s);
-
- uint Node ();
-};
-
-#endif
-
+++ /dev/null
-
-#include <curses.h>
-#include "w_btree.h"
-
-wBTree::wBTree (Window *p):Window (p, "", p->Width()-2, p->Height ()-5, 1, 1, true)
-{
- last_length = 0;
- wnode = new wNodeHeader (this, p->Width () - 30, 2);
-}
-
-wBTree::~wBTree ()
-{
-}
-
-void wBTree::SetTree (BTree *b)
-{
- tree = b;
-}
-
-void wBTree::ShowNode (uint node_num)
-{
- uchar *node;
- std::list<BTreeData*> node_keys;
-
- node = tree->ReadBlock (node_num);
- tree->ReadNodoHeader (node, &node_header);
- node_keys = tree->ReadKeys (node, node_header);
-
- int y, x;
- y = 8;
- x = 2;
-
- for (uint o=0; o<last_length; o++)
- mvwaddstr (win, y, x+o, " ");
-
- std::list<BTreeData*>::iterator it = node_keys.begin ();
- int n = 0;
- while (it != node_keys.end ()) {
- std::string s = *(*it);
-
- if ((x+s.length ()) > (width-4)) {
- y++;
- x = 2;
- }
-
- if (n%2)
- wattron (win, COLOR_PAIR (2));
- else
- wattron (win, COLOR_PAIR (3));
- mvwaddnstr (win, y, x, " ", 1);
- x++;
- mvwaddnstr (win, y, x, (const char *)(s.c_str ()), s.length ());
- if (n%2)
- wattroff (win, COLOR_PAIR (2));
- else
- wattroff (win, COLOR_PAIR (3));
- x += s.length ();
- n++;
- it++;
- }
- last_length = x;
- wnode->ShowHeader (node_num, node_header);
-
- Show ();
-}
-
-void wBTree::Show ()
-{
- wnode->Show ();
- Window::Show ();
-}
-
+++ /dev/null
-
-
-#ifndef _W_B_TREE_
-#define _W_B_TREE_
-
-#include "btree.h"
-#include "window.h"
-#include "w_node_header.h"
-
-class wBTree : public Window {
- public:
- wBTree (Window *p);
- ~wBTree ();
-
- void SetTree (BTree *b);
- void ShowNode (uint node_num);
- BTreeNodeHeader& GetHeader () { return node_header; }
-
- virtual void Show ();
- protected:
- BTree *tree;
- BTreeNodeHeader node_header;
- uint last_length;
-
- wNodeHeader *wnode;
-};
-
-#endif
-
+++ /dev/null
-
-#include "w_node_header.h"
-
-wNodeHeader::wNodeHeader (Window *p, int x, int y):Window (p, "Header", 25, 6, x, y)
-{
- SetText (1, 1, "Nodo :");
- SetText (1, 2, "Nivel :");
- SetText (1, 3, "Libre :");
- SetText (1, 4, "Claves :");
-}
-
-void wNodeHeader::ShowHeader (uint node_num, BTreeNodeHeader &h)
-{
- SetText (1, 1, "Nodo : ");
- SetText (1, 2, "Nivel : ");
- SetText (1, 3, "Libre : ");
- SetText (1, 4, "Claves : ");
-
- SetText (10, 1, node_num);
-
- SetText (10, 2, h.level);
- SetText (10, 3, h.free_space);
- SetText (10, 4, h.item_count);
-}
-
+++ /dev/null
-
-#ifndef _W_NODE_HEADER_
-#define _W_NODE_HEADER_
-
-#include "btree.h"
-#include "window.h"
-
-class wNodeHeader : public Window {
- public:
- wNodeHeader (Window *w, int x, int y);
-
- void ShowHeader (uint node_num, BTreeNodeHeader &h);
-};
-
-#endif
-
+++ /dev/null
-
-#include "window.h"
-
-Window::Window (const std::string &s, int w, int h, int x, int y, bool use_box)
-{
- parent = NULL;
- if (!w) w = COLS;
- if (!h) h = LINES;
-
- width = w;
- height = h;
- win = newwin (h, w, y, x);
-
- if (use_box == true) {
- wattron (win, COLOR_PAIR (6));
- box(win, ACS_VLINE, ACS_HLINE);
- wattroff (win, COLOR_PAIR (6));
- }
-
- title = s;
- wattron (win, COLOR_PAIR (1));
- mvwaddstr(win, 0, 1, title.c_str ());
- wattroff (win, COLOR_PAIR (1));
-}
-
-Window::Window (Window *p, const std::string &s, int w, int h, int x, int y, bool use_box)
-{
- parent = p;
- if (!w) w = COLS;
- if (!h) h = LINES;
-
- width = w;
- height = h;
- win = derwin (parent->win, h, w, y, x);
-
- if (use_box == true) {
- wattron (win, COLOR_PAIR (6));
- box(win, ACS_VLINE, ACS_HLINE);
- wattroff (win, COLOR_PAIR (6));
- }
-
- title = s;
- wattron (win, COLOR_PAIR (1));
- mvwaddstr(win, 0, 1, title.c_str ());
- wattroff (win, COLOR_PAIR (1));
-}
-
-Window::~Window ()
-{
- delwin (win);
-}
-
-void Window::SetText (int x, int y, const std::string &s)
-{
- mvwaddstr (win, y, x, s.c_str ());
- Show ();
-}
-
-void Window::SetText (int x, int y, int i)
-{
- std::stringstream ss;
- std::string s;
- ss << i;
- ss >> s;
- SetText (x, y, s);
-}
-
-void Window::SetText (int x, int y, uint i)
-{
- std::stringstream ss;
- std::string s;
- ss << i;
- ss >> s;
- SetText (x, y, s);
-}
-
-void Window::Show ()
-{
- if (parent)
- touchwin (parent->win);
- wrefresh (win);
-}
-
-int Window::GetChar ()
-{
- return wgetch (win);
-}
-
+++ /dev/null
-
-#ifndef _WINDOW_H_
-#define _WINDOW_H_
-
-#include <ncurses.h>
-#include <sstream>
-#include <string>
-
-class Window {
- public:
- Window (const std::string &s, int w, int h, int x=0, int y=0, bool box=true);
- Window (Window *parent, const std::string &s, int w, int h, int x=0, int y=0, bool box=true);
- virtual ~Window ();
-
- void SetText (int x, int y, const std::string &s);
- void SetText (int x, int y, int i);
- void SetText (int x, int y, uint i);
- virtual void Show ();
- int GetChar ();
-
- int Width () { return width; }
- int Height () { return height; }
- protected:
- int width;
- int height;
- WINDOW *win;
- std::string title;
- Window *parent;
-};
-
-#endif
-