Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

wefts_specific.h

Go to the documentation of this file.
00001 /*
00002    wefts_specific.h
00003    Thread Specific Data object templated
00004 
00005    $Id: wefts_specific.h,v 1.3 2003/08/18 03:50:12 jonnymind Exp $
00006 ---------------------------------------------
00007    Begin      : 2003-08-15 06:05
00008    Author     : Giancarlo Niccolai
00009 
00010    Last modified because:
00011 
00012 */
00013 
00014 /**************************************************************************
00015 *   This program is free software; you can redistribute it and/or modify  *
00016 *   it under the terms of the GNU Library General Public License as       *
00017 *   published by the Free Software Foundation; either version 2.1 of the  *
00018 *   License, or (at your option) any later version.                       *
00019 ***************************************************************************/
00020 
00021 #ifndef WT_SPECIFIC_H
00022 #define WT_SPECIFIC_H
00023 
00024 #include <wefts_os.h>
00025 
00026 namespace Wefts {
00027 
00097 template< typename _T >
00098 class ThreadPtr
00099 {
00100 private:
00102    OSSpecificData m_specific;
00103 
00104 protected:
00109    _T &deref() throw( InvalidError )
00110    {
00111       void *dt = m_specific.data();
00112       if ( dt == 0 ) throw InvalidError();
00113       return *static_cast<_T *>(dt);
00114    }
00115 
00116 public:
00117    ThreadPtr() {}
00118    ThreadPtr( _T *data ) { set(data); }
00119    ThreadPtr( ThreadPtr<_T> &src ) { set( src ); }
00120 
00122    _T *get() const { return static_cast<_T *>( m_specific.data() ); }
00123 
00127    ThreadPtr<_T > &set( ThreadPtr<_T > &src ){
00128       m_specific.data( static_cast< void *>(src.m_specific.data()));
00129       return *this;
00130    }
00131 
00136    _T *set( _T *data ) {
00137       m_specific.data( static_cast< const void *>(&data));
00138       return data;
00139    }
00140 
00146    bool equal( const ThreadPtr<_T > &src ) const {
00147       return equal( src.m_specific.data() );
00148    }
00149 
00155    bool equal( const _T *data) const { return (m_specific.data() == data); }
00156 
00157    _T &operator*() { return deref(); }
00158    ThreadPtr<_T > &operator=( ThreadPtr<_T > &src ) { return set( src ); }
00159    _T *operator=( _T *data ) { return set(data); }
00160 
00161    bool operator ==( const ThreadPtr<_T > &src ) const {return equal( src );}
00162    bool operator ==( const _T *data ) const { return equal(data); }
00163 
00164    bool operator !=( const ThreadPtr<_T > &src ) const { return ! equal( src ); }
00165    bool operator !=( const _T *data ) const { return !equal(data); }
00166 };
00167 
00168 } // namespace
00169 #endif
00170 
00171 /* end of wefts_specific.h */

Generated on Mon Aug 18 05:53:37 2003 for Wefts by doxygen1.2.18