From 4627317bcd02231780b10c3c891e1e4d3182171a Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Tue, 27 May 2003 07:58:08 +0000 Subject: [PATCH] Initial checkin. Slightly more typesafe static array type than built-in arrays, with array length information stored implicitly (i.e. consuming no physical space in the actual struct) via the arrayLength template parameter. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3351 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/udf/Array.h | 83 +++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/add-ons/kernel/file_systems/udf/Array.h diff --git a/src/add-ons/kernel/file_systems/udf/Array.h b/src/add-ons/kernel/file_systems/udf/Array.h new file mode 100644 index 0000000000..f889c2a321 --- /dev/null +++ b/src/add-ons/kernel/file_systems/udf/Array.h @@ -0,0 +1,83 @@ +//---------------------------------------------------------------------- +// This software is part of the OpenBeOS distribution and is covered +// by the OpenBeOS license. +// +// Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net +//--------------------------------------------------------------------- + +#ifndef _UDF_ARRAY_H +#define _UDF_ARRAY_H + +#include "cpp.h" + +#include "SupportDefs.h" + +namespace UDF { + +/*! \brief Slightly more typesafe static array type than built-in arrays, + with array length information stored implicitly (i.e. consuming no + physical space in the actual struct) via the \c arrayLength template + parameter. +*/ +template +struct array { +public: + void dump() { + for (uint32 i = 0; i < arrayLength; i++) + data[i].print(); + } + uint32 length() const { return arrayLength; } + uint32 size() const { return arrayLength * sizeof(DataType); } + DataType data[arrayLength]; +}; + +/*! \brief \c uint8 specialization of the \c array template struct. +*/ +template +struct array { + void dump() + { + const uint8 bytesPerRow = 8; + char classname[40]; + sprintf(classname, "array", arrayLength); + + DUMP_INIT(CF_PUBLIC | CF_DUMP | CF_HIGH_VOLUME, classname); + + for (uint32 i = 0; i < arrayLength; i++) { + if (i % bytesPerRow == 0) + PRINT(("[%ld:%ld]: ", i, i+bytesPerRow-1)); + SIMPLE_PRINT(("0x%.2x ", data[i])); + if ((i+1) % bytesPerRow == 0 || i+1 == arrayLength) + SIMPLE_PRINT(("\n")); + } + } + uint8 data[arrayLength]; +}; + +/*! \brief \c char specialization of the \c array template struct. +*/ +template +struct array { + void dump() + { + const uint8 bytesPerRow = 8; + char classname[40]; + sprintf(classname, "array", arrayLength); + + DUMP_INIT(CF_PUBLIC | CF_DUMP | CF_HIGH_VOLUME, classname); + + for (uint32 i = 0; i < arrayLength; i++) { + if (i % bytesPerRow == 0) + PRINT(("[%ld:%ld]: ", i, i+bytesPerRow-1)); + SIMPLE_PRINT(("0x%.2x ", data[i])); + if ((i+1) % bytesPerRow == 0 || i+1 == arrayLength) + SIMPLE_PRINT(("\n")); + } + } + uint8 data[arrayLength]; +}; + + +}; // namespace UDF + +#endif // _UDF_ARRAY_H