1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 sc_vector.h -- Simple implementation of a vector class. 23 24 Original Author: Stan Y. Liao, Synopsys, Inc. 25 26 CHANGE LOG AT END OF FILE 27 *****************************************************************************/ 28 29#ifndef SC_VECTOR_H 30#define SC_VECTOR_H 31 32#include <vector> 33 34namespace sc_core { 35 36extern "C" { 37 typedef int (*CFT)( const void*, const void* ); 38} 39 40 41// #define ACCESS(I) m_vector.at(I) // index checking 42#define ACCESS(I) m_vector[I] 43#define ADDR_ACCESS(I) (m_vector.size() != 0 ? &m_vector[I] : 0 ) 44 45// ---------------------------------------------------------------------------- 46// CLASS : sc_pvector<T> 47// 48// Simple vector class. 49// ---------------------------------------------------------------------------- 50 51template< class T > 52class sc_pvector 53{ 54public: 55 56 typedef const T* const_iterator; 57 typedef T* iterator; 58 // typedef typename ::std::vector<T>::const_iterator const_iterator; 59 // typedef typename ::std::vector<T>::iterator iterator; 60 61 sc_pvector( int alloc_n = 0 ) 62 { 63 } 64 65 sc_pvector( const sc_pvector<T>& rhs ) 66 : m_vector( rhs.m_vector ) 67 {} 68 69 ~sc_pvector() 70 {} 71 72 73 std::size_t size() const 74 { return m_vector.size(); } 75 76 77 iterator begin() 78 { return (iterator) ADDR_ACCESS(0); } 79 80 const_iterator begin() const 81 { return (const_iterator) ADDR_ACCESS(0); } 82 83 iterator end() 84 { return static_cast<iterator> (ADDR_ACCESS(m_vector.size())); } 85 86 const_iterator end() const 87 { 88 return static_cast<const_iterator> (ADDR_ACCESS(m_vector.size())); 89 } 90 91 92 sc_pvector<T>& operator = ( const sc_pvector<T>& rhs ) 93 { m_vector = rhs.m_vector; return *this; } 94 95 96 T& operator [] ( unsigned int i ) 97 { 98 if ( i >= m_vector.size() ) m_vector.resize(i+1); 99 return (T&) m_vector.operator [] ( i ); 100 } 101 102 const T& operator [] ( unsigned int i ) const 103 { 104 if ( i >= m_vector.size() ) m_vector.resize(i+1); 105 return (const T&) m_vector.operator [] ( i ); 106 } 107 108 T& fetch( int i ) 109 { return ACCESS(i); } 110 111 const T& fetch( int i ) const 112 { return (const T&) ACCESS(i); } 113 114 115 T* raw_data() 116 { return (T*) &ACCESS(0); } 117 118 const T* raw_data() const 119 { return (const T*) &ACCESS(0); } 120 121 122 operator const ::std::vector<T>& () const 123 { return m_vector; } 124 125 void push_back( T item ) 126 { m_vector.push_back( item ); } 127 128 129 void erase_all() 130 { m_vector.resize(0); } 131 132 void sort( CFT compar ) 133 {qsort( (void*)&m_vector[0], m_vector.size(), sizeof(void*), compar );} 134 135 /* These methods have been added from Ptr_Array */ 136 137 void put( T item, int i ) 138 { ACCESS(i) = item; } 139 140 void decr_count() 141 { m_vector.resize(m_vector.size()-1); } 142 143 void decr_count( int k ) 144 { m_vector.resize(m_vector.size()-k); } 145 146 147 148 protected: 149 mutable ::std::vector<T> m_vector; // Actual vector of pointers. 150}; 151 152#undef ACCESS 153#undef ADDR_ACCESS 154 155} // namespace sc_core 156 157// $Log: sc_pvector.h,v $ 158// Revision 1.4 2011/08/26 20:46:19 acg 159// Andy Goodrich: moved the modification log to the end of the file to 160// eliminate source line number skew when check-ins are done. 161// 162// Revision 1.3 2011/02/18 20:38:44 acg 163// Andy Goodrich: Updated Copyright notice. 164// 165// Revision 1.2 2011/01/20 16:52:21 acg 166// Andy Goodrich: changes for IEEE 1666 2011. 167// 168// Revision 1.1 2010/12/07 20:11:45 acg 169// Andy Goodrich: moved sc_pvector class to new header file to allow the 170// use of sc_vector.h for Philipp Hartmann's new sc_vector class. 171// 172// Revision 1.4 2010/08/03 17:52:15 acg 173// Andy Goodrich: fix signature for size() method of sc_pvector. 174// 175// Revision 1.3 2008/10/09 21:20:33 acg 176// Andy Goodrich: fixed the way the end() methods calculate their results. 177// I had incorrectly cut and pasted code from the begin() method. 178// 179// Revision 1.2 2007/01/17 22:44:34 acg 180// Andy Goodrich: fix for Microsoft compiler. 181// 182// Revision 1.3 2006/01/13 18:53:11 acg 183// Andy Goodrich: Added $Log command so that CVS comments are reproduced in 184// the source. 185// 186 187#endif 188