CppCMS
booster/shared_object.h
00001 //
00002 //  Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
00003 //
00004 //  Distributed under the Boost Software License, Version 1.0. (See
00005 //  accompanying file LICENSE_1_0.txt or copy at
00006 //  http://www.boost.org/LICENSE_1_0.txt)
00007 //
00008 #ifndef BOOSTER_SHARED_OBJECT_H
00009 #define BOOSTER_SHARED_OBJECT_H
00010 
00011 #include <booster/config.h>
00012 #include <booster/noncopyable.h>
00013 #include <booster/hold_ptr.h>
00014 #include <booster/backtrace.h>
00015 #include <booster/cstdint.h>
00016 #include <string>
00017 
00018 namespace booster {
00022         class BOOSTER_API shared_object : public booster::noncopyable {
00023         public:
00027                 shared_object();
00032                 ~shared_object();
00040                 shared_object(std::string const &file_name);
00044                 bool is_open() const;
00051                 bool open(std::string const &file_name);
00059                 bool open(std::string const &file_name,std::string &error_message);
00063                 void close();
00064 
00070                 void *resolve_symbol(std::string const &name) const;
00071 
00075                 template<typename T>
00076                 void symbol(T &s,std::string const &name) const
00077                 {
00078                         void *p = resolve_symbol(name);
00079                         if(!p) {
00080                                 throw booster::runtime_error("booster::shared_object:failed to resolve symbol:" + name);
00081                         }
00082                         s = reinterpret_cast<T>(reinterpret_cast<size_t>(p));
00083                 }
00084 
00096                 static std::string name(std::string const &module);
00109                 static std::string name(std::string const &module,std::string const &soversion);
00110         private:
00111                 struct data;
00112                 hold_ptr<data> d;
00113         };
00114 }
00115 
00116 #endif
00117