uvw  1.3.0
lib.hpp
1 #pragma once
2 
3 
4 #include <memory>
5 #include <string>
6 #include <type_traits>
7 #include <utility>
8 #include <uv.h>
9 #include "loop.hpp"
10 #include "underlying_type.hpp"
11 
12 
13 namespace uvw {
14 
15 
22 class SharedLib final: public UnderlyingType<SharedLib, uv_lib_t> {
23 public:
24  explicit SharedLib(ConstructorAccess ca, std::shared_ptr<Loop> ref, std::string filename) noexcept
25  : UnderlyingType{ca, std::move(ref)}
26  {
27  opened = (0 == uv_dlopen(filename.data(), get()));
28  }
29 
30  ~SharedLib() noexcept {
31  uv_dlclose(get());
32  }
33 
38  explicit operator bool() const noexcept { return opened; }
39 
49  template<typename F>
50  F * sym(std::string name) {
51  static_assert(std::is_function<F>::value, "!");
52  F *func;
53  auto err = uv_dlsym(get(), name.data(), reinterpret_cast<void**>(&func));
54  if(err) { func = nullptr; }
55  return func;
56  }
57 
62  const char * error() const noexcept {
63  return uv_dlerror(get());
64  }
65 
66 private:
67  bool opened;
68 };
69 
70 
71 }
Wrapper class for underlying types.
const char * error() const noexcept
Returns the last error message, if any.
Definition: lib.hpp:62
F * sym(std::string name)
Retrieves a data pointer from a dynamic library.
Definition: lib.hpp:50
The SharedLib class.
Definition: lib.hpp:22
uvw default namespace.
Definition: async.hpp:11