00001 #ifndef _STR_BufferChunk_H_ // -*-c++-*-
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef __GNUG__
00022 # pragma interface
00023 #endif
00024
00025
00026
00027
00028
00029 #include <StrMod/ChunkVisitor.h>
00030 #include <StrMod/StrChunk.h>
00031 #include <StrMod/STR_ClassIdent.h>
00032 #include <StrMod/LinearExtent.h>
00033 #include <LCore/GenTypes.h>
00034 #include <LCore/Debugable.h>
00035 #include <new>
00036 #include <iosfwd>
00037
00038 #define _STR_BufferChunk_H_
00039
00040 namespace strmod {
00041 namespace strmod {
00042
00043
00044
00045
00046
00047 class BufferChunk : public StrChunk, virtual public lcore::Debugable
00048 {
00049 typedef lcore::U1Byte U1Byte;
00050 public:
00051 class Factory;
00052 static const STR_ClassIdent identifier;
00053
00054
00055
00056
00057 BufferChunk() : buf_(0), buflen_(0) { }
00058
00059
00060
00061
00062
00063
00064 virtual ~BufferChunk() { }
00065
00066 inline virtual int AreYouA(const lcore::ClassIdent &cid) const;
00067
00068 inline virtual bool invariant() const;
00069
00070 virtual void printState(std::ostream &os) const;
00071
00072 virtual unsigned int Length() const { return(buflen_); }
00073
00074
00075
00076
00077
00078 inline U1Byte &operator [](unsigned int bnum);
00079
00080
00081
00082
00083
00084
00085 inline void *getVoidP();
00086
00087
00088
00089
00090
00091
00092
00093 inline U1Byte *getCharP();
00094
00095
00096
00097
00098
00099 virtual void resize(unsigned int newsize) throw(std::bad_alloc) = 0;
00100
00101 protected:
00102 virtual const lcore::ClassIdent *i_GetIdent() const { return &identifier; }
00103
00104 virtual void acceptVisitor(ChunkVisitor &visitor)
00105 throw(ChunkVisitor::halt_visitation);
00106
00107 protected:
00108
00109
00110
00111
00112
00113
00114
00115
00116 void *buf_;
00117
00118
00119
00120
00121
00122
00123 unsigned int buflen_;
00124
00125 private:
00126 static U1Byte junk_;
00127
00128
00129 void operator =(const BufferChunk &b);
00130 BufferChunk(const BufferChunk &b);
00131 };
00132
00133
00134
00135 inline int BufferChunk::AreYouA(const lcore::ClassIdent &cid) const
00136 {
00137 return((identifier == cid) || StrChunk::AreYouA(cid));
00138 }
00139
00140 inline bool BufferChunk::invariant() const
00141 {
00142 return((buflen_ == 0) || (buf_ != 0));
00143 }
00144
00145 inline lcore::U1Byte &BufferChunk::operator [](unsigned int bnum)
00146 {
00147 return((bnum < buflen_) ? static_cast<U1Byte *>(buf_)[bnum] : junk_);
00148 }
00149
00150 inline void *BufferChunk::getVoidP()
00151 {
00152 return((buflen_ > 0) ? buf_ : &junk_);
00153 }
00154
00155 inline lcore::U1Byte *BufferChunk::getCharP()
00156 {
00157 return((buflen_ > 0) ? static_cast<U1Byte *>(buf_) : &junk_);
00158 }
00159
00160 }
00161 }
00162
00163 #endif