00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Cristin Barghiel 00008 * Side Effects 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: GP_NodeTree.h (C++) 00015 * 00016 * COMMENTS: paste nodes stored in a splay tree structure 00017 * 00018 * 00019 */ 00020 00021 #ifndef __GP_NodeTree_h__ 00022 #define __GP_NodeTree_h__ 00023 00024 00025 #include "GP_API.h" 00026 #include <UT/UT_SplayTree.h> 00027 00028 class GP_Node; 00029 00030 class GP_API GP_NodeTree : public UT_SplayTree 00031 { 00032 public: 00033 // Constructors and destructor: 00034 GP_NodeTree(void); 00035 GP_NodeTree(const GP_NodeTree &tree); // shallow 00036 virtual ~GP_NodeTree(void); // does a clear(), not a clearAndDestroy() 00037 00038 // Clear and DESTROY ourselves, then copy the data from the source. If 00039 // we encounter the target in the source while copying, return its copy. 00040 GP_Node *copyFrom(const GP_NodeTree &src, const GP_Node * = 0); 00041 00042 // Another copy method that looks for the nodes to insert in a pool of 00043 // destination nodes rather than copying the source nodes. Return 0 if 00044 // all source nodes were found in the destination, else -1. 00045 // We first clear ourselves. 00046 int copyFrom(const GP_NodeTree &src, 00047 const GP_NodeTree &destpool); 00048 00049 // Insert a node into the structure. Return 0 if the node is already 00050 // in the tree. Otherwise return 1. 00051 int insert(const GP_Node &d) 00052 { 00053 return UT_SplayTree::add(&d); 00054 } 00055 int append(const GP_Node &d) 00056 { 00057 return UT_SplayTree::add(&d); 00058 } 00059 00060 // Remove a node from the structure and return its address if found. 00061 const GP_Node *remove(void) // removes root 00062 { 00063 return (const GP_Node*)UT_SplayTree::remove(); 00064 } 00065 const GP_Node *remove(int key); 00066 const GP_Node *remove(const GP_Node &d) 00067 { 00068 return (const GP_Node*)UT_SplayTree::remove(&d); 00069 } 00070 00071 // Search for a given node and return it if found. The search is by 00072 // key, so the address might differ. 00073 const GP_Node *find(int key) const; 00074 const GP_Node *find(const GP_Node &d) const 00075 { 00076 return (const GP_Node*)UT_SplayTree::find(&d); 00077 } 00078 00079 // Inquire about a given node: 00080 int contains(int key) const; 00081 int contains(const GP_Node &d) const 00082 { 00083 return (UT_SplayTree::find(&d) != 0); 00084 } 00085 00086 // Clear the structure, or clear and destroy its GP_Node contents too: 00087 void clear(void) { UT_SplayTree::clear(); } 00088 void clearAndDestroy(void); 00089 00090 private: 00091 // Nothing. 00092 }; 00093 00094 #endif
1.5.9