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