CppDB
cppdb/shared_object.h
00001 
00002 //                                                                             
00003 //  Copyright (C) 2010-2011  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>     
00004 //                                                                             
00005 //  Distributed under:
00006 //
00007 //                   the Boost Software License, Version 1.0.
00008 //              (See accompanying file LICENSE_1_0.txt or copy at 
00009 //                     http://www.boost.org/LICENSE_1_0.txt)
00010 //
00011 //  or (at your opinion) under:
00012 //
00013 //                               The MIT License
00014 //                 (See accompanying file MIT.txt or a copy at
00015 //              http://www.opensource.org/licenses/mit-license.php)
00016 //
00018 #ifndef CPPDB_SHARED_OBJECT_H
00019 #define CPPDB_SHARED_OBJECT_H
00020 
00021 #include <cppdb/defs.h>
00022 #include <cppdb/ref_ptr.h>
00023 
00024 
00025 namespace cppdb {
00029         class CPPDB_API shared_object : public ref_counted {
00030                 shared_object() : handle_(0) {}
00031                 shared_object(std::string name,void *h);
00032                 shared_object(shared_object const &);
00033                 void operator=(shared_object const &);
00034         public:
00035                 ~shared_object();
00039                 static ref_ptr<shared_object> open(std::string const &name);
00043                 void *safe_sym(std::string const &name);
00044 
00048                 void *sym(std::string const &name);
00049 
00053                 template<typename T>
00054                 bool resolve(std::string const &s,T *&v)
00055                 {
00056                         void *p=sym(s);
00057                         if(!p) {
00058                                 return false;
00059                         }
00060                         v=(T*)(p);
00061                         return true;
00062                 }
00066                 template<typename T>
00067                 void safe_resolve(std::string const &s,T *&v)
00068                 {
00069                         v=(T*)(sym(s));
00070                 }
00071 
00072         private:
00073                 std::string dlname_;
00074                 void *handle_;
00075         };
00076 }
00077 
00078 
00079 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator