aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-18 19:31:03 +0100
committerHampusM <hampus@hampusmat.com>2022-02-18 19:31:03 +0100
commite206dc1cf625f28149c19eb4dfcbf495ef0efbb4 (patch)
treebdcc6152dbce14f27a17b1a33814b0f8e365969f /src
parent3e4d91b6b029374813cfd0900db1fa8984ad7aa3 (diff)
refactor: improve options of all kindsHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/app/stack.hpp2
-rw-r--r--src/app/stack.tpp2
-rw-r--r--src/conversion.cpp2
-rw-r--r--src/conversion.hpp2
-rw-r--r--src/engine/bounds.cpp5
-rw-r--r--src/engine/bounds.hpp4
-rw-r--r--src/engine/vector2.cpp2
-rw-r--r--src/engine/vector2.hpp4
-rw-r--r--src/mazerator.cpp6
-rw-r--r--src/random_generator.cpp5
-rw-r--r--src/random_generator.hpp5
11 files changed, 22 insertions, 17 deletions
diff --git a/src/app/stack.hpp b/src/app/stack.hpp
index 11f7405..aec6d5e 100644
--- a/src/app/stack.hpp
+++ b/src/app/stack.hpp
@@ -15,7 +15,7 @@ public:
*
* @param capacity The capacity of the stack
*/
- explicit Stack(uint64_t capacity);
+ explicit Stack(const uint64_t &capacity);
/**
* Pushes a item onto the stack.
diff --git a/src/app/stack.tpp b/src/app/stack.tpp
index bcdafc0..263da67 100644
--- a/src/app/stack.tpp
+++ b/src/app/stack.tpp
@@ -6,7 +6,7 @@
#include <stdexcept>
template <typename Item>
-Stack<Item>::Stack(uint64_t capacity)
+Stack<Item>::Stack(const uint64_t &capacity)
{
_items.reserve(capacity);
}
diff --git a/src/conversion.cpp b/src/conversion.cpp
index 71ba1b2..79b3587 100644
--- a/src/conversion.cpp
+++ b/src/conversion.cpp
@@ -3,7 +3,7 @@
#include <climits>
#include <stdexcept>
-unsigned int str_to_uint(std::string_view str)
+unsigned int str_to_uint(const std::string_view &str)
{
if (str.at(0) == '-')
{
diff --git a/src/conversion.hpp b/src/conversion.hpp
index 6da7606..4ae5b7c 100644
--- a/src/conversion.hpp
+++ b/src/conversion.hpp
@@ -10,4 +10,4 @@ constexpr unsigned int NUMBER_BASE = 10U;
* @param str A string that possibly is a unsigned integer
* @returns A unsigned integer
*/
-unsigned int str_to_uint(std::string_view str);
+unsigned int str_to_uint(const std::string_view &str);
diff --git a/src/engine/bounds.cpp b/src/engine/bounds.cpp
index 782fd02..aa54439 100644
--- a/src/engine/bounds.cpp
+++ b/src/engine/bounds.cpp
@@ -1,6 +1,9 @@
#include "bounds.hpp"
-Bounds::Bounds(BoundsOpts opts) : _width(opts.width), _height(opts.height) {}
+Bounds::Bounds(const BoundsOptions &options)
+ : _width(options.width), _height(options.height)
+{
+}
unsigned int Bounds::width() const
{
diff --git a/src/engine/bounds.hpp b/src/engine/bounds.hpp
index 964e73a..0cadb9d 100644
--- a/src/engine/bounds.hpp
+++ b/src/engine/bounds.hpp
@@ -2,7 +2,7 @@
#include "engine/vector2.hpp"
-struct BoundsOpts
+struct BoundsOptions
{
unsigned int width;
unsigned int height;
@@ -11,7 +11,7 @@ struct BoundsOpts
class Bounds
{
public:
- explicit Bounds(BoundsOpts opts);
+ explicit Bounds(const BoundsOptions &options);
[[nodiscard]] unsigned int width() const;
diff --git a/src/engine/vector2.cpp b/src/engine/vector2.cpp
index 2d2283b..8a5a3c1 100644
--- a/src/engine/vector2.cpp
+++ b/src/engine/vector2.cpp
@@ -2,7 +2,7 @@
#include <memory>
-Vector2::Vector2(Vector2Opts opts) : _x(opts.x), _y(opts.y) {}
+Vector2::Vector2(const Vector2Options &options) : _x(options.x), _y(options.y) {}
unsigned int Vector2::x() const
{
diff --git a/src/engine/vector2.hpp b/src/engine/vector2.hpp
index f69008f..e0c0d6b 100644
--- a/src/engine/vector2.hpp
+++ b/src/engine/vector2.hpp
@@ -2,7 +2,7 @@
#include <memory>
-struct Vector2Opts
+struct Vector2Options
{
unsigned int x;
unsigned int y;
@@ -17,7 +17,7 @@ public:
/**
* Creates a 2D vector.
*/
- explicit Vector2(Vector2Opts opts);
+ explicit Vector2(const Vector2Options &options);
/**
* Returns the X coordinate.
diff --git a/src/mazerator.cpp b/src/mazerator.cpp
index a073615..6866aaa 100644
--- a/src/mazerator.cpp
+++ b/src/mazerator.cpp
@@ -59,7 +59,7 @@ unsigned int get_uint_optarg(char arg, bool check_zero = false)
}
} // namespace
-const std::array<option, 8> options = {
+constexpr std::array<option, 8> options = {
option({"width", required_argument, nullptr, 'w'}),
option({"height", required_argument, nullptr, 'h'}),
option({"wall", required_argument, nullptr, 'W'}),
@@ -75,7 +75,7 @@ int main(int argc, char *argv[])
AppOptions app_options;
- BoundsOpts default_maze_bounds = {DEFAULT_MAZE_WIDTH, DEFAULT_MAZE_HEIGHT};
+ BoundsOptions default_maze_bounds = {DEFAULT_MAZE_WIDTH, DEFAULT_MAZE_HEIGHT};
app_options.maze_bounds = std::make_shared<Bounds>(default_maze_bounds);
@@ -177,7 +177,7 @@ int main(int argc, char *argv[])
app_options.random_gen->in_range(0, app_options.maze_bounds->height() - 1U));
}
- Vector2Opts start_coords = {.x = *start_x, .y = *start_y};
+ Vector2Options start_coords = {.x = *start_x, .y = *start_y};
app_options.start_coords = std::make_shared<Vector2>(start_coords);
diff --git a/src/random_generator.cpp b/src/random_generator.cpp
index 1f17a88..3fdc2d4 100644
--- a/src/random_generator.cpp
+++ b/src/random_generator.cpp
@@ -1,6 +1,6 @@
#include "random_generator.hpp"
-RandomNumberGenerator::RandomNumberGenerator(unsigned int seed)
+RandomNumberGenerator::RandomNumberGenerator(const unsigned int &seed)
{
this->_generator = std::make_unique<std::mt19937>(seed);
}
@@ -12,7 +12,8 @@ RandomNumberGenerator::RandomNumberGenerator()
this->_generator = std::make_unique<std::mt19937>(random_device());
}
-unsigned int RandomNumberGenerator::in_range(unsigned int a, unsigned int b)
+unsigned int RandomNumberGenerator::in_range(const unsigned int &a,
+ const unsigned int &b) const
{
auto random_distribution = std::uniform_int_distribution<unsigned int>(a, b);
diff --git a/src/random_generator.hpp b/src/random_generator.hpp
index 8788982..b4931d7 100644
--- a/src/random_generator.hpp
+++ b/src/random_generator.hpp
@@ -14,7 +14,7 @@ public:
*
* @param seed A number generation seed
*/
- explicit RandomNumberGenerator(unsigned int seed);
+ explicit RandomNumberGenerator(const unsigned int &seed);
/**
* Creates a pesudo-random number generator.
@@ -27,7 +27,8 @@ public:
* @param a A number lower than b
* @param b A number greater than a
*/
- unsigned int in_range(unsigned int a, unsigned int b);
+ [[nodiscard]] unsigned int in_range(const unsigned int &a,
+ const unsigned int &b) const;
private:
std::unique_ptr<std::mt19937> _generator;