Skip to content
Snippets Groups Projects
Commit 2cb7b057 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

move type safe wrapper to util because it's useful

parent 00bcae2d
No related branches found
No related tags found
No related merge requests found
/*
* 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
......@@ -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 {
......
/*
* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment