home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / isam / include / nodemgr.h < prev   
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.1 KB  |  83 lines

  1. // NODEMGR.H - NodeMgr Class Header
  2.  
  3. #ifndef NODEMGR_HPP
  4. #define NODEMGR_HPP
  5.  
  6. #include <stddef.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. const stLeaf = -1; // Must be < 0
  11. const stNotLeaf = 0;
  12.  
  13. const noEmpty = -1;
  14. const noFull = -2;
  15. const noDuplicate = -3; // Duplicate key insertion attempt
  16. const noNoSelect = -4; // No item selected!
  17.  
  18. class NodeMgr
  19.     {
  20.  
  21. private:
  22.  
  23.     int max_items;  // Maximum items in node
  24.     int item_size;  // Item size (includes item_ptr)
  25.     int cont_size;  // Size of item contents (excludes item_ptr)
  26.     int cursor;     // Item cursor position
  27.  
  28.     long prev_node; // Previous node
  29.     long next_node; // Next node
  30.     short no_items;   // No of items in node
  31.     short status;    // Status - stLeaf if leaf, else stNotLeaf
  32.  
  33.     long *item_ptr; // Pointer of item
  34.     char **item_contents; // Item contents
  35.  
  36.     int getpos(char *contents, int start, int stop);
  37. public:
  38.  
  39.     NodeMgr(int recsize, int itsize);
  40.     ~NodeMgr(void);
  41.  
  42.     void read_data(char *buffer);
  43.     void write_data(char *buffer);
  44.  
  45.     int erase(int itemno = -1);
  46.     int insert(long ptr, char *contents);
  47.  
  48.     int isleaf(void) { return (status == stLeaf); }
  49.  
  50.     long get_prev_node(void) { return prev_node; }
  51.     long get_next_node(void) { return next_node; }
  52.     void set_prev_node(long node) { prev_node = node; }
  53.     void set_next_node(long node) { next_node = node; }
  54.     void set_cursor_low(void) { cursor = -1; }
  55.     void set_cursor_high(void) { cursor = no_items; }
  56.     char *get_high_item(char *buffer) // Return last item in node
  57.         {
  58.         if (no_items == 0)
  59.             return NULL;
  60.         else
  61.             memcpy(buffer, item_contents[no_items - 1], cont_size);
  62.         return buffer;
  63.         }
  64.     char *get_cur_item(char *buffer) // Return item under cursor
  65.         {
  66.         if (cursor < 0 || cursor >= no_items)
  67.             return NULL;
  68.         else
  69.             memcpy(buffer, item_contents[cursor], cont_size);
  70.         return buffer;
  71.         }
  72.     long read_ptr(int item) { return item_ptr[item]; }
  73.     int get_no_items(void) { return no_items; }
  74.     long find(char *contents);
  75.     long retrieve(void);
  76.     long next(void);
  77.     long prev(void);
  78.     void reset(int st = stLeaf);
  79.     void split(char *block1, char *block2);
  80.     };
  81.  
  82. #endif
  83.