dsrc isn't necessary for this repo
[client-tools.git] / src / external / 3rd / library / perforce / include / vararray.h
blobc9a7d16aec9764fa86aba3ef6359f1d767509f0b
1 /*
2 * Copyright 1995, 1996 Perforce Software. All rights reserved.
3 */
5 /*
6 * VarArray.h - manage a list of void *'s
8 * Class Defined:
10 * VarArray - list of void *'s
12 * Public methods:
14 * VarArray::Clear() - zero out count for values
15 * VarArray::Count() - return count of elements in array
16 * VarArray::ElemTab() - return a pointer to the array
17 * VarArray::Get(i) - return a pointer to slot i in the array
18 * VarArray::Move(i,j) - move element i to j
19 * VarArray::Put(v) - set a new slot to v
20 * VarArray::WillGrow(i) - returns size of new vararray if it
21 * would have to grow in the next i rows.
23 * Private methods:
25 * VarArray::New() - return a pointer to a new slot in the array
28 class VarArray {
30 public:
32 VarArray();
33 VarArray( int max );
34 ~VarArray();
36 void Clear() { numElems = 0; }
37 int Count() const { return numElems; }
38 void ** ElemTab() { return elems; }
39 void * Get( int i ) const { return i<numElems ? elems[i]:0; }
40 void Move( int i, int j ) { elems[j] = elems[i]; }
41 void Exchange( int i, int j )
42 { void *t = elems[j]; elems[j] = elems[i]; elems[i] = t; }
43 void * Put( void *v ) { return *New() = v; }
44 void SetCount( int i ) { numElems = i; }
45 int WillGrow( int interval );
47 private:
48 void ** New();
50 int maxElems;
51 int numElems;
52 void **elems;
53 } ;