Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
LibraryManager.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** R-Type
4** File description:
5** LibraryManager.hpp, declaration of dynamic library manager
6*/
7
8/*
9** MIT License
10**
11** Copyright (c) 2025 Robin Toillon
12**
13** Permission is hereby granted, free of charge, to any person obtaining
14** a copy of this software and associated documentation files (the
15** "Software"), to deal in the Software without restriction, including
16** without limitation the rights to use, copy, modify, merge, publish,
17** distribute, sublicense, and/or sell copies of the Software, and to
18** permit persons to whom the Software is furnished to do so, subject to
19** the following conditions:
20**
21** The above copyright notice and this permission notice shall be
22** included in all copies or substantial portions of the Software.
23**
24** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31*/
32
43#ifndef RTYPE_LIBRARYMANAGER_HPP_
44 #define RTYPE_LIBRARYMANAGER_HPP_
45
46 #include "RType/Error.hpp"
48
49 #include <expected>
50 #include <memory>
51 #include <shared_mutex>
52 #include <string>
53 #include <string_view>
54 #include <unordered_map>
55
56namespace rtp::sys
57{
63 class LibraryManager final {
64 public:
65 LibraryManager(void) = default;
66 ~LibraryManager() noexcept = default;
67
68 LibraryManager(const LibraryManager &) = delete;
69 LibraryManager &operator=(const LibraryManager &) = delete;
70
71 LibraryManager(LibraryManager &&) noexcept = delete;
72 LibraryManager &operator=(LibraryManager &&) noexcept = delete;
73
81 [[nodiscard]]
82 auto load(std::string_view path)
83 -> std::expected<const DynamicLibrary *, rtp::Error>;
84
93 [[nodiscard]]
94 auto loadShared(std::string_view path)
95 -> std::expected<std::shared_ptr<DynamicLibrary>, rtp::Error>;
96
105 static auto loadStandalone(std::string_view path)
106 -> std::expected<std::unique_ptr<DynamicLibrary>, rtp::Error>;
107
108 private:
109 std::unordered_map<std::string,
111 std::shared_mutex _mutex;
113 private:
120 [[nodiscard]]
121 auto getOrLoadInternal(std::string_view path)
122 -> std::expected<std::shared_ptr<DynamicLibrary>,
123 rtp::Error>;
124
125 };
126}
127
128#endif /* !RTYPE_LIBRARYMANAGER_HPP_ */
Declaration of the DynamicLibrary class.
Error handling system with categorized error codes.
Comprehensive error object with severity and retry tracking.
Definition Error.hpp:156
Represents a dynamically loaded library.
Manages dynamic libraries, providing loading and caching mechanisms.
std::shared_mutex _mutex
Mutex for thread-safe access.
auto loadShared(std::string_view path) -> std::expected< std::shared_ptr< DynamicLibrary >, rtp::Error >
Shared API.
~LibraryManager() noexcept=default
auto load(std::string_view path) -> std::expected< const DynamicLibrary *, rtp::Error >
Main API.
static auto loadStandalone(std::string_view path) -> std::expected< std::unique_ptr< DynamicLibrary >, rtp::Error >
Isolated API (Factory).
std::unordered_map< std::string, std::shared_ptr< DynamicLibrary > > _libraries
auto getOrLoadInternal(std::string_view path) -> std::expected< std::shared_ptr< DynamicLibrary >, rtp::Error >
Get an existing library or load it if not present.
LibraryManager(void)=default
STL namespace.