dptrtemplate.h
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #ifndef __dptrtemplate_h__
00023 #define __dptrtemplate_h__
00024 
00025 #include <qptrdict.h>
00026 
00027 template<class Instance, class PrivateData>
00028 class dPtrTemplate {
00029 public:
00030     static PrivateData* d( const Instance* instance )
00031     {
00032         if ( !d_ptr ) {
00033             cleanup_d_ptr();
00034             d_ptr = new QPtrDict<PrivateData>;
00035             qAddPostRoutine( cleanup_d_ptr );
00036         }
00037         PrivateData* ret = d_ptr->find( (void*) instance );
00038         if ( ! ret ) {
00039             ret = new PrivateData;
00040             d_ptr->replace( (void*) instance, ret );
00041         }
00042         return ret;
00043     }
00044     static void delete_d( const Instance* instance )
00045     {
00046         if ( d_ptr )
00047             d_ptr->remove( (void*) instance );
00048     }
00049 private:
00050     static void cleanup_d_ptr()
00051     {
00052         delete d_ptr;
00053     }
00054     static QPtrDict<PrivateData>* d_ptr;
00055 };
00056 
00057 #endif
 
This file is part of the documentation for kio Library Version 3.2.0.