BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / udf / Array.h
blob2f2f6ee1e21d55b2a6af62cb31dde1ffc6e156e3
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 /*! \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
16 parameter.
18 template<typename DataType, uint32 arrayLength>
19 struct array {
20 public:
21 void dump() const {
22 for (uint32 i = 0; i < arrayLength; i++)
23 data[i].print();
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> {
39 void dump() const
41 const uint8 bytesPerRow = 8;
42 char classname[40];
43 sprintf(classname, "array<uint8, %ld>", arrayLength);
45 DUMP_INIT(classname);
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)
52 SIMPLE_PRINT(("\n"));
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> {
65 void dump() const
67 const uint8 bytesPerRow = 8;
68 char classname[40];
69 sprintf(classname, "array<uint8, %ld>", arrayLength);
71 DUMP_INIT(classname);
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)
78 SIMPLE_PRINT(("\n"));
82 uint32 length() const { return arrayLength; }
83 uint32 size() const { return arrayLength; }
84 uint8 data[arrayLength];
87 #endif // _UDF_ARRAY_H