home *** CD-ROM | disk | FTP | other *** search
- // NODEMGR.H - NodeMgr Class Header
-
- #ifndef NODEMGR_HPP
- #define NODEMGR_HPP
-
- #include <stddef.h>
- #include <stdio.h>
- #include <string.h>
-
- const stLeaf = -1; // Must be < 0
- const stNotLeaf = 0;
-
- const noEmpty = -1;
- const noFull = -2;
- const noDuplicate = -3; // Duplicate key insertion attempt
- const noNoSelect = -4; // No item selected!
-
- class NodeMgr
- {
-
- private:
-
- int max_items; // Maximum items in node
- int item_size; // Item size (includes item_ptr)
- int cont_size; // Size of item contents (excludes item_ptr)
- int cursor; // Item cursor position
-
- long prev_node; // Previous node
- long next_node; // Next node
- short no_items; // No of items in node
- short status; // Status - stLeaf if leaf, else stNotLeaf
-
- long *item_ptr; // Pointer of item
- char **item_contents; // Item contents
-
- int getpos(char *contents, int start, int stop);
- public:
-
- NodeMgr(int recsize, int itsize);
- ~NodeMgr(void);
-
- void read_data(char *buffer);
- void write_data(char *buffer);
-
- int erase(int itemno = -1);
- int insert(long ptr, char *contents);
-
- int isleaf(void) { return (status == stLeaf); }
-
- long get_prev_node(void) { return prev_node; }
- long get_next_node(void) { return next_node; }
- void set_prev_node(long node) { prev_node = node; }
- void set_next_node(long node) { next_node = node; }
- void set_cursor_low(void) { cursor = -1; }
- void set_cursor_high(void) { cursor = no_items; }
- char *get_high_item(char *buffer) // Return last item in node
- {
- if (no_items == 0)
- return NULL;
- else
- memcpy(buffer, item_contents[no_items - 1], cont_size);
- return buffer;
- }
- char *get_cur_item(char *buffer) // Return item under cursor
- {
- if (cursor < 0 || cursor >= no_items)
- return NULL;
- else
- memcpy(buffer, item_contents[cursor], cont_size);
- return buffer;
- }
- long read_ptr(int item) { return item_ptr[item]; }
- int get_no_items(void) { return no_items; }
- long find(char *contents);
- long retrieve(void);
- long next(void);
- long prev(void);
- void reset(int st = stLeaf);
- void split(char *block1, char *block2);
- };
-
- #endif
-