CppCMS

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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:
24 static const int load_lazy = 1;
25 static const int load_now = 2;
26 static const int load_global = 4;
27 static const int load_local = 8;
28 shared_object();
36 ~shared_object();
45 shared_object(std::string const &file_name,int flags);
53 shared_object(std::string const &file_name);
57 bool is_open() const;
64 bool open(std::string const &file_name);
72 bool open(std::string const &file_name,std::string &error_message);
81 bool open(std::string const &file_name,int flags);
91 bool open(std::string const &file_name,std::string &error_message,int flags);
96 void close();
97
103 void *resolve_symbol(std::string const &name) const;
104
109 template<typename T>
110 void symbol(T &s,std::string const &name) const
111 {
112 void *p = resolve_symbol(name);
113 if(!p) {
114 throw booster::runtime_error("booster::shared_object:failed to resolve symbol:" + name);
115 }
116 s = reinterpret_cast<T>(reinterpret_cast<size_t>(p));
117 }
118
130 static std::string name(std::string const &module);
143 static std::string name(std::string const &module,std::string const &soversion);
144 private:
145 struct data;
146 hold_ptr<data> d;
147 };
148 }
149
150 #endif
151
booster::hold_ptr< data >
booster::runtime_error
Same as std::runtime_error but records stack trace.
Definition: backtrace.h:158
booster::shared_object
Class that allows loading dynamic libraries: shared objects and dlls.
Definition: shared_object.h:22
booster::shared_object::symbol
void symbol(T &s, std::string const &name) const
Definition: shared_object.h:110
booster
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
booster::noncopyable
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15