Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / lib / utl / src / BL_BoundedArray.h
/*
* ========== Copyright Header Begin ==========================================
*
* OpenSPARC T2 Processor File: BL_BoundedArray.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
*
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
*
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ========== Copyright Header End ============================================
*/
#ifndef __BL_BoundedArray_h__
#define __BL_BoundedArray_h__
#include <assert.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
// Bounded array template. Takes the type of the array elements and
// the array's length as template arguments. Provides range checked
// operator[] methods.
template<typename TYPE, uint64_t SIZE, bool DO_INIT=false> class BL_BoundedArray
{
public:
BL_BoundedArray()
{
!DO_INIT || memset(0);
}
~BL_BoundedArray() {}
TYPE& operator[](uint64_t ndx)
{
assert(ndx < SIZE);
return array[ndx];
}
const TYPE& operator[](uint64_t ndx) const
{
assert(ndx < SIZE);
return array[ndx];
}
TYPE* memset(int c, size_t n = 0)
{
if (n == 0)
n = SIZE;
::memset(array, c, n * sizeof(TYPE));
return array;
}
private:
TYPE array[SIZE];
};
#endif /* __BL_BoundedArray_h__ */