NGen

Untitled

May 17th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.26 KB | None | 0 0
  1. #ifndef INNOVATION_ENGINE_BASIC_TREE_H
  2. #define INNOVATION_ENGINE_BASIC_TREE_H
  3.  
  4. #include <deque>
  5.  
  6. #include <ORE\Retainable Container.h>
  7.  
  8. //  std::deque chosen for general-purpose capabilities and efficiencies.
  9. #define DEF_SEQUENTIAL_CONTAINER std::deque
  10.  
  11. namespace ie
  12. {
  13.     enum NodeType
  14.     {
  15.         Tree_Node = 1,
  16.         Tree_Split = 2,
  17.         Tree_Branch = 6,    //  Tree_Branch has 2's bit ON
  18.         Tree_Root = 10,     //  Tree_Root has 2's bit ON        You can still check for exact values, but if you just
  19.                     //                      want something with children then check for Split's bit
  20.  
  21.         Tree_Mask = 0xFF    //  Mask of the NodeType variable that is being used by the system itself, feel free to use
  22.                     //      the other bits if you want to
  23.     };
  24.  
  25.     //  Keeping inheritance in mind, all members are typed using STL-style
  26.     //      naming and are prefixed with an underscore and an abbreviation
  27.     //      of the parent class name to keep down on intellisense clutter.
  28.  
  29.     class CBasicTreeObject
  30.     {
  31.     public:
  32.         NodeType _bto_type;
  33.  
  34.         virtual ~CBasicTreeObject ()
  35.         {
  36.         }
  37.     };
  38.  
  39.     class CBasicSequentialTreeSplit;
  40.  
  41.     class CBasicSequentialTreeNode
  42.         : public CBasicTreeObject
  43.     {
  44.     public:
  45.         CBasicSequentialTreeNode * _bstn_next, * _bstn_previous;
  46.         CBasicSequentialTreeSplit * _bstn_parent;
  47.  
  48.         CBasicSequentialTreeNode (CBasicSequentialTreeNode* next = NULL, CBasicSequentialTreeNode* previous = NULL, CBasicSequentialTreeSplit* parent = NULL)
  49.             : _bstn_next (next), _bstn_previous (previous), _bstn_parent (parent)
  50.         {
  51.             _bto_type = Tree_Node;
  52.         }
  53.  
  54.         CBasicSequentialTreeNode (const CBasicSequentialTreeNode& o)
  55.             : _bstn_next (o._bstn_next), _bstn_previous (o._bstn_previous), _bstn_parent (o._bstn_parent)
  56.         {
  57.             _bto_type = Tree_Node;
  58.         }
  59.  
  60.         virtual ~CBasicSequentialTreeNode (){}
  61.     };
  62.  
  63.  
  64.  
  65.     //  SEQUENTIAL CLASS DEFINITIONS
  66.  
  67.     //  Some object that can have children (bad name I know, nothing else really works though.)
  68.     class CBasicSequentialTreeSplit
  69.     {
  70.     public:
  71.         //  You'll have to handle the deletion of the children yourself
  72.         ie::CRetainablePtr <DEF_SEQUENTIAL_CONTAINER <CBasicSequentialTreeNode *>> _bsts_children;
  73.  
  74.         CBasicSequentialTreeSplit ()
  75.             : _bsts_children (new DEF_SEQUENTIAL_CONTAINER <CBasicSequentialTreeNode *>)
  76.         {
  77.         }
  78.  
  79.         CBasicSequentialTreeSplit (const CBasicSequentialTreeSplit& o)
  80.             : _bsts_children (o._bsts_children)
  81.         {
  82.         }
  83.  
  84.         virtual ~CBasicSequentialTreeSplit () {}
  85.     };
  86.  
  87.     //  A branch, specifically
  88.     class CBasicSequentialTreeBranch
  89.         : public CBasicSequentialTreeNode, public CBasicSequentialTreeSplit
  90.     {
  91.     public:
  92.         CBasicSequentialTreeBranch (CBasicSequentialTreeNode* next = NULL, CBasicSequentialTreeNode* previous = NULL, CBasicSequentialTreeSplit* parent = NULL)
  93.             : CBasicSequentialTreeNode (next, previous, parent)
  94.         {
  95.             _bto_type = Tree_Branch;
  96.         }
  97.  
  98.         virtual ~CBasicSequentialTreeBranch () {}
  99.     };
  100.  
  101.     //  A tree, specifically
  102.     class CBasicSequentialTree
  103.         : public CBasicTreeObject, public CBasicSequentialTreeSplit
  104.     {
  105.     public:
  106.         CBasicSequentialTree ()
  107.         {
  108.             _bto_type = Tree_Root;
  109.         }
  110.  
  111.         virtual ~CBasicSequentialTree () {}
  112.     };
  113.  
  114.  
  115.     //  TYPE DEFINITIONS
  116.     typedef DEF_SEQUENTIAL_CONTAINER <CBasicSequentialTreeNode *>           SequentialTreeContainer;
  117.     typedef DEF_SEQUENTIAL_CONTAINER <CBasicSequentialTreeNode *>::iterator SequentialTreeIterator;
  118. }
  119.  
  120. #endif
Advertisement
Add Comment
Please, Sign In to add comment