2 * Copyright, 2003, Tyler Dauwalder, tyler@dauwalder.net.
3 * Distributed under the terms of the MIT License.
10 #include "SupportDefs.h"
13 /*! \brief Slightly more typesafe static array type than built-in arrays,
14 with array length information stored implicitly (i.e. consuming no
15 physical space in the actual struct) via the \c arrayLength template
18 template<typename DataType
, uint32 arrayLength
>
22 for (uint32 i
= 0; i
< arrayLength
; i
++)
26 uint32
length() const { return arrayLength
; }
27 uint32
size() const { return arrayLength
* sizeof(DataType
); }
29 // This doesn't appear to work. I don't know why.
30 DataType
operator[] (int index
) const { return data
[index
]; }
32 DataType data
[arrayLength
];
36 /*! \brief \c uint8 specialization of the \c array template struct. */
37 template<uint32 arrayLength
>
38 struct array
<uint8
, arrayLength
> {
41 const uint8 bytesPerRow
= 8;
43 sprintf(classname
, "array<uint8, %ld>", arrayLength
);
47 for (uint32 i
= 0; i
< arrayLength
; i
++) {
48 if (i
% bytesPerRow
== 0)
49 PRINT(("[%ld:%ld]: ", i
, i
+ bytesPerRow
- 1));
50 SIMPLE_PRINT(("0x%.2x ", data
[i
]));
51 if ((i
+ 1) % bytesPerRow
== 0 || i
+ 1 == arrayLength
)
56 uint32
length() const { return arrayLength
; }
57 uint32
size() const { return arrayLength
; }
58 uint8 data
[arrayLength
];
62 /*! \brief \c char specialization of the \c array template struct. */
63 template<uint32 arrayLength
>
64 struct array
<char, arrayLength
> {
67 const uint8 bytesPerRow
= 8;
69 sprintf(classname
, "array<uint8, %ld>", arrayLength
);
73 for (uint32 i
= 0; i
< arrayLength
; i
++) {
74 if (i
% bytesPerRow
== 0)
75 PRINT(("[%ld:%ld]: ", i
, i
+ bytesPerRow
- 1));
76 SIMPLE_PRINT(("0x%.2x ", data
[i
]));
77 if ((i
+ 1) % bytesPerRow
== 0 || i
+ 1 == arrayLength
)
82 uint32
length() const { return arrayLength
; }
83 uint32
size() const { return arrayLength
; }
84 uint8 data
[arrayLength
];
87 #endif // _UDF_ARRAY_H