summaryrefslogtreecommitdiff
path: root/universe/src
diff options
context:
space:
mode:
Diffstat (limited to 'universe/src')
-rw-r--r--universe/src/NotFound.cpp27
-rw-r--r--universe/src/SampleRepository.cpp51
-rw-r--r--universe/src/SampleRepository.h25
-rw-r--r--universe/src/universe.cpp24
4 files changed, 127 insertions, 0 deletions
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 <kurator/universe/NotFound.h>
+
+#include <string>
+#include <utility>
+
+
+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 <stdexcept>
+#include <string>
+#include <unordered_map>
+
+#include <kurator/universe/NotFound.h>
+#include <kurator/universe/ShipType.h>
+#include <kurator/universe/TurretType.h>
+
+
+namespace kurator
+{
+namespace universe
+{
+
+
+static const std::unordered_map<std::string, ShipType> ships {
+ {"cube", {"Cube", 10.0}},
+ {"halo", {"Halo", 4.0}},
+ {"bell", {"Bell", 18.0}},
+};
+
+
+static const std::unordered_map<std::string, TurretType> 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 <string>
+
+#include <kurator/universe/Repository.h>
+#include <kurator/universe/ShipType.h>
+#include <kurator/universe/TurretType.h>
+
+
+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 <kurator/universe.h>
+
+#include <memory>
+
+#include <kurator/universe/Repository.h>
+
+#include "SampleRepository.h"
+
+
+namespace kurator
+{
+namespace universe
+{
+
+
+std::shared_ptr<Repository>
+load_sample()
+{
+ return std::make_shared<SampleRepository>();
+}
+
+
+} // namespace universe
+} // namespace kurator