Simplify source file names and go from .c to .cpp
[haiku.git] / src / add-ons / kernel / file_systems / udf / Array.h
blob5a48e1371afd47393f321b2d99fd31a4d7e30628
1 /*
2 * Copyright, 2003, Tyler Dauwalder, tyler@dauwalder.net.
3 * Distributed under the terms of the MIT License.
4 */
6 #ifndef _UDF_ARRAY_H
7 #define _UDF_ARRAY_H
10 #include "SupportDefs.h"
11 #include "UdfDebug.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
18 parameter.
20 template<typename DataType, uint32 arrayLength>
21 struct array {
22 public:
23 void dump() const {
24 for (uint32 i = 0; i < arrayLength; i++)
25 data[i].print();
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> {
41 void dump() const
43 const uint8 bytesPerRow = 8;
44 char classname[40];
45 sprintf(classname, "array<uint8, %ld>", arrayLength);
47 DUMP_INIT(classname);
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)
54 SIMPLE_PRINT(("\n"));
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> {
67 void dump() const
69 const uint8 bytesPerRow = 8;
70 char classname[40];
71 sprintf(classname, "array<uint8, %ld>", arrayLength);
73 DUMP_INIT(classname);
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)
80 SIMPLE_PRINT(("\n"));
84 uint32 length() const { return arrayLength; }
85 uint32 size() const { return arrayLength; }
86 uint8 data[arrayLength];
89 #endif // _UDF_ARRAY_H