Summary Files Commits Branches @commit @diff @stats
path: root / src
diff options
context:
space:
mode:
Commit92630c6d0a1928e6f112013a45b9b681d55c1d63 (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-07-23 14:36:53 +0300
Committer
 Syndamia <kamen@syndamia.com>
2025-07-23 14:36:53 +0300
Files29de5b32bbd3424ffaec04672d028c84a1c6c9dc /src
screen-generator-nemetschek-92630c6d0a1928e6f112013a45b9b681d55c1d63.tar
screen-generator-nemetschek-92630c6d0a1928e6f112013a45b9b681d55c1d63.tar.gz
screen-generator-nemetschek-92630c6d0a1928e6f112013a45b9b681d55c1d63.zip
Parentd71c054e221013f5d5f24648ded514b475aed3df (diff)
feat: Check for invalid values in widths and heights
2 files changed, 64 insertions, 21 deletions
-rw-r--r--src/LEDVideoWall.cpp64
-rw-r--r--src/Television.cpp21
diff --git a/src/LEDVideoWall.cpp b/src/LEDVideoWall.cpp
index 45f66ba..f4f4e16 100644
--- a/src/LEDVideoWall.cpp
+++ b/src/LEDVideoWall.cpp
@@ -38,12 +38,20 @@ enum class LEDVideoWallType {
LEDVideoWall* LEDVideoWall::fromCommandLine() {
mm ipanel_width = 0, ipanel_height = 0;
- cli::scanTwoValues(
- "%dx%d",
- ipanel_width,
- ipanel_height,
- "Enter panel size (in the format 'WIDTHxHEIGHT'): ",
- "Invalid size, try again!");
+ do {
+ cli::scanTwoValues(
+ "%dx%d",
+ ipanel_width,
+ ipanel_height,
+ "Enter panel size (in the format 'WIDTHxHEIGHT'): ",
+ "Invalid size, try again!");
+
+ if (ipanel_width == 0 || ipanel_height == 0) {
+ std::cerr << "The panel width or height cannot be zero!" << std::endl;
+ continue;
+ }
+ break;
+ } while (true);
unsigned int itype = 2;
cli::readUserInputMax(
@@ -56,24 +64,42 @@ LEDVideoWall* LEDVideoWall::fromCommandLine() {
switch (type) {
case LEDVideoWallType::Freeform: {
mm iwall_max_width = 0, iwall_max_height = 0;
- cli::scanTwoValues(
- "%dx%d",
- iwall_max_width,
- iwall_max_height,
- "Enter singe wall size (in the format 'WIDTHxHEIGHT'): ",
- "Invalid size, try again!");
+ do {
+ cli::scanTwoValues(
+ "%dx%d",
+ iwall_max_width,
+ iwall_max_height,
+ "Enter singe wall size (in the format 'WIDTHxHEIGHT'): ",
+ "Invalid size, try again!");
+
+ if (iwall_max_width == 0 || iwall_max_height == 0) {
+ std::cerr << "The wall width or height cannot be zero!" << std::endl;
+ continue;
+ }
+ if (iwall_max_width < panel_width || iwall_max_height < panel_height) {
+ std::cerr << "The wall cannot be smaller than the panel!" << std::endl;
+ continue;
+ }
+ } while (true);
return LEDVideoWall::Freeform(ipanel_width, ipanel_height, iwall_max_width, iwall_max_height);
};
case LEDVideoWallType::Aspect: {
- mm i_width = 0, i_height = 0;
- cli::scanTwoValues(
- "%d:%d",
- i_width,
- i_height,
- "Enter aspect ratio (in the format 'width:height'): ",
- "Invalid input, try again!");
+ mm iaspect_width = 0, iaspect_height = 0;
+ do {
+ cli::scanTwoValues(
+ "%d:%d",
+ iaspect_width,
+ iaspect_height,
+ "Enter aspect ratio (in the format 'WIDTH:HEIGHT'): ",
+ "Invalid input, try again!");
+
+ if (iaspect_width == 0 || iaspect_height == 0) {
+ std::cerr << "The aspect ratio width or height cannot be zero!" << std::endl;
+ continue;
+ }
+ } while (true);
return LEDVideoWall::Aspect(ipanel_width, ipanel_height, i_width, i_height);
};
diff --git a/src/Television.cpp b/src/Television.cpp
index 35f1d46..b682211 100644
--- a/src/Television.cpp
+++ b/src/Television.cpp
@@ -1,5 +1,6 @@
#include "Television.h"
#include "cli.hpp"
+#include <iostream>
Television::Television(mm width, mm height) : Screen(width, height) { }
@@ -7,10 +8,26 @@ Television::~Television() { }
Television* Television::fromCommandLine() {
mm iwidth = 0;
- cli::readUserInput(iwidth, "Enter width (in mm): ", "Invalid width, try again!");
+ do {
+ cli::readUserInput(iwidth, "Enter width (in mm): ", "Invalid width, try again!");
+
+ if (iwidth == 0) {
+ std::cerr << "Width cannot be zero! Try again!" << std::endl;
+ continue;
+ }
+ break;
+ } while (true);
mm iheight = 0;
- cli::readUserInput(iheight, "Enter height (in mm): ", "Invalid height, try again!");
+ do {
+ cli::readUserInput(iheight, "Enter height (in mm): ", "Invalid height, try again!");
+ if (iheight == 0) {
+ std::cerr << "Height cannot be zero! Try again!" << std::endl;
+ continue;
+ }
+ break;
+ }
+ while (true);
return new Television(iwidth, iheight);
}