home *** CD-ROM | disk | FTP | other *** search
/ ftptest.leeds.ac.uk / 2015.02.ftptest.leeds.ac.uk.tar / ftptest.leeds.ac.uk / bionet / CAE-GROUP / SCL-WIN3x / SCL.EXE / GENNODEA.H < prev    next >
C/C++ Source or Header  |  1994-10-03  |  3KB  |  120 lines

  1.  
  2. #ifndef gennodea_h
  3. #define gennodea_h
  4.  
  5. /*
  6. * NIST Utils Class Library
  7. * clutils/gennode.h
  8. * February, 1994
  9. * David Sauder
  10. * K. C. Morris
  11.  
  12. * Development of this software was funded by the United States Government,
  13. * and is not subject to copyright.
  14. */
  15.  
  16. /* $Id: gennodearray.h,v 2.0.1.2 1994/04/05 16:44:05 sauderd Exp $  */ 
  17.  
  18. /*
  19.  * GenNodeArray - dynamic array object of GenericNodes.
  20.  * the array part of this is copied from Unidraws UArray - dynamic array object
  21.  * Copyright (c) 1990 Stanford University
  22.  */
  23.  
  24. #ifdef __O3DB__
  25. #include <OpenOODB.h>
  26. #endif
  27.  
  28. #include <string.h>
  29. #include <stdlib.h> // to get bcopy for CenterLine
  30.  
  31. #include <gennode.h>
  32.  
  33.     // the initial size of the array
  34. #define ARRAY_DEFAULT_SIZE (1024)
  35.  
  36. //////////////////////////////////////////////////////////////////////////////
  37. // GenNodeArray
  38. // If you delete this object, it does not delete the entries it points to.
  39. // If you want it to delete the entries it points to you need to call
  40. // DeleteEntries().
  41. //////////////////////////////////////////////////////////////////////////////
  42.  
  43. class GenNodeArray 
  44. {
  45. public:
  46.     GenNodeArray(int defaultSize = ARRAY_DEFAULT_SIZE);
  47.     virtual ~GenNodeArray();
  48.  
  49.     GenericNode*& operator[](int index);
  50.     virtual int Index(GenericNode* gn);
  51.     virtual int Index(GenericNode** gn);
  52.  
  53.     int Count();
  54.  
  55.     virtual void Append(GenericNode* gn);
  56.     virtual int Insert(GenericNode* gn);
  57.     virtual int Insert(GenericNode* gn, int index);
  58.     virtual void Remove(int index);
  59.     virtual void ClearEntries();
  60.     virtual void DeleteEntries();
  61.  
  62. protected:
  63.     virtual void Check(int index);
  64.  
  65.     GenericNode** _buf;    // the array
  66.     int _bufsize;    // the possible number of entries in the array
  67.     int _count;        // the number of entries in the array
  68. };
  69.  
  70. //////////////////////////////////////////////////////////////////////////////
  71. // class GenNodeArray inline public functions
  72. //////////////////////////////////////////////////////////////////////////////
  73.  
  74. inline GenNodeArray::GenNodeArray (int defaultSize)
  75. {
  76.     _bufsize = defaultSize;
  77.     _buf = new GenericNode*[_bufsize];
  78.     memset(_buf, 0, _bufsize*sizeof(GenericNode*));
  79.     _count = 0;
  80. }
  81.  
  82. inline GenNodeArray::~GenNodeArray ()
  83. {
  84.  
  85. //    int i;
  86.     // this is dangerous because several things point at these nodes
  87.     // also whatever is derived from this thing might do this
  88. //    for(i = 0; i < _count; i++)
  89. //    delete _buf[i];
  90.     delete [] _buf;
  91. }
  92.  
  93. inline GenericNode*& GenNodeArray::operator[] (int index) 
  94. {
  95.     Check(index);
  96.     return _buf[index];
  97. }
  98.  
  99. inline int GenNodeArray::Index (GenericNode** gn)
  100. {
  101.     return ((gn - _buf) / sizeof(GenericNode*));
  102. }
  103.  
  104. inline void GenNodeArray::Append(GenericNode* gn)
  105. {    
  106.     Insert(gn, _count); 
  107. }
  108.  
  109. inline int GenNodeArray::Insert(GenericNode* gn)
  110. {
  111.     return Insert(gn, _count); 
  112. }
  113.  
  114. inline int GenNodeArray::Count ()
  115. {
  116.     return _count;
  117. }
  118.  
  119. #endif
  120.