00001 //-*-c++-*- 00002 //===================================================================== 00003 // 00004 // Module: opt_array.h 00005 // $Revision: 1.1.1.1 $ 00006 // $Date: 2005/10/21 19:00:00 $ 00007 // $Author: marcel $ 00008 // $Source: /proj/osprey/CVS/open64/osprey1.0/be/opt/opt_array.h,v $ 00009 // 00010 // Revision history: 00011 // 01-MAR-95 dahl - Original Version 00012 // 00013 // ==================================================================== 00014 // 00015 // Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00016 // 00017 // This program is free software; you can redistribute it and/or modify 00018 // it under the terms of version 2 of the GNU General Public License as 00019 // published by the Free Software Foundation. 00020 // 00021 // This program is distributed in the hope that it would be useful, but 00022 // WITHOUT ANY WARRANTY; without even the implied warranty of 00023 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00024 // 00025 // Further, this software is distributed without any warranty that it 00026 // is free of the rightful claim of any third person regarding 00027 // infringement or the like. Any license provided herein, whether 00028 // implied or otherwise, applies only to this software file. Patent 00029 // licenses, if any, provided herein do not apply to combinations of 00030 // this program with other software, or any other product whatsoever. 00031 // 00032 // You should have received a copy of the GNU General Public License 00033 // along with this program; if not, write the Free Software Foundation, 00034 // Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00035 // 00036 // Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00037 // Mountain View, CA 94043, or: 00038 // 00039 // http://www.sgi.com 00040 // 00041 // For further information regarding this notice, see: 00042 // 00043 // http://oss.sgi.com/projects/GenInfo/NoticeExplan 00044 // 00045 // ==================================================================== 00046 // 00047 // Description: 00048 // template for fixed length arrays 00049 // 00050 //====================================================================== 00051 //====================================================================== 00052 00053 00054 #ifndef opt_array_INCLUDED 00055 #define opt_array_INCLUDED "opt_array.h" 00056 #ifdef _KEEP_RCS_ID 00057 00058 static char *opt_arrayrcs_id = opt_array_INCLUDED"$ $Revision$"; 00059 #endif /* _KEEP_RCS_ID */ 00060 00061 00062 // forward declaration 00063 typedef struct mem_pool MEM_POOL; 00064 00065 #include "defs.h" 00066 #include "opt_defs.h" 00067 #include "opt_sys.h" 00068 00069 00070 //---------------------------------------------------------------------------- 00071 // fixed size array template 00072 template <class TT> 00073 class ARRAY { 00074 00075 private: 00076 MEM_POOL *_mem_pool; // memory pool for array 00077 mUINT32 _size; // number of elements in array 00078 TT *_array; // the actual array 00079 00080 ARRAY<TT>(const ARRAY&); // PPP what is this ??? 00081 00082 public: 00083 00084 ARRAY(void); // default constructor 00085 ARRAY(MEM_POOL *pool) { _mem_pool = pool; 00086 _size = 0; 00087 _array = NULL; 00088 } 00089 ARRAY(mUINT32, MEM_POOL *); // constructor 00090 ~ARRAY(void) { } // destructor 00091 void Init(mUINT32 size); // Initialize array with size 00092 00093 MEM_POOL *Mem_Pool(void) { return _mem_pool; }// what pool is being used 00094 void Free_array(void); // free the arrays memory 00095 void Bzero_array(void); // zero out the array 00096 mUINT32 Size(void) const { return _size; } // size of the array 00097 TT& operator [] (mUINT32 idx) const { // access array by index idx 00098 Is_True(idx < _size,("ARRAY::[%d]:Subscript out of range %d",idx,_size)); 00099 return (_array[idx]); } 00100 TT& operator [] (mUINT32 idx) { // access array by index idx 00101 Is_True(idx < _size,("ARRAY::[%d]:Subscript out of range %d",idx,_size)); 00102 return (_array[idx]); } 00103 00104 }; // end of class ARRAY 00105 00106 00107 //---------------------------------------------------------------------------- 00108 // constructor 00109 // can be given a zero size to delay the allocation until later 00110 template <class TT> 00111 ARRAY<TT>::ARRAY(mUINT32 sz, MEM_POOL *mpool) 00112 { 00113 _mem_pool = mpool; 00114 _size = sz; 00115 if (_size > 0) { 00116 _array = (TT *)OPT_POOL_Alloc(_mem_pool, _size * sizeof(TT), 00117 MEM_DUMP_FLAG+15); 00118 if (_array == NULL) 00119 ErrMsg(EC_No_Mem,"ARRAY<TT>::Alloc_array"); 00120 Bzero_array(); 00121 } else 00122 _array = NULL; 00123 } 00124 00125 //---------------------------------------------------------------------------- 00126 // Initializer 00127 // can be given a size to allocate array 00128 template <class TT> 00129 void 00130 ARRAY<TT>::Init(mUINT32 size) 00131 { 00132 _size = size; 00133 if (_size > 0) { 00134 _array = (TT *)OPT_POOL_Alloc(_mem_pool, _size * sizeof(TT), 00135 MEM_DUMP_FLAG+15); 00136 if (_array == NULL) 00137 ErrMsg(EC_No_Mem,"ARRAY<TT>::Alloc_array"); 00138 Bzero_array(); 00139 } 00140 } 00141 00142 // free the array to the memory pool 00143 template <class TT> 00144 void 00145 ARRAY<TT>::Free_array(void) 00146 { 00147 if (_array != NULL) 00148 OPT_POOL_FREE(_mem_pool,_array, MEM_DUMP_FLAG+15); 00149 _size = 0; 00150 _mem_pool = _array = NULL; 00151 } 00152 00153 // zero out the array 00154 template <class TT> 00155 void 00156 ARRAY<TT>::Bzero_array(void) 00157 { 00158 if (_array != NULL) 00159 BZERO(_array,sizeof(TT) * _size); 00160 } 00161 00162 #endif //opt_array_INCLUDED
1.5.6