--- /dev/null
+TARGET=nviewer
+CXXFLAGS=-Wall -g -I../src
+OBJECTS=main.o window.o w_node_header.o w_btree.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 <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();
+ /* 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);
+ }
+
+ wBTree *w = new wBTree ();
+ wNodeHeader *w1 = new wNodeHeader (10, 10);
+
+ w->SetTree (&tree);
+ int n = 0;
+ do {
+ w->ShowNode (n);
+ w->Show ();
+
+ w1->SetHeader (n, w->GetHeader ());
+ w1->Show ();
+
+ scanf ("%d", &n);
+ if (n == -1) break;
+
+ } while (true);
+
+ delete w;
+ delete w1;
+
+ endwin();
+ return 0;
+}
+
--- /dev/null
+
+#include <curses.h>
+#include "w_btree.h"
+
+wBTree::wBTree ():Window ("TreeMulator", 0, 0)
+{
+ last_length = 0;
+}
+
+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 = 5;
+ x = 5;
+ /* Dibujo el bloque de color rojo */
+ /*wattron (win, COLOR_PAIR (1));
+ for (uint i=0; i < tree->header.block_size + 2; i++)
+ mvwaddstr (win, y+1, i+x-1, ".");
+ for (uint i=0; i < tree->header.block_size + 2; i++)
+ mvwaddstr (win, y-1, i+x-1, ".");
+ mvwaddstr (win, y, x-1, ".");
+ mvwaddstr (win, y, tree->header.block_size + x, ".");
+ wattroff (win, COLOR_PAIR (1));*/
+
+ 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 (n%2)
+ wattron (win, COLOR_PAIR (2));
+ else
+ wattron (win, COLOR_PAIR (3));
+ 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;
+ mvwaddstr (win, 20, 5, "Ir al nodo (-1 para salir) : ");
+}
+
--- /dev/null
+
+
+#ifndef _W_B_TREE_
+#define _W_B_TREE_
+
+#include "btree.h"
+#include "window.h"
+
+class wBTree : public Window {
+ public:
+ wBTree ();
+ ~wBTree ();
+
+ void SetTree (BTree *b);
+ void ShowNode (uint node_num);
+ BTreeNodeHeader& GetHeader () { return node_header; }
+ protected:
+ BTree *tree;
+ BTreeNodeHeader node_header;
+ uint last_length;
+};
+
+#endif
+
--- /dev/null
+
+#include "w_node_header.h"
+
+wNodeHeader::wNodeHeader (int x, int y):Window ("Header", 25, 4, x, y)
+{
+ SetText (1, 1, "Nodo :");
+ SetText (1, 2, "Nivel :");
+ SetText (1, 3, "Libre :");
+ SetText (1, 4, "Claves :");
+}
+
+void wNodeHeader::SetHeader (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 (int x, int y);
+
+ void SetHeader (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)
+{
+ if (use_box == true) {
+ if (w) w +=2;
+ if (h) h +=2;
+ }
+ if (h) h++;
+
+ width = w;
+ height = h;
+ win = newwin (h, w, y, x);
+
+ if (use_box == true) {
+ wattron (win, COLOR_PAIR (4));
+ box(win, ACS_VLINE, ACS_HLINE);
+ wattroff (win, COLOR_PAIR (4));
+ }
+
+ title = s;
+ wattron (win, COLOR_PAIR (1));
+ mvwaddstr(win, 1, 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+1, x+1, s.c_str ());
+ wrefresh (win);
+}
+
+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 ()
+{
+ wrefresh (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 ();
+
+ 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);
+ void Show ();
+ protected:
+ int width;
+ int height;
+ WINDOW *win;
+ std::string title;
+};
+
+#endif
+