Switched from class to namespace for Tables organization

This commit is contained in:
Dmitriy Shishkov 2021-12-12 16:25:27 +03:00
parent 8c464edb2e
commit 3d98710648
4 changed files with 25 additions and 41 deletions

View File

@ -172,7 +172,6 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="QRCode.cpp" />
<ClCompile Include="Tables.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -50,9 +50,6 @@
<ClCompile Include="Method.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Tables.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Encoder.cpp">
<Filter>Source Files</Filter>
</ClCompile>

View File

@ -1,30 +0,0 @@
#include "pch.h"
#include "Tables.hpp"
const std::array<char, 45> Tables::alphabetic{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*',
'+', '-', '.', '/', ':'
};
const std::map<CorrectionLevel, const std::array<unsigned, 20>> Tables::max_capability{
{ CorrectionLevel::L, {{152, 272, 440, 640, 864, 1088, 1248, 1552, 1856, 2192, 2592, 2960, 3424, 3688, 4184, 4712, 5176, 5768, 6360, 6888}} },
{ CorrectionLevel::M, {{128, 224, 352, 512, 688, 864, 992, 1232, 1456, 1728, 2032, 2320, 2672, 2920, 3320, 3624, 4056, 4504, 5016, 5352}} },
{ CorrectionLevel::Q, {{104, 176, 272, 384, 496, 608, 704, 880, 1056, 1232, 1440, 1648, 1952, 2088, 2360, 2600, 2936, 3176, 3560, 3880}} },
{ CorrectionLevel::H, {{72, 128, 208, 288, 368, 480, 528, 688, 800, 976, 1120, 1264, 1440, 1576, 1784, 2024, 2264, 2504, 2728, 3080}} }
};
const std::map<QRCodeMethod, unsigned char> Tables::mode_indicator{
{ QRCodeMethod::Numeric, 0b0001 },
{ QRCodeMethod::Alphabetic, 0b0010 },
{ QRCodeMethod::Byte, 0b0100 }
};
const std::map<QRCodeMethod, const std::array<const std::pair<unsigned char, unsigned char>, 3>> Tables::data_amount_lengths{
{ QRCodeMethod::Numeric, {{ {0, 10}, {8, 12}, {25, 14} }} },
{ QRCodeMethod::Alphabetic, {{ {0, 9}, {8, 11}, {25, 13} }} } ,
{ QRCodeMethod::Byte, {{ {0, 8}, {8, 16}, {25, 16} }} }
};

View File

@ -5,12 +5,30 @@
#include "Method.hpp"
class Tables {
public:
static const std::array<char, 45>alphabetic;
static const std::map<CorrectionLevel, const std::array<unsigned, 20>>max_capability;
static const std::map<QRCodeMethod, unsigned char>mode_indicator;
static const std::map<QRCodeMethod, const std::array<const std::pair<unsigned char, unsigned char>, 3>>data_amount_lengths;
namespace Tables {
static const std::array<char, 45> alphabetic{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*',
'+', '-', '.', '/', ':'
};
static const std::map<CorrectionLevel, const std::array<unsigned, 20>> max_capability{
{ CorrectionLevel::L, {{152, 272, 440, 640, 864, 1088, 1248, 1552, 1856, 2192, 2592, 2960, 3424, 3688, 4184, 4712, 5176, 5768, 6360, 6888}} },
{ CorrectionLevel::M, {{128, 224, 352, 512, 688, 864, 992, 1232, 1456, 1728, 2032, 2320, 2672, 2920, 3320, 3624, 4056, 4504, 5016, 5352}} },
{ CorrectionLevel::Q, {{104, 176, 272, 384, 496, 608, 704, 880, 1056, 1232, 1440, 1648, 1952, 2088, 2360, 2600, 2936, 3176, 3560, 3880}} },
{ CorrectionLevel::H, {{72, 128, 208, 288, 368, 480, 528, 688, 800, 976, 1120, 1264, 1440, 1576, 1784, 2024, 2264, 2504, 2728, 3080}} }
};
static const std::map<QRCodeMethod, unsigned char> mode_indicator{
{ QRCodeMethod::Numeric, 0b0001 },
{ QRCodeMethod::Alphabetic, 0b0010 },
{ QRCodeMethod::Byte, 0b0100 }
};
static const std::map<QRCodeMethod, const std::array<const std::pair<unsigned char, unsigned char>, 3>> data_amount_lengths{
{ QRCodeMethod::Numeric, {{ {0, 10}, {8, 12}, {25, 14} }} },
{ QRCodeMethod::Alphabetic, {{ {0, 9}, {8, 11}, {25, 13} }} } ,
{ QRCodeMethod::Byte, {{ {0, 8}, {8, 16}, {25, 16} }} }
};
}