code quality: deleted copy & move constructors

pull/1/head
Michael Ochmann 2 years ago
parent 576bdf8430
commit 98b1cddd79
  1. 2
      src/QR.cpp
  2. 4
      src/QR.hpp
  3. 3
      src/Renderer.hpp
  4. 10
      src/renderers/PixelRenderer.hpp

@ -1,6 +1,6 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <assert.h> #include <cassert>
#include "QR.hpp" #include "QR.hpp"

@ -28,6 +28,10 @@ namespace massivedynamic {
std::unordered_map<Format, std::unique_ptr<Renderer>> renderers; std::unordered_map<Format, std::unique_ptr<Renderer>> renderers;
public: public:
QR(const std::string& data, std::string outputFile, size_t size, qrcodegen::QrCode::Ecc type); QR(const std::string& data, std::string outputFile, size_t size, qrcodegen::QrCode::Ecc type);
QR(const QR&&) = delete;
QR(QR&) = delete;
~QR() = default;
void render(Format format); void render(Format format);
}; };

@ -11,7 +11,10 @@ class Renderer {
size_t targetSize; size_t targetSize;
public: public:
Renderer(const std::vector<bool>& pixels, size_t sourceSize, size_t targetSize) : pixels(pixels), sourceSize(sourceSize), targetSize(targetSize) {} Renderer(const std::vector<bool>& pixels, size_t sourceSize, size_t targetSize) : pixels(pixels), sourceSize(sourceSize), targetSize(targetSize) {}
Renderer(const Renderer&&) = delete;
Renderer(Renderer&) = delete;
virtual ~Renderer() = default; virtual ~Renderer() = default;
virtual void render(const std::string& filename) = 0; virtual void render(const std::string& filename) = 0;
}; };

@ -2,6 +2,7 @@
#include <math.h> #include <math.h>
#include <iostream> #include <iostream>
#include <cassert>
#include "Renderer.hpp" #include "Renderer.hpp"
#define STB_IMAGE_WRITE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION
@ -19,10 +20,7 @@ namespace massivedynamic {
void drawPixelScaled(size_t x, size_t y, Color color) { void drawPixelScaled(size_t x, size_t y, Color color) {
size_t pixelSize = this->pixelSize; size_t pixelSize = this->pixelSize;
if (pixelSize < 1) { assert(pixelSize > 1 && "ERROR: output file size is too small");
std::cerr << "ERROR: output file size is too small" << std::endl;
exit(1);
}
size_t absoluteX = pixelSize * x + this->border; size_t absoluteX = pixelSize * x + this->border;
size_t absoluteY = pixelSize * y + this->border; size_t absoluteY = pixelSize * y + this->border;
@ -42,12 +40,12 @@ namespace massivedynamic {
PixelRenderer(const std::vector<bool>& pixels, size_t sourceSize, size_t targetSize) : Renderer(pixels, sourceSize, targetSize), pixelSize(0) { PixelRenderer(const std::vector<bool>& pixels, size_t sourceSize, size_t targetSize) : Renderer(pixels, sourceSize, targetSize), pixelSize(0) {
this->targetSize = this->targetSize == 0 ? (sourceSize + 2) * 2 : this->targetSize; this->targetSize = this->targetSize == 0 ? (sourceSize + 2) * 2 : this->targetSize;
this->pixelSize = round(static_cast<float>(this->targetSize) / static_cast<float>(this->sourceSize + 2)); this->pixelSize = round(static_cast<float>(this->targetSize) / static_cast<float>(this->sourceSize + 2));
this->border = round((this->targetSize - this->pixelSize * this->sourceSize) / 2); this->border = round(static_cast<float>(this->targetSize - this->pixelSize * this->sourceSize) / 2.0f);
this->bitmap = std::vector<Color>(this->targetSize * this->targetSize, Colors::WHITE); this->bitmap = std::vector<Color>(this->targetSize * this->targetSize, Colors::WHITE);
} }
void generateBuffer() { virtual void generateBuffer() {
for (size_t y = 0; y < sourceSize; y++) { for (size_t y = 0; y < sourceSize; y++) {
for (size_t x = 0; x < sourceSize; x++) { for (size_t x = 0; x < sourceSize; x++) {
if (!pixels.at(y * sourceSize + x)) if (!pixels.at(y * sourceSize + x))

Loading…
Cancel
Save