Vcsn  2.5
Be Rational
xltdl.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdexcept>
4 
5 #include <ltdl.h>
6 
9 #include <vcsn/misc/raise.hh>
10 
11 namespace vcsn
12 {
13  namespace detail
14  {
15  class xlt_handle;
16 
17  class xlt_advise
18  {
19  public:
20  xlt_advise();
21  ~xlt_advise();
22 
23  xlt_advise& global(bool global);
24  xlt_advise& ext();
25 
26  const file_library& path() const noexcept;
27  file_library& path() noexcept;
28  xlt_advise& path(const file_library& p) noexcept;
29 
30  xlt_handle open(const std::string& s);
31 
33  template <typename... Args>
34  ATTRIBUTE_NORETURN
35  static void raise(Args&&... args)
36  {
37  vcsn::raise(std::forward<Args>(args)...);
38  }
39 
40  private:
42  lt_dlhandle dlopen_(const file_library::path& s) const;
43 
44  lt_dladvise advise_;
46  };
47 
48 
49  class xlt_handle
50  {
51  public:
52  xlt_handle(lt_dlhandle h = nullptr);
53  ~xlt_handle();
54 
56  void close();
57 
59  void detach();
60 
62  void attach(lt_dlhandle h);
63 
65  template <typename T>
66  T sym(const std::string& s)
67  {
68  assert(handle);
69  if (auto res = lt_dlsym(handle, s.c_str()))
70  return reinterpret_cast<T>(res);
71  else
72  raise("failed to dlsym ", s);
73  }
74 
77  lt_dlhandle handle;
78  };
79 
82  xlt_openext(const std::string& s, bool global);
83  }
84 }
xlt_handle open(const std::string &s)
Definition: xltdl.cc:88
ATTRIBUTE_NORETURN void raise(Args &&... args)
Raise a runtime_error with the concatenation of args as message.
Definition: raise.hh:75
Definition: a-star.hh:8
lt_dlhandle dlopen_(const file_library::path &s) const
Does not use the search path. Can return 0.
Definition: xltdl.cc:82
return res
Definition: multiply.hh:398
Manage search paths.
Definition: file-library.hh:22
lt_dladvise advise_
Definition: xltdl.hh:44
lt_dlhandle handle
The handle.
Definition: xltdl.hh:77
const file_library & path() const noexcept
Definition: xltdl.cc:63
xlt_advise & ext()
Definition: xltdl.cc:55
xlt_handle xlt_openext(const std::string &s, bool global)
Wrapper around lt_dlopenext.
Definition: xltdl.cc:160
boost::filesystem::path path
Definition: file-library.hh:27
T sym(const std::string &s)
Wrapper around lt_dlsym that exits on failures.
Definition: xltdl.hh:66
Manage sets of inclusion paths.
xlt_advise & global(bool global)
Definition: xltdl.cc:46
file_library path_
Definition: xltdl.hh:45