00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00039 #include "blocxx/BLOCXX_config.h"
00040 #include "blocxx/Types.hpp"
00041 #include "blocxx/DataStreams.hpp"
00042 #include <cstring>
00043
00044 namespace BLOCXX_NAMESPACE
00045 {
00046
00048 int
00049 DataIStreamBuf::underflow()
00050 {
00051 return (gptr() < egptr()) ? static_cast<unsigned char>(*gptr()) : EOF;
00052 }
00053
00055 std::streambuf::pos_type
00056 DataIStreamBuf::seekoff(off_type off, std::ios_base::seekdir way, std::ios_base::openmode which)
00057 {
00058 pos_type ret = pos_type(off_type(-1));
00059
00060 char* begin = eback();
00061 char* cur = gptr();
00062 char* end = egptr();
00063
00064 off_type newOff = 0;
00065
00066 if (way == std::ios_base::cur)
00067 {
00068 newOff = cur - begin;
00069 }
00070 else if (way == std::ios_base::end)
00071 {
00072 newOff = end - begin;
00073 }
00074
00075 if (newOff + off >= 0 && end - begin >= newOff + off)
00076 {
00077 setg(begin, begin + newOff + off, end);
00078 ret = pos_type(newOff);
00079 }
00080
00081 return ret;
00082 }
00083
00085 std::streambuf::pos_type
00086 DataIStreamBuf::seekpos(pos_type sp, std::ios_base::openmode which)
00087 {
00088 pos_type ret = pos_type(off_type(-1));
00089
00090 char* begin = eback();
00091 char* end = egptr();
00092
00093 if (sp <= end - begin)
00094 {
00095 setg(begin, begin + sp, end);
00096 ret = sp;
00097 }
00098
00099 return ret;
00100 }
00101
00103 DataOStreamBuf::DataOStreamBuf(size_t initialSize)
00104 : std::streambuf()
00105 {
00106 m_bfr.reserve(initialSize);
00107 }
00109 int
00110 DataOStreamBuf::overflow(int c)
00111 {
00112 m_bfr.push_back(c);
00113 return 0;
00114 }
00116 std::streamsize
00117 DataOStreamBuf::xsputn(const char* s, std::streamsize n)
00118 {
00119 m_bfr.insert(m_bfr.end(), s, s+n);
00120 return n;
00121 }
00122
00123 }
00124