00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2014 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 (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.accellera.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 CHANGE LOG AT END OF FILE 00025 *****************************************************************************/ 00026 00027 #ifndef SC_VECTOR_H 00028 #define SC_VECTOR_H 00029 00030 #include <vector> 00031 00032 namespace sc_core { 00033 00034 extern "C" { 00035 typedef int (*CFT)( const void*, const void* ); 00036 } 00037 00038 00039 // #define ACCESS(I) m_vector.at(I) // index checking 00040 #define ACCESS(I) m_vector[I] 00041 #define ADDR_ACCESS(I) (m_vector.size() != 0 ? &m_vector[I] : 0 ) 00042 00043 // ---------------------------------------------------------------------------- 00044 // CLASS : sc_pvector<T> 00045 // 00046 // Simple vector class. 00047 // ---------------------------------------------------------------------------- 00048 00049 template< class T > 00050 class sc_pvector 00051 { 00052 public: 00053 00054 typedef const T* const_iterator; 00055 typedef T* iterator; 00056 // typedef typename ::std::vector<T>::const_iterator const_iterator; 00057 // typedef typename ::std::vector<T>::iterator iterator; 00058 00059 sc_pvector( int alloc_n = 0 ) 00060 { 00061 } 00062 00063 sc_pvector( const sc_pvector<T>& rhs ) 00064 : m_vector( rhs.m_vector ) 00065 {} 00066 00067 ~sc_pvector() 00068 {} 00069 00070 00071 std::size_t size() const 00072 { return m_vector.size(); } 00073 00074 00075 iterator begin() 00076 { return (iterator) ADDR_ACCESS(0); } 00077 00078 const_iterator begin() const 00079 { return (const_iterator) ADDR_ACCESS(0); } 00080 00081 iterator end() 00082 { return static_cast<iterator> (ADDR_ACCESS(m_vector.size())); } 00083 00084 const_iterator end() const 00085 { 00086 return static_cast<const_iterator> (ADDR_ACCESS(m_vector.size())); 00087 } 00088 00089 00090 sc_pvector<T>& operator = ( const sc_pvector<T>& rhs ) 00091 { m_vector = rhs.m_vector; return *this; } 00092 00093 00094 T& operator [] ( unsigned int i ) 00095 { 00096 if ( i >= m_vector.size() ) m_vector.resize(i+1); 00097 return (T&) m_vector.operator [] ( i ); 00098 } 00099 00100 const T& operator [] ( unsigned int i ) const 00101 { 00102 if ( i >= m_vector.size() ) m_vector.resize(i+1); 00103 return (const T&) m_vector.operator [] ( i ); 00104 } 00105 00106 T& fetch( int i ) 00107 { return ACCESS(i); } 00108 00109 const T& fetch( int i ) const 00110 { return (const T&) ACCESS(i); } 00111 00112 00113 T* raw_data() 00114 { return (T*) &ACCESS(0); } 00115 00116 const T* raw_data() const 00117 { return (const T*) &ACCESS(0); } 00118 00119 00120 operator const ::std::vector<T>& () const 00121 { return m_vector; } 00122 00123 void push_back( T item ) 00124 { m_vector.push_back( item ); } 00125 00126 00127 void erase_all() 00128 { m_vector.resize(0); } 00129 00130 void sort( CFT compar ) 00131 {qsort( (void*)&m_vector[0], m_vector.size(), sizeof(void*), compar );} 00132 00133 /* These methods have been added from Ptr_Array */ 00134 00135 void put( T item, int i ) 00136 { ACCESS(i) = item; } 00137 00138 void decr_count() 00139 { m_vector.resize(m_vector.size()-1); } 00140 00141 void decr_count( int k ) 00142 { m_vector.resize(m_vector.size()-k); } 00143 00144 00145 00146 protected: 00147 mutable ::std::vector<T> m_vector; // Actual vector of pointers. 00148 }; 00149 00150 #undef ACCESS 00151 #undef ADDR_ACCESS 00152 00153 } // namespace sc_core 00154 00155 // $Log: sc_pvector.h,v $ 00156 // Revision 1.4 2011/08/26 20:46:19 acg 00157 // Andy Goodrich: moved the modification log to the end of the file to 00158 // eliminate source line number skew when check-ins are done. 00159 // 00160 // Revision 1.3 2011/02/18 20:38:44 acg 00161 // Andy Goodrich: Updated Copyright notice. 00162 // 00163 // Revision 1.2 2011/01/20 16:52:21 acg 00164 // Andy Goodrich: changes for IEEE 1666 2011. 00165 // 00166 // Revision 1.1 2010/12/07 20:11:45 acg 00167 // Andy Goodrich: moved sc_pvector class to new header file to allow the 00168 // use of sc_vector.h for Philipp Hartmann's new sc_vector class. 00169 // 00170 // Revision 1.4 2010/08/03 17:52:15 acg 00171 // Andy Goodrich: fix signature for size() method of sc_pvector. 00172 // 00173 // Revision 1.3 2008/10/09 21:20:33 acg 00174 // Andy Goodrich: fixed the way the end() methods calculate their results. 00175 // I had incorrectly cut and pasted code from the begin() method. 00176 // 00177 // Revision 1.2 2007/01/17 22:44:34 acg 00178 // Andy Goodrich: fix for Microsoft compiler. 00179 // 00180 // Revision 1.3 2006/01/13 18:53:11 acg 00181 // Andy Goodrich: Added $Log command so that CVS comments are reproduced in 00182 // the source. 00183 // 00184 00185 #endif