id3lib
3.8.3
|
00001 // -*- C++ -*- 00002 // $Id: reader.h,v 1.13 2002/07/02 22:10:57 t1mpy Exp $ 00003 00004 // id3lib: a software library for creating and manipulating id3v1/v2 tags 00005 // Copyright 1999, 2000 Scott Thomas Haug 00006 00007 // This library is free software; you can redistribute it and/or modify it 00008 // under the terms of the GNU Library General Public License as published by 00009 // the Free Software Foundation; either version 2 of the License, or (at your 00010 // option) any later version. 00011 // 00012 // This library is distributed in the hope that it will be useful, but WITHOUT 00013 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00015 // License for more details. 00016 // 00017 // You should have received a copy of the GNU Library General Public License 00018 // along with this library; if not, write to the Free Software Foundation, 00019 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00020 00021 // The id3lib authors encourage improvements and optimisations to be sent to 00022 // the id3lib coordinator. Please see the README file for details on where to 00023 // send such submissions. See the AUTHORS file for a list of people who have 00024 // contributed to id3lib. See the ChangeLog file for a list of changes to 00025 // id3lib. These files are distributed with id3lib at 00026 // http://download.sourceforge.net/id3lib/ 00027 00028 #ifndef _ID3LIB_READER_H_ 00029 #define _ID3LIB_READER_H_ 00030 00031 #include "id3/globals.h" //has <stdlib.h> "id3/sized_types.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 /* _ID3LIB_READER_H_ */ 00129