From 5d0cba2b45aa30226ba72231b35424d404a5eec1 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 15 Nov 2022 00:37:54 +0100 Subject: Implemented naive skeleton for types repository in universe --- universe/CMakeLists.txt | 7 +++- universe/include/kurator/universe.h | 18 +++++++++ universe/include/kurator/universe/NotFound.h | 24 ++++++++++++ universe/include/kurator/universe/Repository.h | 25 +++++++++++++ universe/src/NotFound.cpp | 27 ++++++++++++++ universe/src/SampleRepository.cpp | 51 ++++++++++++++++++++++++++ universe/src/SampleRepository.h | 25 +++++++++++++ universe/src/universe.cpp | 24 ++++++++++++ 8 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 universe/include/kurator/universe.h create mode 100644 universe/include/kurator/universe/NotFound.h create mode 100644 universe/include/kurator/universe/Repository.h create mode 100644 universe/src/NotFound.cpp create mode 100644 universe/src/SampleRepository.cpp create mode 100644 universe/src/SampleRepository.h create mode 100644 universe/src/universe.cpp (limited to 'universe') diff --git a/universe/CMakeLists.txt b/universe/CMakeLists.txt index 24457c5..bb7253f 100644 --- a/universe/CMakeLists.txt +++ b/universe/CMakeLists.txt @@ -1,8 +1,11 @@ project(universe) add_library( - ${PROJECT_NAME} INTERFACE + ${PROJECT_NAME} + src/NotFound.cpp + src/SampleRepository.cpp + src/universe.cpp ) target_include_directories( ${PROJECT_NAME} - INTERFACE include + PUBLIC include ) diff --git a/universe/include/kurator/universe.h b/universe/include/kurator/universe.h new file mode 100644 index 0000000..73d06ae --- /dev/null +++ b/universe/include/kurator/universe.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include "universe/Repository.h" + + +namespace kurator +{ +namespace universe +{ + + +auto load_sample() -> std::shared_ptr; + + +} // namespace universe +} // namespace kurator diff --git a/universe/include/kurator/universe/NotFound.h b/universe/include/kurator/universe/NotFound.h new file mode 100644 index 0000000..03d344d --- /dev/null +++ b/universe/include/kurator/universe/NotFound.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + + +namespace kurator +{ +namespace universe +{ + + +class NotFound : public std::exception +{ +public: + explicit NotFound(std::string _id); + const char* what() const noexcept override; +private: + const std::string id; +}; + + +} // namespace universe +} // namespace kurator diff --git a/universe/include/kurator/universe/Repository.h b/universe/include/kurator/universe/Repository.h new file mode 100644 index 0000000..8d44793 --- /dev/null +++ b/universe/include/kurator/universe/Repository.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "ShipType.h" +#include "TurretType.h" + + +namespace kurator +{ +namespace universe +{ + + +class Repository +{ +public: + virtual ~Repository() = default; + virtual ShipType ship_type(const std::string& id) const = 0; + virtual TurretType turret_type(const std::string& id) const = 0; +}; + + +} // namespace universe +} // namespace kurator diff --git a/universe/src/NotFound.cpp b/universe/src/NotFound.cpp new file mode 100644 index 0000000..e5a4109 --- /dev/null +++ b/universe/src/NotFound.cpp @@ -0,0 +1,27 @@ +#include + +#include +#include + + +namespace kurator +{ +namespace universe +{ + + +NotFound::NotFound(std::string _id) : + id {std::move(_id)} +{ +} + + +const char* +NotFound::what() const noexcept +{ + return "item not found in repository"; // what is not found? use that id +} + + +} // namespace universe +} // namespace kurator diff --git a/universe/src/SampleRepository.cpp b/universe/src/SampleRepository.cpp new file mode 100644 index 0000000..66a3105 --- /dev/null +++ b/universe/src/SampleRepository.cpp @@ -0,0 +1,51 @@ +#include "SampleRepository.h" + +#include +#include +#include + +#include +#include +#include + + +namespace kurator +{ +namespace universe +{ + + +static const std::unordered_map ships { + {"cube", {"Cube", 10.0}}, + {"halo", {"Halo", 4.0}}, + {"bell", {"Bell", 18.0}}, +}; + + +static const std::unordered_map turrets { + {"cannon", {"Cannon", 1.0, 1.0, 0.5}}, +}; + + +ShipType +SampleRepository::ship_type(const std::string& id) const +try { + return ships.at(id); +} +catch (const std::out_of_range&) { + throw NotFound(id); +} + + +TurretType +SampleRepository::turret_type(const std::string& id) const +try { + return turrets.at(id); +} +catch (const std::out_of_range&) { + throw NotFound(id); +} + + +} // namespace universe +} // namespace kurator diff --git a/universe/src/SampleRepository.h b/universe/src/SampleRepository.h new file mode 100644 index 0000000..1cf4fb4 --- /dev/null +++ b/universe/src/SampleRepository.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include +#include +#include + + +namespace kurator +{ +namespace universe +{ + + +class SampleRepository : public Repository +{ +public: + ShipType ship_type(const std::string& id) const override; + TurretType turret_type(const std::string& id) const override; +}; + + +} // namespace universe +} // namespace kurator diff --git a/universe/src/universe.cpp b/universe/src/universe.cpp new file mode 100644 index 0000000..b77ce7c --- /dev/null +++ b/universe/src/universe.cpp @@ -0,0 +1,24 @@ +#include + +#include + +#include + +#include "SampleRepository.h" + + +namespace kurator +{ +namespace universe +{ + + +std::shared_ptr +load_sample() +{ + return std::make_shared(); +} + + +} // namespace universe +} // namespace kurator -- cgit v1.1