diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-06 13:29:10 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:54 +0200 |
commit | 0854ebbc0720c1691f2de661c4ce3467b71746c6 (patch) | |
tree | 6bede8baea394711056db7109f395e71e880e03d | |
parent | a285df324deb579d262ea7cf484de4d6b11b28e4 (diff) |
refactor: replace unsigned int with uint32_t
-rw-r--r-- | src/argument_parser.cpp | 2 | ||||
-rw-r--r-- | src/bootstrap.cpp | 2 | ||||
-rw-r--r-- | src/conversion.cpp | 4 | ||||
-rw-r--r-- | src/conversion.hpp | 8 | ||||
-rw-r--r-- | src/engine/graphics/string_matrix.cpp | 8 | ||||
-rw-r--r-- | src/engine/graphics/string_matrix.hpp | 8 | ||||
-rw-r--r-- | src/engine/user/cursor.hpp | 2 | ||||
-rw-r--r-- | src/engine/user/cursor.tpp | 2 | ||||
-rw-r--r-- | src/engine/user/input.cpp | 2 | ||||
-rw-r--r-- | src/interfaces/matrix.hpp | 4 | ||||
-rw-r--r-- | src/interfaces/randomization.hpp | 10 | ||||
-rw-r--r-- | src/randomization/generator.cpp | 7 | ||||
-rw-r--r-- | src/randomization/generator.hpp | 5 | ||||
-rw-r--r-- | src/randomization/seed_generator.cpp | 2 | ||||
-rw-r--r-- | src/randomization/seed_generator.hpp | 2 |
15 files changed, 33 insertions, 35 deletions
diff --git a/src/argument_parser.cpp b/src/argument_parser.cpp index 5ad23d7..16945f7 100644 --- a/src/argument_parser.cpp +++ b/src/argument_parser.cpp @@ -30,7 +30,7 @@ std::string_view get_str_optarg() * @param arg The current command-line argument character * @param check_zero Whether or not to make sure that the result is not zero */ -unsigned int get_uint_optarg(char arg, bool check_zero = false) +uint32_t get_uint_optarg(char arg, bool check_zero = false) { auto conversion_result = str_to_uint(get_str_optarg()); diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp index a0d8ab2..ddeba4d 100644 --- a/src/bootstrap.cpp +++ b/src/bootstrap.cpp @@ -41,7 +41,7 @@ Container bootstrap() container.bind<IInputConfigurator>().to<InputConfigurator>(); container.bind<IRandomNumberGeneratorFactory>().to_factory( - [](const unsigned int &seed) + [](const uint32_t &seed) { return std::dynamic_pointer_cast<IRandomNumberGenerator>( std::make_shared<RandomNumberGenerator>(seed)); diff --git a/src/conversion.cpp b/src/conversion.cpp index 5f9494f..26f2db2 100644 --- a/src/conversion.cpp +++ b/src/conversion.cpp @@ -3,7 +3,7 @@ #include <climits> #include <stdexcept> -ConversionResult<unsigned int> str_to_uint(const std::string_view &str) +ConversionResult<uint32_t> str_to_uint(const std::string_view &str) { if (!ctre::match<IS_VALID_UINT>(str)) { @@ -29,5 +29,5 @@ ConversionResult<unsigned int> str_to_uint(const std::string_view &str) return ConversionResult(false, 0U, "Out of range"); } - return ConversionResult(true, static_cast<unsigned int>(num)); + return ConversionResult(true, static_cast<uint32_t>(num)); } diff --git a/src/conversion.hpp b/src/conversion.hpp index 0bdf82d..6f13342 100644 --- a/src/conversion.hpp +++ b/src/conversion.hpp @@ -3,7 +3,7 @@ #include <ctre.hpp> #include <string_view> -constexpr unsigned int NUMBER_BASE = 10U; +constexpr uint32_t NUMBER_BASE = 10U; template <typename ResultType> class ConversionResult @@ -24,9 +24,9 @@ static constexpr auto IS_VALID_UINT = ctll::fixed_string("^[0-9]+$"); static constexpr auto IS_UINT_IN_RANGE = ctll::fixed_string("^[0-9]{1,19}$"); /** - * Converts a string to a unsigned integer. + * Converts a string to a uint32_teger. * - * @param str A string that possibly is a unsigned integer + * @param str A string that possibly is a uint32_teger * @returns A conversion result */ -ConversionResult<unsigned int> str_to_uint(const std::string_view &str); +ConversionResult<uint32_t> str_to_uint(const std::string_view &str); diff --git a/src/engine/graphics/string_matrix.cpp b/src/engine/graphics/string_matrix.cpp index 75d3700..b1db334 100644 --- a/src/engine/graphics/string_matrix.cpp +++ b/src/engine/graphics/string_matrix.cpp @@ -9,11 +9,11 @@ StringMatrix::StringMatrix(const Bounds &bounds) void StringMatrix::fill(std::string_view element) { - for (unsigned int row = 0U; row < _matrix.capacity(); row++) + for (uint32_t row = 0U; row < _matrix.capacity(); row++) { std::vector<std::string_view> row_vector = _matrix[row]; - for (unsigned int column = 0U; column < row_vector.capacity(); column++) + for (uint32_t column = 0U; column < row_vector.capacity(); column++) { _matrix[row][column] = element; } @@ -30,12 +30,12 @@ void StringMatrix::set(const Vector2 &pos, std::string_view element) _matrix[pos.get_y()][pos.get_x()] = element; } -unsigned int StringMatrix::rows() const +uint32_t StringMatrix::rows() const { return _rows; } -unsigned int StringMatrix::columns() const +uint32_t StringMatrix::columns() const { return _columns; } diff --git a/src/engine/graphics/string_matrix.hpp b/src/engine/graphics/string_matrix.hpp index 351053e..540d63b 100644 --- a/src/engine/graphics/string_matrix.hpp +++ b/src/engine/graphics/string_matrix.hpp @@ -46,16 +46,16 @@ public: /** * Returns the number of rows the matrix has. */ - [[nodiscard]] unsigned int rows() const override; + [[nodiscard]] uint32_t rows() const override; /** * Returns the number of columns the matrix has. */ - [[nodiscard]] unsigned int columns() const override; + [[nodiscard]] uint32_t columns() const override; private: std::vector<std::vector<std::string_view>> _matrix; - unsigned int _rows; - unsigned int _columns; + uint32_t _rows; + uint32_t _columns; }; diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp index 69d639a..70a2bf2 100644 --- a/src/engine/user/cursor.hpp +++ b/src/engine/user/cursor.hpp @@ -28,7 +28,7 @@ public: CursorController() = default; template <Direction::value_type direction> - constexpr void move(const unsigned int &amount) const; + constexpr void move(const uint32_t &amount) const; static void move_to(const Vector2 &pos); diff --git a/src/engine/user/cursor.tpp b/src/engine/user/cursor.tpp index 224418e..0743ae8 100644 --- a/src/engine/user/cursor.tpp +++ b/src/engine/user/cursor.tpp @@ -19,7 +19,7 @@ constexpr auto get_direction_format_map() } template <Direction::value_type direction> -constexpr void CursorController::move(const unsigned int &amount) const +constexpr void CursorController::move(const uint32_t &amount) const { constexpr auto direction_format_map = get_direction_format_map(); diff --git a/src/engine/user/input.cpp b/src/engine/user/input.cpp index e68f303..1dc7f63 100644 --- a/src/engine/user/input.cpp +++ b/src/engine/user/input.cpp @@ -46,7 +46,7 @@ void InputHandler::enter_raw_mode() auto raw_termios = termios(*_original_termios); - raw_termios.c_lflag &= static_cast<unsigned int>(~(ECHO | ICANON | ISIG)); + raw_termios.c_lflag &= static_cast<uint32_t>(~(ECHO | ICANON | ISIG)); tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw_termios); } diff --git a/src/interfaces/matrix.hpp b/src/interfaces/matrix.hpp index 8242b18..e0a92bf 100644 --- a/src/interfaces/matrix.hpp +++ b/src/interfaces/matrix.hpp @@ -36,12 +36,12 @@ public: /** * Returns the number of rows the matrix has. */ - [[nodiscard]] virtual unsigned int rows() const = 0; + [[nodiscard]] virtual uint32_t rows() const = 0; /** * Returns the number of columns the matrix has. */ - [[nodiscard]] virtual unsigned int columns() const = 0; + [[nodiscard]] virtual uint32_t columns() const = 0; }; template <typename Element> diff --git a/src/interfaces/randomization.hpp b/src/interfaces/randomization.hpp index 12f6486..a17efb4 100644 --- a/src/interfaces/randomization.hpp +++ b/src/interfaces/randomization.hpp @@ -7,13 +7,13 @@ class ISeedGenerator public: virtual ~ISeedGenerator() = default; - [[nodiscard]] virtual unsigned int random_seed() const = 0; + [[nodiscard]] virtual uint32_t random_seed() const = 0; }; using ISeedGeneratorFactory = std::shared_ptr<ISeedGenerator> (*)(); /** - * Pseudo-random unsigned integer generator. + * Pseudo-random uint32_teger generator. */ class IRandomNumberGenerator { @@ -26,9 +26,9 @@ public: * @param a A number lower than b * @param b A number greater than a */ - [[nodiscard]] virtual unsigned int in_range(const unsigned int &a, - const unsigned int &b) const = 0; + [[nodiscard]] virtual uint32_t in_range(const uint32_t &a, + const uint32_t &b) const = 0; }; using IRandomNumberGeneratorFactory = - std::shared_ptr<IRandomNumberGenerator> (*)(const unsigned int &seed); + std::shared_ptr<IRandomNumberGenerator> (*)(const uint32_t &seed); diff --git a/src/randomization/generator.cpp b/src/randomization/generator.cpp index b9bcb8a..56fbbf1 100644 --- a/src/randomization/generator.cpp +++ b/src/randomization/generator.cpp @@ -1,14 +1,13 @@ #include "generator.hpp" -RandomNumberGenerator::RandomNumberGenerator(const unsigned int &seed) +RandomNumberGenerator::RandomNumberGenerator(const uint32_t &seed) { this->_generator = std::make_unique<std::mt19937>(seed); } -unsigned int RandomNumberGenerator::in_range(const unsigned int &a, - const unsigned int &b) const +uint32_t RandomNumberGenerator::in_range(const uint32_t &a, const uint32_t &b) const { - auto random_distribution = std::uniform_int_distribution<unsigned int>(a, b); + auto random_distribution = std::uniform_int_distribution<uint32_t>(a, b); return random_distribution(*this->_generator); } diff --git a/src/randomization/generator.hpp b/src/randomization/generator.hpp index 3acfc98..35bd9eb 100644 --- a/src/randomization/generator.hpp +++ b/src/randomization/generator.hpp @@ -8,10 +8,9 @@ class RandomNumberGenerator : public IRandomNumberGenerator { public: - explicit RandomNumberGenerator(const unsigned int &seed); + explicit RandomNumberGenerator(const uint32_t &seed); - [[nodiscard]] unsigned int in_range(const unsigned int &a, - const unsigned int &b) const override; + [[nodiscard]] uint32_t in_range(const uint32_t &a, const uint32_t &b) const override; private: std::unique_ptr<std::mt19937> _generator; diff --git a/src/randomization/seed_generator.cpp b/src/randomization/seed_generator.cpp index fdb2b12..5d51e18 100644 --- a/src/randomization/seed_generator.cpp +++ b/src/randomization/seed_generator.cpp @@ -5,7 +5,7 @@ SeedGenerator::SeedGenerator(const std::shared_ptr<std::random_device> &random_d { } -unsigned int SeedGenerator::random_seed() const +uint32_t SeedGenerator::random_seed() const { return (*_random_device)(); } diff --git a/src/randomization/seed_generator.hpp b/src/randomization/seed_generator.hpp index 238fdbe..1447a8c 100644 --- a/src/randomization/seed_generator.hpp +++ b/src/randomization/seed_generator.hpp @@ -10,7 +10,7 @@ class SeedGenerator : public ISeedGenerator public: explicit SeedGenerator(const std::shared_ptr<std::random_device> &random_device); - [[nodiscard]] unsigned int random_seed() const override; + [[nodiscard]] uint32_t random_seed() const override; private: const std::shared_ptr<std::random_device> &_random_device; |