FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
November 01, 2000

Creating Truly Maintainable Class Factories

(Page 5 of 8)
November 2000/Creating Truly Maintainable Class Factories/Listing 4

Listing 4: Partial listing of class dll_object_ref

template
< class object >
class dll_object_ref
   {
      friend class dll_object_ptr< object >;

      // not shown: invariant()
      ...

   private:

      dll_object_ref
         ( dll_sentinel&         dll
         , std::string const& function_name )
         : m_dll( dll ), m_count( 1 ), m_obj( NULL )
         {
         #ifdef _WIN32
            typedef object* (WINAPI* p_instantiate)( );
         #elif defined( _DLSYM )
            typedef object* (* p_instantiate)( );
         #else
            #error Unsupported Platform.   Please port me
         #endif

         void* pvfunc = m_dll.find_func( function_name );
         if ( !_pvfunc )
            throw dll_exception
               ( "Could not find instantiation routine." );

         p_instantiate pfunc = 
            *reinterpret_cast<p_instantiate*>( &_pvfunc );
         m_obj = pfunc( );

         assert( invariant() );
         } 

      virtual ~dll_object_ref( )
         {
         assert( invariant() );
         m_obj->destroy();
         m_obj = NULL;
         } // ~dll_object_ref( )


      // not shown: functions ref and unref
      ...

   private: // data

      dll_sentinel   m_dll;
      object*          m_obj;
      unsigned long m_count;

   }; // class dll_object_ref< >

Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 Next Page
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK