00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2005 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License Version 2.4 (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.systemc.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_vector.h -- Simple implementation of a vector class. 00021 00022 Original Author: Stan Y. Liao, Synopsys, Inc. 00023 00024 *****************************************************************************/ 00025 00026 /***************************************************************************** 00027 00028 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00029 changes you are making here. 00030 00031 Name, Affiliation, Date: 00032 Description of Modification: 00033 00034 *****************************************************************************/ 00035 00036 00037 #ifndef SC_VECTOR_H 00038 #define SC_VECTOR_H 00039 00040 #include <vector> 00041 00042 namespace sc_core { 00043 00044 extern "C" { 00045 typedef int (*CFT)( const void*, const void* ); 00046 } 00047 00048 00049 // #define ACCESS(I) m_vector.at(I) // index checking 00050 #define ACCESS(I) m_vector[I] 00051 00052 // ---------------------------------------------------------------------------- 00053 // CLASS : sc_pvector<T> 00054 // 00055 // Simple vector class. 00056 // ---------------------------------------------------------------------------- 00057 00058 template< class T > 00059 class sc_pvector 00060 { 00061 public: 00062 00063 typedef const T* const_iterator; 00064 typedef T* iterator; 00065 // typedef typename ::std::vector<T>::const_iterator const_iterator; 00066 // typedef typename ::std::vector<T>::iterator iterator; 00067 00068 sc_pvector( int alloc_n = 0 ) 00069 { 00070 } 00071 00072 sc_pvector( const sc_pvector<T>& rhs ) 00073 : m_vector( rhs.m_vector ) 00074 {} 00075 00076 ~sc_pvector() 00077 {} 00078 00079 00080 int size() const 00081 { return m_vector.size(); } 00082 00083 00084 iterator begin() 00085 { return (iterator) &ACCESS(0); } 00086 00087 const_iterator begin() const 00088 { return (const_iterator) &ACCESS(0); } 00089 00090 iterator end() 00091 { return (iterator) &ACCESS(m_vector.size()); } 00092 00093 const_iterator end() const 00094 { return (const iterator) &ACCESS(m_vector.size()); } 00095 00096 00097 sc_pvector<T>& operator = ( const sc_pvector<T>& rhs ) 00098 { m_vector = rhs.m_vector; return *this; } 00099 00100 00101 T& operator [] ( unsigned int i ) 00102 { 00103 if ( i >= m_vector.size() ) m_vector.resize(i+1); 00104 return (T&) m_vector.operator [] ( i ); 00105 } 00106 00107 const T& operator [] ( unsigned int i ) const 00108 { 00109 if ( i >= m_vector.size() ) m_vector.resize(i+1); 00110 return (const T&) m_vector.operator [] ( i ); 00111 } 00112 00113 T& fetch( int i ) 00114 { return ACCESS(i); } 00115 00116 const T& fetch( int i ) const 00117 { return (const T&) ACCESS(i); } 00118 00119 00120 T* raw_data() 00121 { return (T*) &ACCESS(0); } 00122 00123 const T* raw_data() const 00124 { return (const T*) &ACCESS(0); } 00125 00126 00127 operator const ::std::vector<T>& () const 00128 { return m_vector; } 00129 00130 void push_back( T item ) 00131 { m_vector.push_back( item ); } 00132 00133 00134 void erase_all() 00135 { m_vector.resize(0); } 00136 00137 void sort( CFT compar ) 00138 {qsort( (void*)&m_vector[0], m_vector.size(), sizeof(void*), compar );} 00139 00140 /* These methods have been added from Ptr_Array */ 00141 00142 void put( T item, int i ) 00143 { ACCESS(i) = item; } 00144 00145 void decr_count() 00146 { m_vector.resize(m_vector.size()-1); } 00147 00148 void decr_count( int k ) 00149 { m_vector.resize(m_vector.size()-k); } 00150 00151 00152 00153 protected: 00154 mutable ::std::vector<T> m_vector; // Actual vector of pointers. 00155 }; 00156 00157 #undef ACCESS 00158 00159 } // namespace sc_core 00160 00161 #endif