00001
00002 #ifndef _OSMBUF_HH_
00003 #define _OSMBUF_HH_
00004
00005
00006
00007 #include "PConfig.h"
00008
00009
00010 #if defined(OSMBUF_TRACE)
00011 #include <string>
00012 #include <iostream>
00013 #endif
00014
00015 #if defined(__GNU_STDC_OLD)
00016 #include <streambuf.h>
00017 #else
00018 #include <iostream>
00019 #include <streambuf>
00020 #endif
00021
00022 class LSMP_PROD;
00023
00032 class oSMbuf : public std::streambuf {
00033 public:
00034 #if defined(__GNU_STDC_OLD)
00035 typedef std::ios::open_mode openmode_type;
00036 typedef std::ios::seek_dir seekdir_type;
00037 #else
00038 typedef std::ios::openmode openmode_type;
00039 typedef std::ios::seekdir seekdir_type;
00040 #endif
00041
00042 public:
00043
00047 oSMbuf();
00048
00054 oSMbuf(const char *partition, openmode_type mode=std::ios::out);
00055
00058 ~oSMbuf();
00059
00066 oSMbuf* open(const char *partition, openmode_type mode=std::ios::out);
00067
00070 void close(void);
00071
00074 int doallocate(void);
00075
00078 int overflow(int c);
00079
00082 void set_id(int evtid);
00083
00086 int underflow() {return EOF;}
00087
00090 int underflow(int c) {return EOF;}
00091
00094 std::streampos seekoff(std::streamoff off, seekdir_type dir,
00095 openmode_type mode);
00096
00099 std::streampos seekpos(std::streampos pos, openmode_type mode);
00100
00103 int sync(void);
00104
00105 #ifndef __GNU_STDC_OLD
00106
00108 void setb(char* b, char* eb, int a=0) {}
00109
00112 int out_waiting(void) {return pptr() - pbase();}
00113 #endif
00114
00115 private:
00117 LSMP_PROD *mProducer;
00119 char *mBuffer;
00121 int mLength;
00122 #ifdef OSMBUF_TRACE
00123 public:
00124 void pTrace(void) const {mTrace.pTrace();}
00125 private:
00126 class trace {
00127 #define maxTrace 8
00128 public:
00129 trace() : nTrace(0) {}
00130 void tracepoint(const std::string& funct, int arg1=0, int arg2=0);
00131 long returns(long i);
00132 void pTrace(void) const;
00133 void clear(void);
00134 private:
00135 int nTrace;
00136 std::string mFuncName[maxTrace];
00137 long mArg1[maxTrace];
00138 long mArg2[maxTrace];
00139 long mRet[maxTrace];
00140 } mTrace;
00141 #endif
00142 };
00143
00144 #ifdef OSMBUF_TRACE
00145 inline void
00146 oSMbuf::trace::tracepoint(const std::string& funct, int arg1, int arg2) {
00147 int inx = nTrace % maxTrace;
00148 mFuncName[inx] = funct;
00149 mArg1[inx] = arg1;
00150 mArg2[inx] = arg2;
00151 nTrace++;
00152 }
00153
00154 inline void
00155 oSMbuf::trace::clear(void) {
00156 nTrace = 0;
00157 }
00158
00159 inline long
00160 oSMbuf::trace::returns(long ret) {
00161 int inx = (nTrace-1) % maxTrace;
00162 mRet[inx] = ret;
00163 return ret;
00164 }
00165 #endif
00166
00167 #endif // _OSMBUF_HH_