Vcsn  2.8
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();
26  xlt_advise& verbose(int v);
27 
28  const file_library& path() const noexcept;
29  file_library& path() noexcept;
30  xlt_advise& path(const file_library& p) noexcept;
31 
32  xlt_handle open(const std::string& s);
33 
35  template <typename... Args>
36  ATTRIBUTE_NORETURN
37  static void raise(Args&&... args)
38  {
39  vcsn::raise(std::forward<Args>(args)...);
40  }
41 
42  private:
44  lt_dlhandle dlopen_(const file_library::path& s) const;
45 
46  lt_dladvise advise_;
48  int verbose_ = 0;
49  };
50 
51 
52  class xlt_handle
53  {
54  public:
55  xlt_handle(lt_dlhandle h = nullptr);
56  ~xlt_handle();
57 
59  void close();
60 
62  void detach();
63 
65  void attach(lt_dlhandle h);
66 
68  template <typename T>
69  T sym(const std::string& s)
70  {
71  assert(handle);
72  if (auto res = lt_dlsym(handle, s.c_str()))
73  return reinterpret_cast<T>(res);
74  else
75  raise("failed to dlsym ", s);
76  }
77 
80  lt_dlhandle handle;
81  };
82 
85  xlt_openext(const std::string& s, bool global);
86  }
87 }
ATTRIBUTE_NORETURN void raise(Args &&... args)
Raise a runtime_error with the concatenation of args as message.
Definition: raise.hh:71
xlt_advise & global(bool global)
Definition: xltdl.cc:46
lt_dlhandle handle
The handle.
Definition: xltdl.hh:80
xlt_advise & ext()
Definition: xltdl.cc:55
lt_dladvise advise_
Definition: xltdl.hh:46
T sym(const std::string &s)
Wrapper around lt_dlsym that exits on failures.
Definition: xltdl.hh:69
lt_dlhandle dlopen_(const file_library::path &s) const
Does not use the search path. Can return 0.
Definition: xltdl.cc:89
Definition: a-star.hh:8
const file_library & path() const noexcept
Definition: xltdl.cc:70
Manage search paths.
Definition: file-library.hh:22
file_library path_
Definition: xltdl.hh:47
boost::filesystem::path path
Definition: file-library.hh:27
xlt_handle xlt_openext(const std::string &s, bool global)
Wrapper around lt_dlopenext.
Definition: xltdl.cc:177
Manage sets of inclusion paths.
xlt_handle open(const std::string &s)
Definition: xltdl.cc:105
return res
Definition: multiply.hh:399
xlt_advise & verbose(int v)
Whether to report dlopen attempts.
Definition: xltdl.cc:63