From 1627abc431166942842eace83debf08a4abea84e Mon Sep 17 00:00:00 2001 From: noffie Date: Sun, 12 Jan 2025 19:02:19 +0100 Subject: [PATCH] allowing count selection --- src/main.cpp | 17 ++++++++++++++++- src/sortiva/sortiva.cpp | 16 ++++++++++------ src/sortiva/sortiva.hpp | 4 +++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3fb7b8d..9e636db 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,29 @@ #include #include "sortiva/sortiva.hpp" +#include //#undef _DEBUG int main(int argc, char** argv) { + uint8_t CountValues = 5; + for (int i = 0; i < argc; ++i) + { + std::string arg = argv[i]; + if (arg == "-n") + { + if (i + 1 < argc) + { + arg = argv[++i]; + CountValues = static_cast(std::stoi(arg)); + } + } + } + printf("Darling, I'm Home!\n"); #ifdef _DEBUG try { #endif - Sortiva app; + Sortiva app(CountValues); app.run(); #ifdef _DEBUG } diff --git a/src/sortiva/sortiva.cpp b/src/sortiva/sortiva.cpp index 98abe72..a83a7c3 100644 --- a/src/sortiva/sortiva.cpp +++ b/src/sortiva/sortiva.cpp @@ -9,8 +9,7 @@ #include -Sortiva::Sortiva() : m_Ticker(std::chrono::seconds(1)) -{ +void Sortiva::init() { m_Sorter.set(m_List); m_Steps = std::make_unique(); @@ -28,6 +27,13 @@ Sortiva::Sortiva() : m_Ticker(std::chrono::seconds(1)) MaximizeWindow(); } +Sortiva::Sortiva(uint8_t count) : m_Ticker(std::chrono::seconds(1)) { + init(); + count--; + m_CountValues = count % 7; + m_CountValues++; +} + Sortiva::~Sortiva() { CloseWindow(); @@ -60,10 +66,8 @@ void Sortiva::setup() m_Steps->clear(); m_List.list.clear(); - uint16_t count = 5; - - for (int i = 1; i <= count; ++i) // 1,2,3,4,5 + for (uint8_t i = 1; i <= m_CountValues; ++i) // 1,2,3,4,5 { m_List.list.push_back(i); m_Steps->emplace_back(); @@ -74,7 +78,7 @@ void Sortiva::setup() std::ranges::shuffle(m_List.list, rng); // 2,3,1,5,4 - for (int i = 1; i <= count; ++i) + for (uint8_t i = 1; i <= m_CountValues; ++i) { m_Steps->at(m_List.at(i - 1) - 1).value = i; } diff --git a/src/sortiva/sortiva.hpp b/src/sortiva/sortiva.hpp index 4edd67f..df1328a 100644 --- a/src/sortiva/sortiva.hpp +++ b/src/sortiva/sortiva.hpp @@ -52,7 +52,7 @@ public: class Sortiva final { public: - Sortiva(); + Sortiva(uint8_t); ~Sortiva(); void run(); @@ -66,7 +66,9 @@ private: void update(double); void setup(); + void init(); + uint8_t m_CountValues; bool m_SortingFinished = true; TickSystem m_Ticker; Bubble_Sorter m_Sorter;