source: golgotha/src/maxtool/sdk_inc/ptrvec.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1/**********************************************************************
2 *<
3        FILE: ptrvec.h
4
5        DESCRIPTION:  An variable length array of pointers
6
7        CREATED BY: Dan Silva
8
9        HISTORY:
10
11 *>     Copyright (c) 1994, All Rights Reserved.
12 **********************************************************************/
13
14#ifndef __PTRVEC__H
15#define __PTRVEC__H
16
17class PtrVector {
18        protected:
19                int size;
20                int nused;
21                void** data;
22                PtrVector() { size = nused = 0; data = NULL; }
23                UtilExport ~PtrVector();
24                UtilExport PtrVector(const PtrVector& v);
25                UtilExport PtrVector&   operator=(const PtrVector& v);
26            UtilExport void append(void * ptr , int extra);
27                UtilExport void insertAt(void * ptr , int at, int extra);
28            UtilExport void* remove(int i);
29            UtilExport void* removeLast();
30                void* operator[](int i) const { return data[i]; }               
31                void*& operator[](int i) { return data[i]; }           
32        public:
33                UtilExport void reshape(int i);  // sets capacity
34                UtilExport void setLength(int i);  // sets length, capacity if necessary
35                UtilExport void clear();        // deletes the ptr array, but not the objects
36                void shrink() { reshape(nused); }
37                int length() const { return nused; }
38                int capacity() const { return size; }
39        };
40
41template <class T> class PtrVec: public PtrVector {
42public:
43        PtrVec():PtrVector() {}
44        T* operator[](int i) const { return (T*)PtrVector::operator[](i); }             
45        T*& operator[](int i) { return (T*&)PtrVector::operator[](i); }                         
46        PtrVec<T>& operator=(const PtrVec<T>& v) { return (PtrVec<T>&)PtrVector::operator=(v); }
47        void append(T *ptr, int extra = 10) { PtrVector::append(ptr,extra); }   
48        void insertAt(T* ptr, int at, int extra=10) { PtrVector::insertAt(ptr,at,extra); }       
49        T* remove(int i) { return (T *)PtrVector::remove(i); }         
50        T* removeLast() { return (T *)PtrVector::removeLast(); }               
51        void deleteAll();  //  deletes all the objects         
52        };
53
54template <class T>
55void PtrVec<T>::deleteAll() {
56        while (length()) {
57                T* p = removeLast();
58                delete p;
59                }
60        }
61
62#endif
Note: See TracBrowser for help on using the repository browser.