genhier.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: hierclas.h
00004 
00005     DESCRIPTION: Simple utility class for describing hierarchies
00006 
00007     CREATED BY: Tom Hudson
00008 
00009     HISTORY: Created 3 July 1995
00010 
00011  *> Copyright (c) 1995, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 #include "maxheap.h"
00016 #include "strclass.h"
00017 
00018 #define INVALID_HIERARCHY -1
00019 
00040 class HierarchyEntry: public MaxHeapOperators {
00041     public:
00042         int data;
00043         int children;
00044         HierarchyEntry *parent;
00045         HierarchyEntry *sibling;
00046         HierarchyEntry *child;
00047         MSTR sortKey;
00049         UtilExport HierarchyEntry();
00058         UtilExport HierarchyEntry(int d, HierarchyEntry *p, HierarchyEntry *s);
00063         UtilExport int HierarchyLevel();
00069         UtilExport void AddChild(int d);
00077         UtilExport int GetChild(int index);
00079         int Children() { return children; }
00081         UtilExport void Sort();
00082     };
00083 
00095 class GenericHierarchy: public MaxHeapOperators {
00096     private:
00097         HierarchyEntry root;
00098         void FreeTree(HierarchyEntry* start = NULL);
00099         BOOL isSorted;
00100         void CopyTree(int parent, HierarchyEntry* ptr);
00101     public:
00103         GenericHierarchy() { root = HierarchyEntry(-1,NULL,NULL); isSorted = FALSE; }
00104         UtilExport ~GenericHierarchy();
00111         UtilExport void AddEntry(int data, int parent = -1);        // Add one entry, given its parent
00113         UtilExport int Entries();                                   // Total number of members in the hierarchy
00116         UtilExport HierarchyEntry* GetStart() { return root.child; } // Get the first item under the root
00126         UtilExport HierarchyEntry* FindEntry(int data, HierarchyEntry* start = NULL);
00131         UtilExport int NumberOfChildren(int data);                  // The number of children for this item
00139         UtilExport int GetChild(int data, int index);               // Get the nth child of this item
00141         UtilExport void New();                                      // Clear out the hierarchy tree
00145         UtilExport void Sort();                                     // Sort tree by children/siblings
00152         UtilExport BOOL IsCompatible(GenericHierarchy& hier);       // Are they compatible?
00156         UtilExport void Dump(HierarchyEntry* start = NULL);         // DebugPrint the tree
00161         UtilExport GenericHierarchy& operator=(GenericHierarchy& from); // Copy operator
00166         UtilExport MSTR& SortKey();                                 // Get the sort key for the hierarchy
00167     };
00168