From df1c3a78ba4aa715391175eceab6a7677f24feb9 Mon Sep 17 00:00:00 2001 From: Michael Ochmann Date: Sun, 5 Mar 2023 17:36:24 +0100 Subject: [PATCH] code quality: consolidated helpers to single header --- main.cpp | 6 +++--- src/QR.cpp | 1 + src/QR.hpp | 7 ++----- src/util.hpp | 12 ++++++++++++ 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 src/util.hpp diff --git a/main.cpp b/main.cpp index bcf4613..aa51d11 100644 --- a/main.cpp +++ b/main.cpp @@ -3,10 +3,10 @@ #include #include -#include "qrcodegen.hpp" -#include "QR.hpp" +#include -#define UNUSED(var) (void) var; +#include "util.hpp" +#include "QR.hpp" // Version is injected through cmake constexpr const char* VERSION = "@qr_VERSION@"; diff --git a/src/QR.cpp b/src/QR.cpp index 5be5764..9187701 100644 --- a/src/QR.cpp +++ b/src/QR.cpp @@ -14,6 +14,7 @@ namespace massivedynamic { QR::QR(const std::string& data, std::string outputFile, size_t size, qrcodegen::QrCode::Ecc type) : outputFile(std::move(outputFile)), qr(qrcodegen::QrCode::encodeText(data.c_str(), type)), size(size) { + this->pixels.reserve(this->qr.getSize() * this->qr.getSize()); // this is inherently stupid, but "qrcodegen::QrCode" does not give access to the // `segments` vector member and the class itself is marked final. for (int y = 0; y < qr.getSize(); y++) { diff --git a/src/QR.hpp b/src/QR.hpp index 2c3fd00..d7ba957 100644 --- a/src/QR.hpp +++ b/src/QR.hpp @@ -2,15 +2,12 @@ #include #include +#include -#include "qrcodegen.hpp" +#include "util.hpp" #include "Renderer.hpp" -#define UNUSED_CASE(name) case name: break; - namespace massivedynamic { - typedef uint32_t Color; - enum class Format { CONSOLE, SVG, diff --git a/src/util.hpp b/src/util.hpp new file mode 100644 index 0000000..e0ee9c7 --- /dev/null +++ b/src/util.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +#define UNUSED(var) (void) var; +#define UNUSED_CASE(name) case name: break; + +namespace massivedynamic { + + using Color = uint32_t; + +} \ No newline at end of file