smstream/iSMbuf.hh

00001 /* -*- mode: c++; c-basic-offset: 4; -*- */
00002 #ifndef ISMBUF_HH_
00003 #define ISMBUF_HH_
00004 //
00005 //   Shared memory stream input buffer class
00006 //
00007 #include "PConfig.h"
00008 // #define ISMBUF_TRACE
00009 
00010 #if defined(ISMBUF_TRACE)
00011   #include <string>
00012   #include <iostream>
00013 #endif
00014 #if defined(__GNU_STDC_OLD)
00015    #include <streambuf.h>
00016 #else
00017    #include <iostream>
00018    #include <streambuf>
00019 #endif
00020 
00021 class LSMP_CON;
00022 
00035 class iSMbuf : public std::streambuf {
00036 public:
00037 
00038 #ifdef __GNU_STDC_OLD
00039     typedef std::ios::open_mode openmode_type;
00040     typedef std::ios::seek_dir  seekdir_type;
00041 #else
00042     typedef std::ios::openmode  openmode_type;
00043     typedef std::ios::seekdir   seekdir_type;
00044 #endif
00045 
00048     typedef std::streamoff off_type;
00049 
00052     typedef std::streampos pos_type;
00053 
00054 public:
00059     iSMbuf();
00060 
00067     iSMbuf(const char *partition, openmode_type mode=std::ios::in);
00068 
00071     ~iSMbuf();
00072 
00075     int eventid(void) const;
00076 
00079     bool latest(void) const;
00080 
00084     iSMbuf* open(const char *partition, openmode_type mode=std::ios::in);
00085 
00096     void setBCount(int nbuf);
00097 
00107     bool waitBuf(bool nowait=false);
00108 
00112     void relse(void);
00113 
00116     int doallocate(void);
00117 
00120     int overflow(int c) {return EOF;}
00121 
00124     int underflow(void);
00125 
00126 
00129     pos_type seekoff(off_type off, seekdir_type dir, openmode_type mode);
00130 
00133     pos_type seekpos(pos_type off, openmode_type mode);
00134 
00137     int sync(){return 0;}
00138 
00139   private:
00140     void setptrs(int ix=0);
00141 #ifndef __GNUG__
00142   void setb(char* b, char*eb, int a=0) {}
00143 #endif
00144 
00145 
00146   private:
00148     LSMP_CON*   mConsumer;
00150     const char* mBuffer;
00152     int         mLength;
00153 #ifdef ISMBUF_TRACE
00154   public:
00155     void pTrace(void) const {mTrace.pTrace();}
00156   private:
00157     class trace {
00158     #define maxTrace 8
00159     public:
00160         trace() : nTrace(0) {}
00161         void tracepoint(const std::string& funct, int arg1=0, int arg2=0);
00162         void pTrace(void) const;
00163         void clear(void);
00164     private:
00165         int nTrace;
00166         std::string mFuncName[maxTrace];
00167         int mArg1[maxTrace];
00168         int mArg2[maxTrace];
00169     } mTrace;
00170 #endif
00171 };
00172 
00173 //======================================  Inline implementation of seekoff
00174 #ifndef __GNU_STDC_OLD
00175 inline iSMbuf::pos_type
00176 iSMbuf::seekpos(pos_type off, openmode_type mode) {
00177     return seekoff(off_type(off), std::ios::beg, mode);
00178 }
00179 #endif
00180 
00181 //======================================  Trace point function
00182 #ifdef ISMBUF_TRACE
00183 inline void 
00184 iSMbuf::trace::tracepoint(const std::string& funct, int arg1, int arg2) {
00185     int inx = nTrace % maxTrace;
00186     mFuncName[inx] = funct;
00187     mArg1[inx] = arg1;
00188     mArg2[inx] = arg2;
00189     nTrace++;
00190 }
00191 
00192 inline void 
00193 iSMbuf::trace::clear(void) {
00194     nTrace = 0;
00195 }
00196 #endif
00197 
00198 #endif  //  ISMBUF_HH_

Generated on Sun Mar 8 19:20:51 2009 for dmt by  doxygen 1.5.4