2 * Copyright (c) 1996 Barton P. Miller
4 * We provide the Paradyn Parallel Performance Tools (below
5 * described as Paradyn") on an AS IS basis, and do not warrant its
6 * validity or performance. We reserve the right to update, modify,
7 * or discontinue this software at any time. We shall have no
8 * obligation to supply such updates or modifications or any other
9 * form of support to you.
11 * This license is for research uses. For such uses, there is no
12 * charge. We define "research use" to mean you may freely use it
13 * inside your organization for whatever purposes you see fit. But you
14 * may not re-distribute Paradyn or parts of Paradyn, in any form
15 * source or binary (including derivatives), electronic or otherwise,
16 * to any other organization or entity without our permission.
18 * (for other uses, please contact us at paradyn@cs.wisc.edu)
20 * All warranties, including without limitation, any warranty of
21 * merchantability or fitness for a particular purpose, are hereby
24 * By your use of Paradyn, you understand and agree that we (or any
25 * other person or entity with proprietary rights in Paradyn) are
26 * under no obligation to provide either maintenance services,
27 * update services, notices of latent defects, or correction of
28 * defects for Paradyn.
30 * Even if advised of the possibility of such damages, under no
31 * circumstances shall we (or any other person or entity with
32 * proprietary rights in the software licensed hereunder) be liable
33 * to you or any third party for direct, indirect, or consequential
34 * damages of any character regardless of type of action, including,
35 * without limitation, loss of profits, loss of use, loss of good
36 * will, or computer failure or malfunction. You agree to indemnify
37 * us (and any other person or entity with proprietary rights in the
38 * software licensed hereunder) for any and all liability it may
39 * incur to third parties resulting from your use of Paradyn.
42 // $Id: BPatch_Vector.h,v 1.13 2002/12/20 07:49:55 jaw Exp $
44 #ifndef _BPatch_Vector_h_
45 #define _BPatch_Vector_h_
50 #include "BPatch_dll.h"
56 #if ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ == 1 )
57 #define BPatch_Vector std::vector
59 #define BPatch_Vector vector
63 #ifdef external_templates
65 #endif /* external_templates */
68 * This causes problems when including this file in code that uses STL,
69 * so I'm taking it out for now. - brb
70 #ifndef BPATCH_LIBRARY
71 #define vector BPatch_Vector
76 class BPATCH_DLL_EXPORT BPatch_Vector {
77 int reserved; // Number of objects for which space is reserved
78 int len; // The current number of objects in the vector
79 T* data; // Points to the array of objects
82 inline void copy_from(const BPatch_Vector &);
84 BPatch_Vector(int n = 0);
85 BPatch_Vector(const BPatch_Vector<T> &);
88 BPatch_Vector<T>& operator=(const BPatch_Vector<T> &);
90 unsigned int size() const { return len; }
91 void push_back(const T& x);
92 void push_front(const T& x);
94 T& operator[](int n) const;
97 // VG(06/15/02): VC.NET doesn't like definitions for dll imports
98 #ifndef BPATCH_DLL_IMPORT
100 // Reserve space for at least n entries in the vector
102 void BPatch_Vector<T>::reserve(int n)
104 if (n > reserved) { // If we haven't already reserved enough space
105 // Generally we double the size each time we reserve memory, so
106 // that we're not doing it for every insertion.
107 if (reserved*2 > n) n = reserved*2;
109 // Create a new array with enough space
110 T* new_data = new T[n];
112 // Copy the entries from the old array to the new one
113 for (int i = 0; i < len; i++)
114 new_data[i] = data[i];
116 // Get rid of the old array and set up to use the new one
117 if( data != NULL ) delete [] data;
121 assert(data != NULL || n == 0);
124 // Copy the contents of another vector into this one.
126 inline void BPatch_Vector<T>::copy_from(const BPatch_Vector &src)
128 reserved = src.reserved;
133 data = new T[reserved];
135 for (int i = 0; i < src.len; i++)
136 data[i] = src.data[i];
140 // Contructor. Takes one optional parameter, the number of entries for which
143 BPatch_Vector<T>::BPatch_Vector(int n) : reserved(0), len(0), data(NULL)
146 if (n > 0) reserve(n);
151 BPatch_Vector<T>::BPatch_Vector(const BPatch_Vector<T> &src)
156 // Destructor. Frees allocated memory.
158 BPatch_Vector<T>::~BPatch_Vector()
160 if( data != NULL ) delete [] data;
163 // Assignment operator. Delete the contents of this vector and copy the
164 // contents of the other vector into it.
166 BPatch_Vector<T>& BPatch_Vector<T>::operator=(const BPatch_Vector<T> &src)
168 if( data != NULL ) delete [] data;
175 // Add an element to the end of the vector.
177 void BPatch_Vector<T>::push_back(const T& x)
184 // Add an element to the end of the vector.
186 void BPatch_Vector<T>::push_front(const T& x)
191 for (i=len; i > 0; i--) data[i] = data[i-1];
196 // Reference the nth element of the vector.
198 T& BPatch_Vector<T>::operator[](int n) const
200 assert(data != NULL && n >= 0 && n < len);
204 #endif /* BPATCH_DLL_IMPORT */
205 #endif /* USE_STL_VECTOR */
206 #endif /* _BPatch_Vector_h_ */