shm_ptr.h

Go to the documentation of this file.
00001 
00005 #ifndef SHM_PTR_H
00006 #define SHM_PTR_H 1
00007 
00008 #include "shm_segment.h"
00009 
00018 template<typename T>
00019 class shm_ptr
00020 {
00021  public:
00024   shm_ptr() { offset = 0; } ;
00027   shm_ptr( T* rawptr, const shm_segment& seg ) { 
00028     offset = (long) rawptr - (long)seg.get_base();
00029   };
00030  
00033   T* get( const shm_segment& seg ) const { 
00034     return ( T * )( offset + (long)( seg.get_base() ) ) ; 
00035   };
00040   long off( void ) { return offset ; } ;
00041 
00046   long set( long off ) { return offset = off ; } ;
00049   void reset( T* rawptr, const shm_segment& seg ) { 
00050     offset = (long)rawptr - (long)( seg.get_base() ); 
00051   };
00052  private:
00053   long offset;
00054 };
00055  
00056 class shm_ptr_out_of_bounds : public std::exception
00057 {
00058  public:
00059   const char* what() const throw()
00060     { return "shm_ptr cannot be created with address outside of segment"; }
00061 };
00062 
00063 #endif
00064 

Project shmq hosted by   SourceForge.net
Documentation generated on Sat Sep 2 10:07:40 2006 for shmq by   doxygen.org 1.4.6