uvw 3.1.0
Loading...
Searching...
No Matches
lib.h
1#ifndef UVW_LIB_INCLUDE_H
2#define UVW_LIB_INCLUDE_H
3
4#include <memory>
5#include <string>
6#include <type_traits>
7#include <uv.h>
8#include "config.h"
9#include "loop.h"
10#include "uv_type.hpp"
11
12namespace uvw {
13
20class shared_lib final: public uv_type<uv_lib_t> {
21public:
22 explicit shared_lib(loop::token token, std::shared_ptr<loop> ref, const std::string &filename) noexcept;
23
24 ~shared_lib() noexcept;
25
30 explicit operator bool() const noexcept;
31
41 template<typename F>
42 F *sym(const std::string &name) {
43 static_assert(std::is_function_v<F>);
44 F *func;
45 auto err = uv_dlsym(raw(), name.data(), reinterpret_cast<void **>(&func));
46 if(err) { func = nullptr; }
47 return func;
48 }
49
54 const char *error() const noexcept;
55
56private:
57 bool opened;
58};
59
60} // namespace uvw
61
62#ifndef UVW_AS_LIB
63# include "lib.cpp"
64#endif
65
66#endif // UVW_LIB_INCLUDE_H
The shared lib class.
Definition: lib.h:20
const char * error() const noexcept
Returns the last error message, if any.
F * sym(const std::string &name)
Retrieves a data pointer from a dynamic library.
Definition: lib.h:42
uvw default namespace.
Definition: async.h:8
Wrapper class for underlying types.
Definition: uv_type.hpp:18
const uv_lib_t * raw() const noexcept
Gets the underlying raw data structure.
Definition: uv_type.hpp:59