home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / hl10osrc.zoo / Include / PTree.h < prev    next >
Text File  |  2009-11-06  |  3KB  |  87 lines

  1. /* -*- Mode: C -*- */
  2. /* PTree.h - Parse Tree structs
  3.  * Created by Robert Heller on Thu Feb 27 20:04:20 1992
  4.  *
  5.  * ------------------------------------------------------------------
  6.  * Home Libarian by Deepwoods Software
  7.  * Common Header Files
  8.  * ------------------------------------------------------------------
  9.  * Modification History:
  10.  * ------------------------------------------------------------------
  11.  * Contents:
  12.  * ------------------------------------------------------------------
  13.  * 
  14.  * 
  15.  * Copyright (c) 1991,1992 by Robert heller (D/B/A Deepwoods Software)
  16.  *        All Rights Reserved
  17.  * 
  18.  */
  19.  
  20. #ifndef _PTREE_
  21. #define _PTREE_
  22. #include <common.h>        // common defs
  23.  
  24. // Node and Tree classes.  These classes are structures for holding
  25. // parsed expressions used by the print programs to limit output
  26. // to a selected subset (define by a logical expression)
  27. // To avoid pounding on the simple heap memory management, Nodes and
  28. // Trees are allocated 100 at a time (upto a max of 1,000 each), and
  29. // "old" nodes and trees are reused, rather than returned to the
  30. // general heap.
  31.  
  32. enum NodeTypes {IntNode, StringNode, TreeNode, FieldNode,
  33.            CardTypeNode};                // nodetypes
  34. enum Operators {Equal, Less, Greater, LessEqual,
  35.         GreaterEqual, NotEqual, And, Or, Not};    // operators
  36. enum Fields {TypeField, AuthorField, TitleField, PublisherField, CityField,
  37.          VolumeField, YearField};            // fields
  38.  
  39. class Tree;        // forward decl
  40. class Node {
  41.     const blocksize = 100;    // number of nodes to allocate at a time
  42.     const maxblocks = 10;    // maximum number of blocks to allocate.
  43.     static int numblocks;    // current number of allocated blocks
  44.     static Node* blocks[maxblocks]; // allocated nodes
  45.     static Node* freelist;    // linked list of available nodes
  46.     void   moreblocks();    // internal functio to get another block of nodes
  47. public:
  48.     NodeTypes type;    // type of node
  49.     union {
  50.         int _int;
  51.         char* _string;
  52.         Tree* _tree;
  53.         Fields _field;
  54.         CardType _ctype;
  55.     } value;    // value
  56.         Node()    // new node
  57.            {Node(0);}
  58.         Node(Fields v) {type = FieldNode; value._field = v;}
  59.         Node(CardType v) {type = CardTypeNode; value._ctype = v;}
  60.         Node(int v) {type = IntNode; value._int = v;}
  61.         Node(char* v) {type = StringNode; value._string = v;}
  62.         Node(Tree* v) {type = IntNode; value._tree = v;}
  63.     void* operator new (long bytes);    // dyn. allocated node
  64.     void  operator delete (void* ptr);    // free a dyn. allocated node
  65. };
  66.  
  67. class Tree {
  68.     const blocksize = 100;    // number of trees to allocate at a time
  69.     const maxblocks = 10;    // maximum number of blocks to allocate.
  70.     static int numblocks;    // current number of allocated blocks
  71.     static Tree* blocks[maxblocks]; // allocated trees
  72.     static Tree* freelist;    // linked list of available trees
  73.     void   moreblocks();    // internal functio to get another block of trees
  74. public:
  75.     Operators oper;
  76.     Node* right;
  77.     Node* left;
  78.           Tree() // new tree
  79.             {Tree(Equal,0,0);}
  80.           Tree(Operators o,Node* l,Node* r)
  81.             {oper = o;right = r; left = l;}
  82.     void* operator new (long bytes);    // dyn. allocated node
  83.     void  operator delete (void* ptr);    // free a dyn. allocated node
  84. };
  85. #endif
  86.  
  87.