File indexing completed on 2024-04-14 05:45:56

0001 /*
0002     This file is part of the Okteta Gui library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2003 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef OKTETA_OFFSETFORMAT_HPP
0010 #define OKTETA_OFFSETFORMAT_HPP
0011 
0012 // lib
0013 #include "oktetagui_export.hpp"
0014 
0015 namespace Okteta {
0016 
0017 /**
0018  * @author Friedrich W. H. Kossebau
0019  */
0020 
0021 class OKTETAGUI_EXPORT OffsetFormat
0022 {
0023 public:
0024     /** */
0025     using print = void (*)(char* Buffer, unsigned int Offset);
0026     /** */
0027     enum Format
0028     {
0029         Hexadecimal = 0,
0030         Decimal,
0031         Octal,
0032     };
0033     /** */
0034     static constexpr int MaxFormatWidth = 11;
0035 
0036 public:
0037     OffsetFormat() = delete;
0038     OffsetFormat(const OffsetFormat&) = delete;
0039     ~OffsetFormat() = delete;
0040 
0041     OffsetFormat& operator=(const OffsetFormat&) = delete;
0042 
0043 public:
0044     /** */
0045     static unsigned int codingWidth(int i);
0046     /** */
0047     static print printFunction(int i);
0048 
0049 public:
0050     static void printHexadecimalOffset(char* Buffer, unsigned int Offset);
0051     static void printHexadecimalSmallOffset(char* Buffer, unsigned int Offset);
0052     static void printDecimalOffset(char* Buffer, unsigned int Offset);
0053     static void printOctalOffset(char* Buffer, unsigned int Offset);
0054 
0055 private:
0056     /** */
0057     static const unsigned int CodingWidth[3]; // TODO: would sizeof(Coding} work?
0058     /** */
0059     static const print PrintFunction[3];
0060 };
0061 
0062 inline unsigned int OffsetFormat::codingWidth(int i)
0063 { return CodingWidth[i]; }
0064 
0065 inline OffsetFormat::print OffsetFormat::printFunction(int i)
0066 { return PrintFunction[i]; }
0067 
0068 }
0069 
0070 #endif