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_READER_H_
00029 #define _ID3LIB_READER_H_
00030
00031 #include <id3/globals.h>
00032
00033 class ID3_CPP_EXPORT ID3_Reader
00034 {
00035 public:
00036 typedef uint32 size_type;
00037 typedef uint8 char_type;
00038 typedef uint32 pos_type;
00039 typedef int32 off_type;
00040 typedef int16 int_type;
00041 static const int_type END_OF_READER;
00042
00045 virtual void close() = 0;
00046
00048 virtual pos_type getBeg() { return static_cast<pos_type>(0); }
00049
00051 virtual pos_type getEnd() { return static_cast<pos_type>(-1); }
00052
00054 virtual pos_type getCur() = 0;
00055
00058 virtual pos_type setCur(pos_type pos) = 0;
00059
00065 virtual int_type readChar()
00066 {
00067 if (this->atEnd())
00068 {
00069 return END_OF_READER;
00070 }
00071 char_type ch;
00072 this->readChars(&ch, 1);
00073 return ch;
00074 }
00075
00080 virtual int_type peekChar() = 0;
00081
00087 virtual size_type readChars(char_type buf[], size_type len) = 0;
00088 virtual size_type readChars(char buf[], size_type len)
00089 {
00090 return this->readChars(reinterpret_cast<char_type *>(buf), len);
00091 }
00092
00097 virtual size_type skipChars(size_type len)
00098 {
00099 const size_type SIZE = 1024;
00100 char_type bytes[SIZE];
00101 size_type remaining = len;
00102 while (!this->atEnd() && remaining > 0)
00103 {
00104 remaining -= this->readChars(bytes, (remaining < SIZE ? remaining : SIZE));
00105 }
00106 return len - remaining;
00107 }
00108
00109 virtual size_type remainingBytes()
00110 {
00111 pos_type end = this->getEnd(), cur = this->getCur();
00112 if (end == pos_type(-1))
00113 {
00114 return size_type(-1);
00115 }
00116
00117 if (end >= cur)
00118 {
00119 return end - cur;
00120 }
00121
00122 return 0;
00123 }
00124
00125 virtual bool atEnd() { return this->getCur() >= this->getEnd(); }
00126 };
00127
00128 #endif