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.12 2002/06/17 17:04:04 gaburici Exp $
44 #ifndef _BPatch_Vector_h_
45 #define _BPatch_Vector_h_
50 #include "BPatch_dll.h"
57 #define BPatch_Vector vector
60 #ifdef external_templates
62 #endif /* external_templates */
65 * This causes problems when including this file in code that uses STL,
66 * so I'm taking it out for now. - brb
67 #ifndef BPATCH_LIBRARY
68 #define vector BPatch_Vector
73 class BPATCH_DLL_EXPORT BPatch_Vector {
74 int reserved; // Number of objects for which space is reserved
75 int len; // The current number of objects in the vector
76 T* data; // Points to the array of objects
79 inline void copy_from(const BPatch_Vector &);
81 BPatch_Vector(int n = 0);
82 BPatch_Vector(const BPatch_Vector<T> &);
85 BPatch_Vector<T>& operator=(const BPatch_Vector<T> &);
87 unsigned int size() const { return len; }
88 void push_back(const T& x);
89 void push_front(const T& x);
91 T& operator[](int n) const;
94 // VG(06/15/02): VC.NET doesn't like definitions for dll imports
95 #ifndef BPATCH_DLL_IMPORT
97 // Reserve space for at least n entries in the vector
99 void BPatch_Vector<T>::reserve(int n)
101 if (n > reserved) { // If we haven't already reserved enough space
102 // Generally we double the size each time we reserve memory, so
103 // that we're not doing it for every insertion.
104 if (reserved*2 > n) n = reserved*2;
106 // Create a new array with enough space
107 T* new_data = new T[n];
109 // Copy the entries from the old array to the new one
110 for (int i = 0; i < len; i++)
111 new_data[i] = data[i];
113 // Get rid of the old array and set up to use the new one
114 if( data != NULL ) delete [] data;
118 assert(data != NULL || n == 0);
121 // Copy the contents of another vector into this one.
123 inline void BPatch_Vector<T>::copy_from(const BPatch_Vector &src)
125 reserved = src.reserved;
130 data = new T[reserved];
132 for (int i = 0; i < src.len; i++)
133 data[i] = src.data[i];
137 // Contructor. Takes one optional parameter, the number of entries for which
140 BPatch_Vector<T>::BPatch_Vector(int n) : reserved(0), len(0), data(NULL)
143 if (n > 0) reserve(n);
148 BPatch_Vector<T>::BPatch_Vector(const BPatch_Vector<T> &src)
153 // Destructor. Frees allocated memory.
155 BPatch_Vector<T>::~BPatch_Vector()
157 if( data != NULL ) delete [] data;
160 // Assignment operator. Delete the contents of this vector and copy the
161 // contents of the other vector into it.
163 BPatch_Vector<T>& BPatch_Vector<T>::operator=(const BPatch_Vector<T> &src)
165 if( data != NULL ) delete [] data;
172 // Add an element to the end of the vector.
174 void BPatch_Vector<T>::push_back(const T& x)
181 // Add an element to the end of the vector.
183 void BPatch_Vector<T>::push_front(const T& x)
188 for (i=len; i > 0; i--) data[i] = data[i-1];
193 // Reference the nth element of the vector.
195 T& BPatch_Vector<T>::operator[](int n) const
197 assert(data != NULL && n >= 0 && n < len);
201 #endif /* BPATCH_DLL_IMPORT */
202 #endif /* USE_STL_VECTOR */
203 #endif /* _BPatch_Vector_h_ */