112027Sjungma@eit.uni-kl.de/*****************************************************************************
212027Sjungma@eit.uni-kl.de
312027Sjungma@eit.uni-kl.de  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412027Sjungma@eit.uni-kl.de  more contributor license agreements.  See the NOTICE file distributed
512027Sjungma@eit.uni-kl.de  with this work for additional information regarding copyright ownership.
612027Sjungma@eit.uni-kl.de  Accellera licenses this file to you under the Apache License, Version 2.0
712027Sjungma@eit.uni-kl.de  (the "License"); you may not use this file except in compliance with the
812027Sjungma@eit.uni-kl.de  License.  You may obtain a copy of the License at
912027Sjungma@eit.uni-kl.de
1012027Sjungma@eit.uni-kl.de    http://www.apache.org/licenses/LICENSE-2.0
1112027Sjungma@eit.uni-kl.de
1212027Sjungma@eit.uni-kl.de  Unless required by applicable law or agreed to in writing, software
1312027Sjungma@eit.uni-kl.de  distributed under the License is distributed on an "AS IS" BASIS,
1412027Sjungma@eit.uni-kl.de  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512027Sjungma@eit.uni-kl.de  implied.  See the License for the specific language governing
1612027Sjungma@eit.uni-kl.de  permissions and limitations under the License.
1712027Sjungma@eit.uni-kl.de
1812027Sjungma@eit.uni-kl.de *****************************************************************************/
1912027Sjungma@eit.uni-kl.de
2012027Sjungma@eit.uni-kl.de/*****************************************************************************
2112027Sjungma@eit.uni-kl.de
2212027Sjungma@eit.uni-kl.de  sc_vector.h -- Simple implementation of a vector class.
2312027Sjungma@eit.uni-kl.de
2412027Sjungma@eit.uni-kl.de  Original Author: Stan Y. Liao, Synopsys, Inc.
2512027Sjungma@eit.uni-kl.de
2612027Sjungma@eit.uni-kl.de  CHANGE LOG AT END OF FILE
2712027Sjungma@eit.uni-kl.de *****************************************************************************/
2812027Sjungma@eit.uni-kl.de
2912027Sjungma@eit.uni-kl.de#ifndef SC_VECTOR_H
3012027Sjungma@eit.uni-kl.de#define SC_VECTOR_H
3112027Sjungma@eit.uni-kl.de
3212027Sjungma@eit.uni-kl.de#include <vector>
3312027Sjungma@eit.uni-kl.de
3412027Sjungma@eit.uni-kl.denamespace sc_core {
3512027Sjungma@eit.uni-kl.de
3612027Sjungma@eit.uni-kl.deextern "C" {
3712027Sjungma@eit.uni-kl.de  typedef int (*CFT)( const void*, const void* );
3812027Sjungma@eit.uni-kl.de}
3912027Sjungma@eit.uni-kl.de
4012027Sjungma@eit.uni-kl.de
4112027Sjungma@eit.uni-kl.de// #define ACCESS(I) m_vector.at(I) // index checking
4212027Sjungma@eit.uni-kl.de#define ACCESS(I) m_vector[I]
4312027Sjungma@eit.uni-kl.de#define ADDR_ACCESS(I) (m_vector.size() != 0 ? &m_vector[I] : 0 )
4412027Sjungma@eit.uni-kl.de
4512027Sjungma@eit.uni-kl.de// ----------------------------------------------------------------------------
4612027Sjungma@eit.uni-kl.de//  CLASS : sc_pvector<T>
4712027Sjungma@eit.uni-kl.de//
4812027Sjungma@eit.uni-kl.de//  Simple vector class.
4912027Sjungma@eit.uni-kl.de// ----------------------------------------------------------------------------
5012027Sjungma@eit.uni-kl.de
5112027Sjungma@eit.uni-kl.detemplate< class T >
5212027Sjungma@eit.uni-kl.declass sc_pvector
5312027Sjungma@eit.uni-kl.de{
5412027Sjungma@eit.uni-kl.depublic:
5512027Sjungma@eit.uni-kl.de
5612027Sjungma@eit.uni-kl.de    typedef const T* const_iterator;
5712027Sjungma@eit.uni-kl.de    typedef       T* iterator;
5812027Sjungma@eit.uni-kl.de	// typedef typename ::std::vector<T>::const_iterator const_iterator;
5912027Sjungma@eit.uni-kl.de	// typedef typename ::std::vector<T>::iterator       iterator;
6012027Sjungma@eit.uni-kl.de
6112027Sjungma@eit.uni-kl.de    sc_pvector( int alloc_n = 0 )
6212027Sjungma@eit.uni-kl.de	{
6312027Sjungma@eit.uni-kl.de	}
6412027Sjungma@eit.uni-kl.de
6512027Sjungma@eit.uni-kl.de    sc_pvector( const sc_pvector<T>& rhs )
6612027Sjungma@eit.uni-kl.de	: m_vector( rhs.m_vector )
6712027Sjungma@eit.uni-kl.de	{}
6812027Sjungma@eit.uni-kl.de
6912027Sjungma@eit.uni-kl.de    ~sc_pvector()
7012027Sjungma@eit.uni-kl.de	{}
7112027Sjungma@eit.uni-kl.de
7212027Sjungma@eit.uni-kl.de
7312027Sjungma@eit.uni-kl.de    std::size_t size() const
7412027Sjungma@eit.uni-kl.de	{ return m_vector.size(); }
7512027Sjungma@eit.uni-kl.de
7612027Sjungma@eit.uni-kl.de
7712027Sjungma@eit.uni-kl.de    iterator begin()
7812027Sjungma@eit.uni-kl.de        { return (iterator) ADDR_ACCESS(0); }
7912027Sjungma@eit.uni-kl.de
8012027Sjungma@eit.uni-kl.de    const_iterator begin() const
8112027Sjungma@eit.uni-kl.de        { return (const_iterator) ADDR_ACCESS(0); }
8212027Sjungma@eit.uni-kl.de
8312027Sjungma@eit.uni-kl.de    iterator end()
8412027Sjungma@eit.uni-kl.de        { return static_cast<iterator> (ADDR_ACCESS(m_vector.size())); }
8512027Sjungma@eit.uni-kl.de
8612027Sjungma@eit.uni-kl.de    const_iterator end() const
8712027Sjungma@eit.uni-kl.de    {
8812027Sjungma@eit.uni-kl.de        return static_cast<const_iterator> (ADDR_ACCESS(m_vector.size()));
8912027Sjungma@eit.uni-kl.de    }
9012027Sjungma@eit.uni-kl.de
9112027Sjungma@eit.uni-kl.de
9212027Sjungma@eit.uni-kl.de    sc_pvector<T>& operator = ( const sc_pvector<T>& rhs )
9312027Sjungma@eit.uni-kl.de	{ m_vector = rhs.m_vector; return *this; }
9412027Sjungma@eit.uni-kl.de
9512027Sjungma@eit.uni-kl.de
9612027Sjungma@eit.uni-kl.de    T& operator [] ( unsigned int i )
9712027Sjungma@eit.uni-kl.de	{
9812027Sjungma@eit.uni-kl.de	    if ( i >= m_vector.size() ) m_vector.resize(i+1);
9912027Sjungma@eit.uni-kl.de	    return (T&) m_vector.operator [] ( i );
10012027Sjungma@eit.uni-kl.de	}
10112027Sjungma@eit.uni-kl.de
10212027Sjungma@eit.uni-kl.de    const T& operator [] ( unsigned int i ) const
10312027Sjungma@eit.uni-kl.de	{
10412027Sjungma@eit.uni-kl.de	    if ( i >= m_vector.size() ) m_vector.resize(i+1);
10512027Sjungma@eit.uni-kl.de	    return (const T&) m_vector.operator [] ( i );
10612027Sjungma@eit.uni-kl.de	}
10712027Sjungma@eit.uni-kl.de
10812027Sjungma@eit.uni-kl.de    T& fetch( int i )
10912027Sjungma@eit.uni-kl.de	{ return ACCESS(i); }
11012027Sjungma@eit.uni-kl.de
11112027Sjungma@eit.uni-kl.de    const T& fetch( int i ) const
11212027Sjungma@eit.uni-kl.de	{ return (const T&) ACCESS(i); }
11312027Sjungma@eit.uni-kl.de
11412027Sjungma@eit.uni-kl.de
11512027Sjungma@eit.uni-kl.de    T* raw_data()
11612027Sjungma@eit.uni-kl.de	{ return (T*) &ACCESS(0); }
11712027Sjungma@eit.uni-kl.de
11812027Sjungma@eit.uni-kl.de    const T* raw_data() const
11912027Sjungma@eit.uni-kl.de	{ return (const T*) &ACCESS(0); }
12012027Sjungma@eit.uni-kl.de
12112027Sjungma@eit.uni-kl.de
12212027Sjungma@eit.uni-kl.de    operator const ::std::vector<T>& () const
12312027Sjungma@eit.uni-kl.de        { return m_vector; }
12412027Sjungma@eit.uni-kl.de
12512027Sjungma@eit.uni-kl.de    void push_back( T item )
12612027Sjungma@eit.uni-kl.de	{ m_vector.push_back( item ); }
12712027Sjungma@eit.uni-kl.de
12812027Sjungma@eit.uni-kl.de
12912027Sjungma@eit.uni-kl.de    void erase_all()
13012027Sjungma@eit.uni-kl.de	{ m_vector.resize(0); }
13112027Sjungma@eit.uni-kl.de
13212027Sjungma@eit.uni-kl.de    void sort( CFT compar )
13312027Sjungma@eit.uni-kl.de	{qsort( (void*)&m_vector[0], m_vector.size(), sizeof(void*), compar );}
13412027Sjungma@eit.uni-kl.de
13512027Sjungma@eit.uni-kl.de    /* These methods have been added from Ptr_Array */
13612027Sjungma@eit.uni-kl.de
13712027Sjungma@eit.uni-kl.de    void put( T item, int i )
13812027Sjungma@eit.uni-kl.de	{ ACCESS(i) = item; }
13912027Sjungma@eit.uni-kl.de
14012027Sjungma@eit.uni-kl.de    void decr_count()
14112027Sjungma@eit.uni-kl.de	{ m_vector.resize(m_vector.size()-1); }
14212027Sjungma@eit.uni-kl.de
14312027Sjungma@eit.uni-kl.de    void decr_count( int k )
14412027Sjungma@eit.uni-kl.de	{ m_vector.resize(m_vector.size()-k); }
14512027Sjungma@eit.uni-kl.de
14612027Sjungma@eit.uni-kl.de
14712027Sjungma@eit.uni-kl.de
14812027Sjungma@eit.uni-kl.de  protected:
14912027Sjungma@eit.uni-kl.de    mutable ::std::vector<T> m_vector;    // Actual vector of pointers.
15012027Sjungma@eit.uni-kl.de};
15112027Sjungma@eit.uni-kl.de
15212027Sjungma@eit.uni-kl.de#undef ACCESS
15312027Sjungma@eit.uni-kl.de#undef ADDR_ACCESS
15412027Sjungma@eit.uni-kl.de
15512027Sjungma@eit.uni-kl.de} // namespace sc_core
15612027Sjungma@eit.uni-kl.de
15712027Sjungma@eit.uni-kl.de// $Log: sc_pvector.h,v $
15812027Sjungma@eit.uni-kl.de// Revision 1.4  2011/08/26 20:46:19  acg
15912027Sjungma@eit.uni-kl.de//  Andy Goodrich: moved the modification log to the end of the file to
16012027Sjungma@eit.uni-kl.de//  eliminate source line number skew when check-ins are done.
16112027Sjungma@eit.uni-kl.de//
16212027Sjungma@eit.uni-kl.de// Revision 1.3  2011/02/18 20:38:44  acg
16312027Sjungma@eit.uni-kl.de//  Andy Goodrich: Updated Copyright notice.
16412027Sjungma@eit.uni-kl.de//
16512027Sjungma@eit.uni-kl.de// Revision 1.2  2011/01/20 16:52:21  acg
16612027Sjungma@eit.uni-kl.de//  Andy Goodrich: changes for IEEE 1666 2011.
16712027Sjungma@eit.uni-kl.de//
16812027Sjungma@eit.uni-kl.de// Revision 1.1  2010/12/07 20:11:45  acg
16912027Sjungma@eit.uni-kl.de//  Andy Goodrich: moved sc_pvector class to new header file to allow the
17012027Sjungma@eit.uni-kl.de//  use of sc_vector.h for Philipp Hartmann's new sc_vector class.
17112027Sjungma@eit.uni-kl.de//
17212027Sjungma@eit.uni-kl.de// Revision 1.4  2010/08/03 17:52:15  acg
17312027Sjungma@eit.uni-kl.de//   Andy Goodrich: fix signature for size() method of sc_pvector.
17412027Sjungma@eit.uni-kl.de//
17512027Sjungma@eit.uni-kl.de// Revision 1.3  2008/10/09 21:20:33  acg
17612027Sjungma@eit.uni-kl.de//  Andy Goodrich: fixed the way the end() methods calculate their results.
17712027Sjungma@eit.uni-kl.de//  I had incorrectly cut and pasted code from the begin() method.
17812027Sjungma@eit.uni-kl.de//
17912027Sjungma@eit.uni-kl.de// Revision 1.2  2007/01/17 22:44:34  acg
18012027Sjungma@eit.uni-kl.de//  Andy Goodrich: fix for Microsoft compiler.
18112027Sjungma@eit.uni-kl.de//
18212027Sjungma@eit.uni-kl.de// Revision 1.3  2006/01/13 18:53:11  acg
18312027Sjungma@eit.uni-kl.de// Andy Goodrich: Added $Log command so that CVS comments are reproduced in
18412027Sjungma@eit.uni-kl.de// the source.
18512027Sjungma@eit.uni-kl.de//
18612027Sjungma@eit.uni-kl.de
18712027Sjungma@eit.uni-kl.de#endif
188