Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

CSeg.h

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef AXPIPE_CSEG_H
00003 #define AXPIPE_CSEG_H
00004 
00038 #include "AxPipe.h"
00039 
00040 namespace AxPipe {
00073 class CSeg {
00074 private:
00075     volatile LONG m_iRefCnt;                
00076     CRITICAL_SECTION m_CritSect;            
00077 
00078     void *m_pvBuf;                          
00079     size_t m_cbBuf;                         
00080     CSeg *m_pMom;                           
00081     bool m_fOwnPtr;                         
00082     bool m_fReadOnly;                       
00083     int m_iType;                            
00084 
00085     size_t m_cbOff;                         
00086     size_t m_cbLen;                         
00087 
00089     void Init(size_t cbBuf, void *pvBuf, bool fReadOnly, int iType);
00090 
00092     CSeg& operator=(CSeg& rhs);
00093 
00094 public:
00096     CSeg(size_t cbBuf = 0, void *pvBuf = NULL, bool fReadOnly = false);
00097 
00099     CSeg(size_t cbBuf, const void *pvBuf);
00100 
00102     CSeg(const void *pvBuf, size_t cbLen, size_t cbGrowBuf = 0);
00103 
00105     virtual ~CSeg();
00106     
00107     unsigned char *Ptr();                   
00108     const unsigned char *PtrRd();           
00109     unsigned char *PtrWr();                 
00110     void *PtrRelease();                     
00111     size_t Size(void);                      
00112     size_t Len(void);                       
00113     CSeg *Len(size_t cbLen);                
00114     CSeg *Writeable();                      
00115     CSeg *Drop(size_t cbOff);               
00116     CSeg *AddRef();                         
00117     int Release();                          
00118     int Type();                             
00119     CSeg *SetType(int iType);               
00120     static bool IsSeg(CSeg *pSeg);          
00121     CSeg *Clone();                          
00122     static void *ClassId();                 
00123     virtual void *RTClassId();              
00124 };
00125 
00132 template<class T> class Auto_Seg {
00133 private:
00134     T *m_p;                                 
00135 
00137     inline void Release() {
00138         if (m_p) {
00139             m_p->Release();
00140         }
00141     }
00142 public:
00144     inline Auto_Seg(T *p = NULL) {
00145         m_p = p;
00146     }
00147 
00149     inline ~Auto_Seg() {
00150         Release();
00151     }
00152     
00154     inline Auto_Seg<T>& operator=(T *p) {
00155         Release();
00156         m_p = p;
00157         return *this;
00158     }
00159     
00161     inline Auto_Seg<T>& operator=(T& rhs) {
00162         rhs.AddRef();
00163         return *this = &rhs;
00164     }
00165     
00167     inline Auto_Seg<T>& operator=(Auto_Seg<T>& rhs) {
00168         if ((T *)rhs) {
00169             rhs->AddRef();
00170         }
00171         return *this = rhs.m_p;
00172     }
00173     
00175     inline operator T*() {
00176         return m_p;
00177     }
00178     
00180     inline T* operator ->() {
00181         return m_p;
00182     }
00183     
00185     inline T* get() {
00186         return m_p;
00187     }
00188     
00190     inline T* release() {
00191         T *p = m_p;
00192         m_p = NULL;
00193         return p;
00194     }
00195 };
00197 typedef Auto_Seg<CSeg> CAutoSeg;
00198 
00199 }; // namespace AxPipe
00200 #endif AXPIPE_CERROR_H

Generated on Mon Feb 2 13:19:18 2004 for AxPipe by doxygen 1.3.5