Added library demo
This commit is contained in:
parent
9293f97021
commit
67386adad2
152
Demo/Demo.vcxproj
Normal file
152
Demo/Demo.vcxproj
Normal file
@ -0,0 +1,152 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{b2ae1ac2-8d6a-4990-a6a7-e96e3ae6e6ea}</ProjectGuid>
|
||||
<RootNamespace>Demo</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\QRCodeLibrary\QRCodeLibrary.vcxproj">
|
||||
<Project>{b1126767-cdf7-4831-8b08-85bf457db4e2}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
22
Demo/Demo.vcxproj.filters
Normal file
22
Demo/Demo.vcxproj.filters
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
101
Demo/main.cpp
Normal file
101
Demo/main.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
#include <iostream>
|
||||
#include <locale>
|
||||
#include <Windows.h>
|
||||
|
||||
#include "../QRCodeLibrary/QRCode.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
std::string cp1251_to_utf8(const char* str)
|
||||
{
|
||||
std::string res;
|
||||
WCHAR* ures = NULL;
|
||||
char* cres = NULL;
|
||||
|
||||
int result_u = MultiByteToWideChar(1251, 0, str, -1, 0, 0);
|
||||
if (result_u != 0)
|
||||
{
|
||||
ures = new WCHAR[result_u];
|
||||
if (MultiByteToWideChar(1251, 0, str, -1, ures, result_u))
|
||||
{
|
||||
int result_c = WideCharToMultiByte(CP_UTF8, 0, ures, -1, 0, 0, 0, 0);
|
||||
if (result_c != 0)
|
||||
{
|
||||
cres = new char[result_c];
|
||||
if (WideCharToMultiByte(CP_UTF8, 0, ures, -1, cres, result_c, 0, 0))
|
||||
{
|
||||
res = cres;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete[] ures;
|
||||
delete[] cres;
|
||||
|
||||
return res;
|
||||
}
|
||||
#else
|
||||
string str_of(unsigned k, const string input) {
|
||||
string res;
|
||||
for (;k > 0; k--)
|
||||
res += input;
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
SetConsoleCP(1251);
|
||||
#endif
|
||||
|
||||
string input;
|
||||
|
||||
getline(cin, input);
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
input = cp1251_to_utf8(input.c_str());
|
||||
#endif
|
||||
|
||||
QRCode qr(input);
|
||||
|
||||
const auto& res = qr.to_vector();
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
const string long_sep = string((res.size() + 8) * 2, 219),
|
||||
short_sep = string(4 * 2, 219),
|
||||
black = string(2, 219),
|
||||
white = " ";
|
||||
|
||||
SetConsoleCP(855);
|
||||
#else
|
||||
const string long_sep = str_of((res.size() + 8) * 2, "█"),
|
||||
short_sep = str_of(4 * 2, "█"),
|
||||
black = str_of(2, "█"),
|
||||
white = " ";
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
cout << long_sep << endl;
|
||||
|
||||
for (unsigned i = 0; i < res.size(); i++) {
|
||||
cout << short_sep;
|
||||
for (auto cell : res[i])
|
||||
switch (cell) {
|
||||
case Trit::T:
|
||||
cout << white;
|
||||
break;
|
||||
case Trit::F:
|
||||
cout << black;
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Empty cell is not allowed. Your QR code is corrupted.");
|
||||
}
|
||||
cout << short_sep << endl;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
cout << long_sep << endl;
|
||||
}
|
@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QRCodeLibrary", "QRCodeLibr
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "tests\tests.vcxproj", "{96CDAF28-007A-4900-B24E-E21676713543}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo\Demo.vcxproj", "{B2AE1AC2-8D6A-4990-A6A7-E96E3AE6E6EA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@ -31,6 +33,14 @@ Global
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Release|x64.Build.0 = Release|x64
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Release|x86.ActiveCfg = Release|Win32
|
||||
{96CDAF28-007A-4900-B24E-E21676713543}.Release|x86.Build.0 = Release|Win32
|
||||
{B2AE1AC2-8D6A-4990-A6A7-E96E3AE6E6EA}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{B2AE1AC2-8D6A-4990-A6A7-E96E3AE6E6EA}.Debug|x64.Build.0 = Debug|x64
|
||||
{B2AE1AC2-8D6A-4990-A6A7-E96E3AE6E6EA}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{B2AE1AC2-8D6A-4990-A6A7-E96E3AE6E6EA}.Debug|x86.Build.0 = Debug|Win32
|
||||
{B2AE1AC2-8D6A-4990-A6A7-E96E3AE6E6EA}.Release|x64.ActiveCfg = Release|x64
|
||||
{B2AE1AC2-8D6A-4990-A6A7-E96E3AE6E6EA}.Release|x64.Build.0 = Release|x64
|
||||
{B2AE1AC2-8D6A-4990-A6A7-E96E3AE6E6EA}.Release|x86.ActiveCfg = Release|Win32
|
||||
{B2AE1AC2-8D6A-4990-A6A7-E96E3AE6E6EA}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -57,7 +57,7 @@ private:
|
||||
};
|
||||
|
||||
template <typename T, unsigned N>
|
||||
constexpr unsigned char upper_index(const array<T, N> arr, T val) {
|
||||
constexpr unsigned upper_index(const array<T, N> arr, T val) {
|
||||
unsigned count = arr.size(), s = 0, e, step;
|
||||
|
||||
while (count > 0) {
|
||||
|
@ -7,29 +7,29 @@
|
||||
/* upper_index function */
|
||||
|
||||
TEST(UpperIndexTests, FindsExactMatch) {
|
||||
array<int, 5> arr1{ 1, 2, 3, 4, 5 };
|
||||
array<unsigned, 5> arr1{ 1, 2, 3, 4, 5 };
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
for (unsigned i = 0; i < 5; i++)
|
||||
EXPECT_EQ(upper_index(arr1, i+1), i);
|
||||
|
||||
array<int, 4> arr2{ 1, 2, 3, 4 };
|
||||
array<unsigned, 4> arr2{ 1, 2, 3, 4 };
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (unsigned i = 0; i < 4; i++)
|
||||
EXPECT_EQ(upper_index(arr2, i + 1), i);
|
||||
}
|
||||
|
||||
TEST(UpperIndexTests, FindsClosestUpper) {
|
||||
array<int, 5> arr{ 1, 3, 5, 7, 9 };
|
||||
array<unsigned, 5> arr{ 1, 3, 5, 7, 9 };
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
for (unsigned i = 0; i < 5; i++)
|
||||
EXPECT_EQ(upper_index(arr, i * 2), i);
|
||||
}
|
||||
|
||||
TEST(UpperIndexTests, IfNothingFoundReturnsArrSize) {
|
||||
array<int, 5> arr{ 0, 1, 2, 3, 4 };
|
||||
array<unsigned, 5> arr{ 0, 1, 2, 3, 4 };
|
||||
|
||||
EXPECT_EQ(upper_index(arr, 5), 5);
|
||||
EXPECT_EQ(upper_index(arr, 10), 5);
|
||||
EXPECT_EQ(upper_index(arr, 5u), 5);
|
||||
EXPECT_EQ(upper_index(arr, 10u), 5);
|
||||
}
|
||||
|
||||
/* Encoder class */
|
||||
|
Loading…
x
Reference in New Issue
Block a user