shared_object.h
//
// Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOSTER_SHARED_OBJECT_H
#define BOOSTER_SHARED_OBJECT_H
#include <booster/config.h>
#include <booster/noncopyable.h>
#include <booster/hold_ptr.h>
#include <booster/backtrace.h>
#include <booster/cstdint.h>
#include <string>
namespace booster {
class BOOSTER_API shared_object : public booster::noncopyable {
public:
shared_object();
~shared_object();
shared_object(std::string const &file_name);
bool is_open() const;
bool open(std::string const &file_name);
bool open(std::string const &file_name,std::string &error_message);
void close();
void *resolve_symbol(std::string const &name) const;
template<typename T>
void symbol(T &s,std::string const &name) const
{
void *p = resolve_symbol(name);
if(!p) {
throw booster::runtime_error("booster::shared_object:failed to resolve symbol:" + name);
}
s = reinterpret_cast<T>(reinterpret_cast<size_t>(p));
}
static std::string name(std::string const &module);
static std::string name(std::string const &module,std::string const &soversion);
private:
struct data;
hold_ptr<data> d;
};
}
#endif
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:76
booster::noncopyable
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15