Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GList.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // GList.h
00004 //
00005 // Copyright 2001 Derek B. Noonburg
00006 //
00007 //========================================================================
00008 
00009 #ifndef GLIST_H
00010 #define GLIST_H
00011 
00012 #ifdef __GNUC__
00013 #pragma interface
00014 #endif
00015 
00016 #include "gtypes.h"
00017 
00018 //------------------------------------------------------------------------
00019 // GList
00020 //------------------------------------------------------------------------
00021 
00022 class GList {
00023 public:
00024 
00025   // Create an empty list.
00026   GList();
00027 
00028   // Create an empty list with space for <size1> elements.
00029   GList(int sizeA);
00030 
00031   // Destructor - does not free pointed-to objects.
00032   ~GList();
00033 
00034   //----- general
00035 
00036   // Get the number of elements.
00037   int getLength() { return length; }
00038 
00039   //----- ordered list support
00040 
00041   // Return the <i>th element.
00042   // Assumes 0 <= i < length.
00043   void *get(int i) { return data[i]; }
00044 
00045   // Append an element to the end of the list.
00046   void append(void *p);
00047 
00048   // Append another list to the end of this one.
00049   void append(GList *list);
00050 
00051   // Insert an element at index <i>.
00052   // Assumes 0 <= i <= length.
00053   void insert(int i, void *p);
00054 
00055   // Deletes and returns the element at index <i>.
00056   // Assumes 0 <= i < length.
00057   void *del(int i);
00058 
00059   //----- control
00060 
00061   // Set allocation increment to <inc>.  If inc > 0, that many
00062   // elements will be allocated every time the list is expanded.
00063   // If inc <= 0, the list will be doubled in size.
00064   void setAllocIncr(int incA) { inc = incA; }
00065 
00066 private:
00067 
00068   void expand();
00069   void shrink();
00070 
00071   void **data;                  // the list elements
00072   int size;                     // size of data array
00073   int length;                   // number of elements on list
00074   int inc;                      // allocation increment
00075 };
00076 
00077 #define deleteGList(list, T)                        \
00078   do {                                              \
00079     GList *_list = (list);                          \
00080     {                                               \
00081       int _i;                                       \
00082       for (_i = 0; _i < _list->getLength(); ++_i) { \
00083         delete (T*)_list->get(_i);                  \
00084       }                                             \
00085       delete _list;                                 \
00086     }                                               \
00087   } while (0)
00088 
00089 #endif

Generated on Sat Nov 5 16:18:11 2005 for OPIE by  doxygen 1.4.2