home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / classsource.lha / ClassSource / DataStructures / GenArraylist / GenArraylist.c
Encoding:
C/C++ Source or Header  |  1995-02-12  |  1.3 KB  |  92 lines

  1.  
  2. #include <classes/DataStructures/GenArraylist.h>
  3. #include <string.h>
  4.  
  5. gen_arraylist::gen_arraylist(ULONG es, ULONG s)
  6.     : gen_array(es,s)
  7. {
  8.     top = 0;
  9. }
  10.  
  11. VOID &gen_arraylist::addTail()
  12. {
  13.     return gen_array::operator[] (top++);
  14. }
  15.  
  16. VOID &gen_arraylist::insert(ULONG index)
  17. {
  18.     if (index == top)
  19.         return addTail();
  20.     if (index < top)
  21.     {
  22.         gen_array::operator[] (top++);
  23.         memmove(&gen_array::operator[] (index+1),
  24.             &gen_array::operator[] (index),(top-index-1)*esize());
  25.     };
  26.     return gen_array::operator[] (index);
  27. }
  28.  
  29. VOID gen_arraylist::remove(ULONG index)
  30. {
  31.     if (index == top-1)
  32.         --top
  33.     else if (index < top-1)
  34.     {
  35.         --top;
  36.         memmove(&gen_array::operator[] (index),
  37.             &gen_array::operator[] (index+1),(top-index)*esize());
  38.     };
  39. }
  40.  
  41. VOID gen_arraylist::remTail()
  42. {
  43.     if (top > 0)
  44.         --top;
  45. }
  46.  
  47. VOID gen_arraylist::clear()
  48. {
  49.     top = 0;
  50. }
  51.  
  52. // *************************************************************
  53.  
  54. gen_arraycursor::gen_arraycursor(gen_arraylist &l)
  55. {
  56.     list = &l;
  57.     first();
  58. }
  59.  
  60. VOID gen_arraycursor::first()
  61. {
  62.     pos = 0;
  63. }
  64.  
  65. VOID gen_arraycursor::last()
  66. {
  67.     pos = list->length() - 1;
  68. }
  69.  
  70. VOID gen_arraycursor::next()
  71. {
  72.     if (pos < list->length())
  73.         pos++;
  74. }
  75.  
  76. VOID gen_arraycursor::prev()
  77. {
  78.     if (pos >= 0)
  79.         pos--;
  80. }
  81.  
  82. VOID &gen_arraycursor::item()
  83. {
  84.     return list->operator[](pos);
  85. }
  86.  
  87. BOOL gen_arraycursor::isDone()
  88. {
  89.     return pos >= list->length() || pos < 0;
  90. }
  91.  
  92.