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