aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-04-04 11:04:41 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:58 +0200
commita93270968f9aab5d8c1c528daf02c8b27d09eed7 (patch)
tree471394acdf19139a606ca68e558f84dc45ab5171
parent9e61e23ad2ac72030f14ea59e502c19d52995f3a (diff)
refactor: fix compiler errors with libc++
-rw-r--r--src/bootstrap.cpp8
-rw-r--r--src/engine/user/cursor.hpp2
-rw-r--r--src/engine/user/input.hpp1
-rw-r--r--src/game_of_life.cpp4
-rw-r--r--src/interfaces/randomization.hpp4
-rw-r--r--src/randomization/seed_generator.cpp10
-rw-r--r--src/randomization/seed_generator.hpp12
7 files changed, 14 insertions, 27 deletions
diff --git a/src/bootstrap.cpp b/src/bootstrap.cpp
index f22c689..276b73a 100644
--- a/src/bootstrap.cpp
+++ b/src/bootstrap.cpp
@@ -56,6 +56,7 @@ auto bootstrap() noexcept -> Container
container.bind<ICursorController>().to<CursorController>();
container.bind<ICLIGameEngine>().to<CLIGameEngine>();
container.bind<IWindow>().to<Window>();
+ container.bind<ISeedGenerator>().to<SeedGenerator>();
container.bind<IGameFactory>().to_factory(normalize_lambda(
[&container](const std::shared_ptr<IWindow> &window,
@@ -82,13 +83,6 @@ auto bootstrap() noexcept -> Container
seed);
});
- container.bind<ISeedGeneratorFactory>().to_factory(
- []()
- {
- return construct_as_interface<ISeedGenerator, SeedGenerator>(
- std::make_shared<std::random_device>());
- });
-
container.bind<IMatrixFactory<std::string_view>>().to_factory(
[](const Bounds &bounds)
{
diff --git a/src/engine/user/cursor.hpp b/src/engine/user/cursor.hpp
index ccdf71a..fcdfd3b 100644
--- a/src/engine/user/cursor.hpp
+++ b/src/engine/user/cursor.hpp
@@ -5,11 +5,11 @@
#include "engine/data/vector2.hpp"
-#include <array>
#include <fmt/core.h>
#include <memory>
#include <string_view>
#include <unordered_map>
+#include <vector>
constexpr std::string_view MOVE_CURSOR_UP = "{esc}[{amount}A";
constexpr std::string_view MOVE_CURSOR_DOWN = "{esc}[{amount}B";
diff --git a/src/engine/user/input.hpp b/src/engine/user/input.hpp
index 66b58c6..410f3a6 100644
--- a/src/engine/user/input.hpp
+++ b/src/engine/user/input.hpp
@@ -4,6 +4,7 @@
#include "interfaces/input.hpp"
#include "interfaces/subscriber.hpp"
+#include <array>
#include <climits>
#include <memory>
#include <termios.h>
diff --git a/src/game_of_life.cpp b/src/game_of_life.cpp
index 1daf5b8..098ec32 100644
--- a/src/game_of_life.cpp
+++ b/src/game_of_life.cpp
@@ -20,13 +20,13 @@ auto main(int argc, char *argv[]) noexcept -> int
if (parsed_arguments.random_gen == nullptr)
{
- auto seed_generator_factory = container.get<ISeedGeneratorFactory>();
+ auto seed_generator = container.get<ISeedGenerator>();
auto random_number_generator_factory =
container.get<IRandomNumberGeneratorFactory>();
parsed_arguments.random_gen =
- random_number_generator_factory(seed_generator_factory()->random_seed());
+ random_number_generator_factory(seed_generator->random_seed());
}
auto engine = container.get<ICLIGameEngine>();
diff --git a/src/interfaces/randomization.hpp b/src/interfaces/randomization.hpp
index eb8bd30..8b1631c 100644
--- a/src/interfaces/randomization.hpp
+++ b/src/interfaces/randomization.hpp
@@ -8,11 +8,9 @@ class ISeedGenerator
public:
virtual ~ISeedGenerator() noexcept = default;
- [[nodiscard]] virtual auto random_seed() const noexcept -> uint32_t = 0;
+ [[nodiscard]] virtual auto random_seed() noexcept -> uint32_t = 0;
};
-using ISeedGeneratorFactory = std::shared_ptr<ISeedGenerator> (*)();
-
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
class IRandomNumberGenerator
{
diff --git a/src/randomization/seed_generator.cpp b/src/randomization/seed_generator.cpp
index 5aedf17..a0f9303 100644
--- a/src/randomization/seed_generator.cpp
+++ b/src/randomization/seed_generator.cpp
@@ -1,12 +1,6 @@
#include "seed_generator.hpp"
-SeedGenerator::SeedGenerator(
- const std::shared_ptr<std::random_device> &random_device) noexcept
- : _random_device(random_device)
+auto SeedGenerator::random_seed() noexcept -> uint32_t
{
-}
-
-auto SeedGenerator::random_seed() const noexcept -> uint32_t
-{
- return (*_random_device)();
+ return _random_device();
}
diff --git a/src/randomization/seed_generator.hpp b/src/randomization/seed_generator.hpp
index 2439949..71fd089 100644
--- a/src/randomization/seed_generator.hpp
+++ b/src/randomization/seed_generator.hpp
@@ -1,18 +1,18 @@
#pragma once
+#include "DI/auto_wirable.hpp"
#include "interfaces/randomization.hpp"
-#include <memory>
#include <random>
-class SeedGenerator : public ISeedGenerator
+class SeedGenerator : public ISeedGenerator,
+ public AutoWirable<ISeedGenerator, SeedGenerator>
{
public:
- explicit SeedGenerator(
- const std::shared_ptr<std::random_device> &random_device) noexcept;
+ SeedGenerator() noexcept = default;
- [[nodiscard]] auto random_seed() const noexcept -> uint32_t override;
+ [[nodiscard]] auto random_seed() noexcept -> uint32_t override;
private:
- const std::shared_ptr<std::random_device> &_random_device;
+ std::random_device _random_device;
};