Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
DynamicLibrary.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** R-Type
4** File description:
5** DynamicLibrary.hpp, declaration of dynamic library handling
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
40#ifndef RTYPE_DYNAMICLIBRARY_HPP_
41 #define RTYPE_DYNAMICLIBRARY_HPP_
42
43 #include "RType/Error.hpp"
44
45 #include <expected>
46 #include <string>
47 #include <string_view>
48
49namespace rtp::sys
50{
56 class DynamicLibrary final {
57 public:
63 explicit DynamicLibrary(void *handle) noexcept;
64
69 ~DynamicLibrary() noexcept;
70
71 DynamicLibrary(DynamicLibrary &&other) noexcept;
72 DynamicLibrary &operator=(DynamicLibrary &&other) noexcept;
73
74 DynamicLibrary(const DynamicLibrary &) = delete;
76
83 template <typename T>
84 [[nodiscard]]
85 auto get(std::string_view name) const
86 -> std::expected<T, rtp::Error>;
87
88 private:
89 void *_handle{nullptr};
96 [[nodiscard]]
97 auto getSymbolAddress(std::string_view name) const
98 -> std::expected<void *, rtp::Error>;
99
100 };
101}
102
103 #include "DynamicLibrary.tpp"
104
105#endif /* !RTYPE_DYNAMICLIBRARY_HPP_ */
Error handling system with categorized error codes.
Represents a dynamically loaded library.
DynamicLibrary & operator=(const DynamicLibrary &)=delete
DynamicLibrary(const DynamicLibrary &)=delete
void * _handle
The handle to the dynamic library.
auto getSymbolAddress(std::string_view name) const -> std::expected< void *, rtp::Error >
Get the address of a symbol from the dynamic library.
auto get(std::string_view name) const -> std::expected< T, rtp::Error >
Get a symbol from the dynamic library.
DynamicLibrary & operator=(DynamicLibrary &&other) noexcept
~DynamicLibrary() noexcept
Destructor.