libmoost
/home/mhx/git/github/libmoost/include/moost/pdl/dynamic_class.h
Go to the documentation of this file.
00001 /* vim:set ts=3 sw=3 sts=3 et: */
00028 #ifndef MOOST_PDL_DYNAMIC_CLASS_H__
00029 #define MOOST_PDL_DYNAMIC_CLASS_H__
00030 
00031 #include <boost/shared_ptr.hpp>
00032 #include <boost/noncopyable.hpp>
00033 
00034 #include "platform.h"
00035 
00036 namespace moost { namespace pdl {
00037 
00038 class dynamic_library;
00039 class dynamic_library_if;
00040 
00047 class dynamic_class : public boost::noncopyable
00048 {
00049    // We have to be friends with dynamic_library so that m_library can
00050    // be accessed.
00051    friend class dynamic_library;
00052 
00053 public:
00054    virtual ~dynamic_class();
00055 
00056 private:
00057    // This reference is used to manage the lifetime of a loaded shared
00058    // library. Once the last reference to a shared library is gone, the
00059    // shared library will be unloaded.
00060    boost::shared_ptr<dynamic_library_if> m_library;
00061 };
00062 
00063 }}
00064 
00071 #define PDL_EXPORT_DYNAMIC_CLASS(class_name) \
00072    extern "C" PDL_DECL_EXPORT ::moost::pdl::dynamic_class *PDL_create_ ## class_name() \
00073    {                                \
00074       try                           \
00075       {                             \
00076          return new class_name();   \
00077       }                             \
00078       catch (...)                   \
00079       {                             \
00080       }                             \
00081       return 0;                     \
00082    }
00083 
00084 #endif