Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 //-*-c++-*- 00037 /* ==================================================================== 00038 * ==================================================================== 00039 * 00040 * 00041 * Revision history: 00042 * 8-SEP-94 shin - Original Version 00043 * 00044 * Description: 00045 * 00046 * ==================================================================== 00047 * ==================================================================== 00048 */ 00049 #define cxx_template_CXX "cxx_template.cxx" 00050 // rcs_id NOT defined here so that it won't get duplicated 00051 // because this is template, hence gets included implicitly 00052 00053 #include "defs.h" 00054 #include "errors.h" 00055 #include "erglob.h" 00056 #include "cxx_memory.h" 00057 #include "cxx_template.h" 00058 00059 #define MIN_ARRAY_SIZE 16 00060 00061 #if 0 00062 template <class T > 00063 DYN_ARRAY<T>::DYN_ARRAY(void) 00064 { 00065 _lastidx = -1; 00066 _size = 0; 00067 _array = NULL; 00068 _mpool = NULL; 00069 } 00070 00071 template <class T > 00072 DYN_ARRAY<T>::DYN_ARRAY(MEM_POOL *pool) 00073 { 00074 _lastidx = -1; 00075 _size = 0; 00076 _array = NULL; 00077 _mpool = pool; 00078 } 00079 00080 template <class T > 00081 DYN_ARRAY<T>::~DYN_ARRAY() 00082 { 00083 Free_array(); 00084 } 00085 00086 /* must guarantee a min. non-zero size */ 00087 template <class T> 00088 void 00089 DYN_ARRAY<T>::Alloc_array(mUINT32 arr_size) 00090 { 00091 _size = arr_size > MIN_ARRAY_SIZE ? arr_size : MIN_ARRAY_SIZE; 00092 _array = (T*)MEM_POOL_Alloc(_mpool, _size * sizeof(T)); 00093 if ( _array == NULL ) ErrMsg ( EC_No_Mem, "DYN_ARRAY::Alloc_array" ); 00094 } 00095 00096 /* min. size is 1, instead of MIN_ARRAY_SIZE */ 00097 template <class T> 00098 void 00099 DYN_ARRAY<T>::Force_Alloc_array (mUINT32 arr_size) 00100 { 00101 _size = arr_size > 1 ? arr_size : 1; 00102 _array = (T*)MEM_POOL_Alloc(_mpool, _size * sizeof(T)); 00103 if ( _array == NULL ) ErrMsg ( EC_No_Mem, "DYN_ARRAY::Alloc_array" ); 00104 } 00105 00106 template <class T> 00107 void 00108 DYN_ARRAY<T>::Realloc_array(mUINT32 new_size) 00109 { 00110 _array = (T*)MEM_POOL_Realloc(_mpool, 00111 _array, 00112 sizeof(T) * _size, 00113 sizeof(T) * new_size); 00114 if ( _array == NULL ) ErrMsg ( EC_No_Mem, "DYN_ARRAY::Realloc_array" ); 00115 _size = new_size; 00116 } 00117 00118 template <class T> 00119 void 00120 DYN_ARRAY<T>::Free_array() 00121 { 00122 if (_array != NULL) { 00123 MEM_POOL_FREE(_mpool,_array); 00124 _array = NULL; 00125 _size = 0; 00126 } 00127 } 00128 00129 template <class T> 00130 void 00131 DYN_ARRAY<T>::Bzero_array() 00132 { 00133 if (_array != NULL) bzero(_array,sizeof(T) * _size); 00134 } 00135 00136 template <class T> 00137 DYN_ARRAY<T>& 00138 DYN_ARRAY<T>::operator = (const DYN_ARRAY<T>& a) 00139 { 00140 if (_size != a._size) Realloc_array(a._size); 00141 _lastidx = a._lastidx; 00142 memcpy (_array, a._array, a._size * sizeof(T)); 00143 return *this; 00144 } 00145 00146 template <class T > 00147 mUINT32 00148 DYN_ARRAY<T>::Newidx() 00149 { 00150 _lastidx++; 00151 if (_lastidx >= _size) { 00152 // overflow the allocated array, resize the array 00153 if (_array == NULL) { 00154 Alloc_array (MIN_ARRAY_SIZE); // Alloc_array guarantees non-zero size 00155 } else { 00156 Realloc_array (_size * 2); 00157 } 00158 } 00159 return _lastidx; 00160 } 00161 00162 template <class T > 00163 void 00164 DYN_ARRAY<T>::Initidx(UINT32 idx) 00165 { 00166 _lastidx=idx; 00167 if (_lastidx >= _size) { 00168 // overflow the allocated array, resize the array 00169 if (_array != NULL) { 00170 Free_array(); 00171 } 00172 Alloc_array(_lastidx + 1); 00173 } 00174 } 00175 00176 template <class T > 00177 void 00178 DYN_ARRAY<T>::Setidx(UINT32 idx) 00179 { 00180 _lastidx=idx; 00181 if (_lastidx >= _size) { 00182 // overflow the allocated array, resize the array 00183 if (_array == 0) 00184 Alloc_array(_lastidx + 1); 00185 else { 00186 INT32 new_size = _size * 2; 00187 while (new_size < _lastidx + 1) new_size *= 2; 00188 Realloc_array(new_size); 00189 } 00190 } 00191 } 00192 00193 template <class T> 00194 void STACK<T>::Settop(const T& val) 00195 { 00196 INT32 idx = _stack.Lastidx(); 00197 00198 Is_True(idx >= 0, ("STACK::Settop(): Stack Empty")); 00199 _stack[idx] = val; 00200 } 00201 00202 00203 template <class T> 00204 T& STACK<T>::Top_nth(const INT32 n) const 00205 { 00206 INT32 idx = _stack.Lastidx(); 00207 00208 Is_True(idx >= n, ("STACK::Top_nth(): Access beyond stack bottom")); 00209 return _stack[idx - n]; 00210 } 00211 00212 00213 template <class T> 00214 T& STACK<T>::Bottom_nth(const INT32 n) const 00215 { 00216 INT32 idx = _stack.Lastidx(); 00217 00218 Is_True(n <= idx, ("STACK::Bottom_nth(): Access beyond stack top")); 00219 return _stack[n]; 00220 } 00221 00222 00223 template <class T> 00224 T& STACK<T>::Top(void) const 00225 { 00226 INT32 idx = _stack.Lastidx(); 00227 00228 Is_True(idx >= 0, ("STACK::Top(): Stack Empty")); 00229 return _stack[idx]; 00230 } 00231 00232 template <class T> 00233 BOOL STACK<T>::Is_Empty(void) const 00234 { 00235 return _stack.Lastidx() < 0; 00236 } 00237 00238 00239 template <class CONTAINER, class PREDICATE> 00240 void Remove_if(CONTAINER& container, PREDICATE predicate) 00241 { 00242 CONTAINER::CONTAINER_NODE *prev = NULL, *curr, *next; 00243 for (curr = container.Head(); curr != NULL; curr = next) { 00244 next = curr->Next(); 00245 if (predicate(curr)) { 00246 if (prev == NULL) 00247 container.Set_Head(next); 00248 else 00249 prev->Set_Next(next); 00250 } else { 00251 prev = curr; 00252 } 00253 } 00254 if (prev == NULL) 00255 container.Set_Tail(container.Head()); 00256 else 00257 container.Set_Tail(prev); 00258 } 00259 #endif