1 //////////////////////////////////////////////////////////////////////////////
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef fix_sized_array_h
26 #define fix_sized_array_h
28 ///////////////////////////////////////////////////////////////////////////
29 // Class FixArray<T> is a simple array type whose size is fixed
30 // at compile time. The array is allocated in a contiguious chunk.
31 ///////////////////////////////////////////////////////////////////////////
33 #include <AD/generic/generic.h> // Generic definitions
35 template<class T
, int Capacity
>
38 T array
[Capacity
]; // array of elements
41 //////////////////////////////////////////////////////////
42 // Constructor and destructors
43 //////////////////////////////////////////////////////////
47 //////////////////////////////////////////////////////////
49 //////////////////////////////////////////////////////////
50 inline int lo() const { return 0; }
51 inline int hi() const { return Capacity
-1; }
52 inline operator const T
* () const { return array
; }
53 inline operator T
* () { return array
; }
54 inline int length() const { return Capacity
; }
55 inline int capacity() const { return Capacity
; }
56 inline const T
& operator [] (int i
) const { return array
[i
]; }
57 inline T
& operator [] (int i
) { return array
[i
]; }
59 //////////////////////////////////////////////////////////
61 //////////////////////////////////////////////////////////
62 inline Ix
first () const { return Capacity
== 0 ? 0 : (Ix
)array
; }
63 inline Ix
last () const { return Capacity
== 0 ? 0 : array
+ Capacity
- 1; }
64 inline Ix
next (Ix i
) const { return i
>= (Ix
)(array
+ Capacity
) ? 0 :
66 inline Ix
prev (Ix i
) const { return i
<= (Ix
)array
? 0 : (((T
*)i
)-1); }
67 inline const T
& operator () (Ix i
) const { return *(T
*)i
; }
68 inline T
& operator () (Ix i
) { return *(T
*)i
; }