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 #ifndef _ID3LIB_READERS_H_
00029 #define _ID3LIB_READERS_H_
00030
00031 #include <fstream.h>
00032 #include <iostream.h>
00033 #include <id3/reader.h>
00034
00035 class ID3_CPP_EXPORT ID3_IStreamReader : public ID3_Reader
00036 {
00037 istream& _stream;
00038 protected:
00039 istream& getReader() const { return _stream; }
00040 public:
00041 ID3_IStreamReader(istream& reader) : _stream(reader) { ; }
00042 virtual ~ID3_IStreamReader() { ; }
00043 virtual void close() { ; }
00044
00045 virtual int_type peekChar() { return _stream.peek(); }
00046
00050 virtual size_type readChars(char buf[], size_type len)
00051 {
00052 return this->readChars(reinterpret_cast<uchar *>(buf), len);
00053 }
00054 virtual size_type readChars(char_type buf[], size_type len)
00055 {
00056 _stream.read((char *)buf, len);
00057 return _stream.gcount();
00058 }
00059
00060 virtual pos_type getBeg() { return 0; }
00061 virtual pos_type getCur() { return _stream.tellg(); }
00062 virtual pos_type getEnd()
00063 {
00064 pos_type cur = this->getCur();
00065 _stream.seekg(0, ios::end);
00066 pos_type end = this->getCur();
00067 this->setCur(cur);
00068 return end;
00069 }
00070
00073 virtual pos_type setCur(pos_type pos) { _stream.seekg(pos); return pos; }
00074 };
00075
00076 class ID3_CPP_EXPORT ID3_IFStreamReader : public ID3_IStreamReader
00077 {
00078 ifstream& _file;
00079 public:
00080 ID3_IFStreamReader(ifstream& reader)
00081 : ID3_IStreamReader(reader), _file(reader) { ; }
00082
00083 virtual void close()
00084 {
00085 _file.close();
00086 }
00087 };
00088
00089 class ID3_CPP_EXPORT ID3_MemoryReader : public ID3_Reader
00090 {
00091 const char_type* _beg;
00092 const char_type* _cur;
00093 const char_type* _end;
00094 protected:
00095 void setBuffer(const char_type* buf, size_type size)
00096 {
00097 _beg = buf;
00098 _cur = buf;
00099 _end = buf + size;
00100 };
00101 public:
00102 ID3_MemoryReader()
00103 {
00104 this->setBuffer(NULL, 0);
00105 }
00106 ID3_MemoryReader(const char_type* buf, size_type size)
00107 {
00108 this->setBuffer(buf, size);
00109 };
00110 ID3_MemoryReader(const char* buf, size_type size)
00111 {
00112 this->setBuffer(reinterpret_cast<const char_type*>(buf), size);
00113 };
00114 virtual ~ID3_MemoryReader() { ; }
00115 virtual void close() { ; }
00116
00117 virtual int_type peekChar()
00118 {
00119 if (!this->atEnd())
00120 {
00121 return *_cur;
00122 }
00123 return END_OF_READER;
00124 }
00125
00129 virtual size_type readChars(char buf[], size_type len)
00130 {
00131 return this->readChars(reinterpret_cast<char_type *>(buf), len);
00132 }
00133 virtual size_type readChars(char_type buf[], size_type len);
00134
00135 virtual pos_type getCur()
00136 {
00137 return _cur - _beg;
00138 }
00139
00140 virtual pos_type getBeg()
00141 {
00142 return _beg - _beg;
00143 }
00144
00145 virtual pos_type getEnd()
00146 {
00147 return _end - _beg;
00148 }
00149
00152 virtual pos_type setCur(pos_type pos)
00153 {
00154 pos_type end = this->getEnd();
00155 size_type size = (pos < end) ? pos : end;
00156 _cur = _beg + size;
00157 return this->getCur();
00158 }
00159 };
00160
00161 #endif