2 * Copyright, 2003, Tyler Dauwalder, tyler@dauwalder.net.
3 * Distributed under the terms of the MIT License.
10 #include "SupportDefs.h"
13 #include <util/kernel_cpp.h>
15 /*! \brief Slightly more typesafe static array type than built-in arrays,
16 with array length information stored implicitly (i.e. consuming no
17 physical space in the actual struct) via the \c arrayLength template
20 template<typename DataType
, uint32 arrayLength
>
24 for (uint32 i
= 0; i
< arrayLength
; i
++)
28 uint32
length() const { return arrayLength
; }
29 uint32
size() const { return arrayLength
* sizeof(DataType
); }
31 // This doesn't appear to work. I don't know why.
32 DataType
operator[] (int index
) const { return data
[index
]; }
34 DataType data
[arrayLength
];
38 /*! \brief \c uint8 specialization of the \c array template struct. */
39 template<uint32 arrayLength
>
40 struct array
<uint8
, arrayLength
> {
43 const uint8 bytesPerRow
= 8;
45 sprintf(classname
, "array<uint8, %ld>", arrayLength
);
49 for (uint32 i
= 0; i
< arrayLength
; i
++) {
50 if (i
% bytesPerRow
== 0)
51 PRINT(("[%ld:%ld]: ", i
, i
+ bytesPerRow
- 1));
52 SIMPLE_PRINT(("0x%.2x ", data
[i
]));
53 if ((i
+ 1) % bytesPerRow
== 0 || i
+ 1 == arrayLength
)
58 uint32
length() const { return arrayLength
; }
59 uint32
size() const { return arrayLength
; }
60 uint8 data
[arrayLength
];
64 /*! \brief \c char specialization of the \c array template struct. */
65 template<uint32 arrayLength
>
66 struct array
<char, arrayLength
> {
69 const uint8 bytesPerRow
= 8;
71 sprintf(classname
, "array<uint8, %ld>", arrayLength
);
75 for (uint32 i
= 0; i
< arrayLength
; i
++) {
76 if (i
% bytesPerRow
== 0)
77 PRINT(("[%ld:%ld]: ", i
, i
+ bytesPerRow
- 1));
78 SIMPLE_PRINT(("0x%.2x ", data
[i
]));
79 if ((i
+ 1) % bytesPerRow
== 0 || i
+ 1 == arrayLength
)
84 uint32
length() const { return arrayLength
; }
85 uint32
size() const { return arrayLength
; }
86 uint8 data
[arrayLength
];
89 #endif // _UDF_ARRAY_H