CppCMS
shared_object.h
1 //
2 // Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 #ifndef BOOSTER_SHARED_OBJECT_H
9 #define BOOSTER_SHARED_OBJECT_H
10 
11 #include <booster/config.h>
12 #include <booster/noncopyable.h>
13 #include <booster/hold_ptr.h>
14 #include <booster/backtrace.h>
15 #include <booster/cstdint.h>
16 #include <string>
17 
18 namespace booster {
22  class BOOSTER_API shared_object : public booster::noncopyable {
23  public:
27  shared_object();
32  ~shared_object();
40  shared_object(std::string const &file_name);
44  bool is_open() const;
51  bool open(std::string const &file_name);
59  bool open(std::string const &file_name,std::string &error_message);
63  void close();
64 
70  void *resolve_symbol(std::string const &name) const;
71 
75  template<typename T>
76  void symbol(T &s,std::string const &name) const
77  {
78  void *p = resolve_symbol(name);
79  if(!p) {
80  throw booster::runtime_error("booster::shared_object:failed to resolve symbol:" + name);
81  }
82  s = reinterpret_cast<T>(reinterpret_cast<size_t>(p));
83  }
84 
96  static std::string name(std::string const &module);
109  static std::string name(std::string const &module,std::string const &soversion);
110  private:
111  struct data;
112  hold_ptr<data> d;
113  };
114 }
115 
116 #endif
117 
Same as std::runtime_error but records stack trace.
Definition: backtrace.h:158
Class that allows loading dynamic libraries: shared objects and dlls.
Definition: shared_object.h:22
void symbol(T &s, std::string const &name) const
Definition: shared_object.h:76
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15