// StaticArrays.h
//
// Copyright 1999 Diehl Graphsoft, Inc.
// All Rights Reserved.
//
// SourceSafe information for this version:
//    $Revision: 1 $
//    $Date: 6/06/00 6:13p $
//    $Author: Dave $

#ifndef _STATICARRAYS_H_
#define _STATICARRAYS_H_ 1

#pragma once

/* 
	Static Array Macro Templates
	----------------------------

    The standard static array macro is passed a type, length, and class name.
	This class always pins the index value to the array extents and breaks
	into the debugger when BUG is turned on if an out of range value is passed.
	IndexInRange allows you to check if an index is in range while looping
	through the array.
*/

//---------------------------------------------------------------------------------------
template <class T, int elems> class StaticArray
{
	public:
		StaticArray()				{ }

		T& operator[](int i)		{ 
			#if BUG
				DSTOPIF(!IndexInRange(i), (kStaticArrayToWhom | kNoNetDebug, "Array index %d out of bounds (0..%d)!\n", i, elems-1)); 
			#else
				DSTOPIF(!IndexInRange(i), (kStaticArrayToWhom, "Array index %d out of bounds (0..%d)!\n", i, elems-1)); 
			#endif
			return fBuf[PIN(i, 0, elems-1)]; 
		}

		const T& operator[](int i) const { 
			#if BUG
				DSTOPIF(!IndexInRange(i), (kStaticArrayToWhom | kNoNetDebug, "Array index %d out of bounds (0..%d)!\n", i, elems-1)); 
			#else
				DSTOPIF(!IndexInRange(i), (kStaticArrayToWhom, "Array index %d out of bounds (0..%d)!\n", i, elems-1)); 
			#endif
			return fBuf[PIN(i, 0, elems-1)]; 
		}

		bool IndexInRange(int i) const { return i >= 0 && i < elems; }

	private:
		T			fBuf[elems];
};

#define STATIC_ARRAY(DataType, elems, ClassName) \
	typedef StaticArray<DataType, elems>  ClassName

#define STATIC_ARRAY_DEBUGONLY(DataType, elems, ClassName) \
	typedef StaticArray<DataType, elems>  ClassName

//---------------------------------------------------------------------------------------
template <class T> struct List
{
	T v;
	T& operator[](long i)				{ return (&v)[i]; }
	const T& operator[](long i) const	{ return (&v)[i]; }
};

#define DEFINE_LISTSTRUCT(T)  typedef List<T> T##List


#endif // _STATICARRAYS_H_
