From 2cb7b057f0747b32720565364dc4563117efd7a5 Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Mon, 27 Jun 2022 22:43:42 +0100
Subject: [PATCH] move type safe wrapper to util because it's useful

---
 include/fggl/assets/manager.hpp | 37 ++++++++++++++++++++++++
 include/fggl/modules/module.hpp | 20 ++-----------
 include/fggl/util/safety.hpp    | 51 +++++++++++++++++++++++++++++++++
 3 files changed, 91 insertions(+), 17 deletions(-)
 create mode 100644 include/fggl/assets/manager.hpp
 create mode 100644 include/fggl/util/safety.hpp

diff --git a/include/fggl/assets/manager.hpp b/include/fggl/assets/manager.hpp
new file mode 100644
index 0000000..598e648
--- /dev/null
+++ b/include/fggl/assets/manager.hpp
@@ -0,0 +1,37 @@
+/*
+ * This file is part of FGGL.
+ *
+ * FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
+ * later version.
+ *
+ * FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with FGGL.
+ * If not, see <https://www.gnu.org/licenses/>.
+ */
+
+//
+// Created by webpigeon on 27/06/22.
+//
+
+#ifndef FGGL_ASSETS_MANAGER_HPP
+#define FGGL_ASSETS_MANAGER_HPP
+
+#include <string_view>
+#include "fggl/util/safety.hpp"
+
+namespace fggl::assets {
+
+	struct AssetTag{};
+	using AssetType = util::OpaqueName<std::string_view, AssetTag>;
+
+	class Manager {
+		public:
+
+	};
+
+} // namespace fggl::assets
+
+#endif //FGGL_ASSETS_MANAGER_HPP
diff --git a/include/fggl/modules/module.hpp b/include/fggl/modules/module.hpp
index d6c2e75..176b3de 100644
--- a/include/fggl/modules/module.hpp
+++ b/include/fggl/modules/module.hpp
@@ -24,30 +24,16 @@
 #include <functional>
 #include <map>
 #include <memory>
+#include "fggl/util/safety.hpp"
 
 namespace fggl::modules {
 
 	using ModuleIdentifier = std::string;
 
-	struct ModuleService {
-		private:
-			std::string_view value;
-
-		public:
-			constexpr ModuleService(std::string_view value) : value(value) {}
-			constexpr explicit operator std::string_view() const { return value; }
-
-			bool operator==(const ModuleService& other) const {
-				return value == other.value;
-			}
-
-			std::strong_ordering operator<=>(const ModuleService& other) const noexcept {
-				return value <=> other.value;
-			}
-	};
+	using ModuleService = util::OpaqueName<std::string_view, struct ModuleServiceTag>;
 
 	constexpr ModuleService make_service(const std::string_view name) {
-		return {name};
+		return ModuleService::make(name);
 	}
 
 	class Services {
diff --git a/include/fggl/util/safety.hpp b/include/fggl/util/safety.hpp
new file mode 100644
index 0000000..18797ea
--- /dev/null
+++ b/include/fggl/util/safety.hpp
@@ -0,0 +1,51 @@
+/*
+ * This file is part of FGGL.
+ *
+ * FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
+ * later version.
+ *
+ * FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with FGGL.
+ * If not, see <https://www.gnu.org/licenses/>.
+ */
+
+//
+// Created by webpigeon on 27/06/22.
+//
+
+#ifndef FGGL_UTIL_SAFETY_H
+#define FGGL_UTIL_SAFETY_H
+
+#include <string>
+
+namespace fggl::util {
+
+	template<typename T, typename Tag>
+	struct OpaqueName {
+		private:
+			T m_value;
+
+		public:
+			constexpr OpaqueName(T value) : m_value(value) {}
+
+			constexpr explicit operator std::string_view() const { return m_value; }
+
+			bool operator==(const OpaqueName<T, Tag> &other) const {
+				return m_value == other.m_value;
+			}
+
+			std::strong_ordering operator<=>(const OpaqueName<T, Tag> &other) const noexcept {
+				return m_value <=> other.m_value;
+			}
+
+			constexpr static OpaqueName<T, Tag> make(T value) {
+				return OpaqueName(value);
+			}
+	};
+
+} // namespace fggl::util
+
+#endif //FGGL_UTIL_SAFETY_H
-- 
GitLab