id3lib
3.8.3
|
00001 // -*- C++ -*- 00002 // $Id: io_decorators.h,v 1.5 2002/07/02 22:10:51 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_DECORATORS_H_ 00029 #define _ID3LIB_READER_DECORATORS_H_ 00030 00031 #include "readers.h" 00032 #include "io_helpers.h" 00033 #include "id3/utils.h" // has <config.h> "id3/id3lib_streams.h" "id3/globals.h" "id3/id3lib_strings.h" 00034 00035 namespace dami 00036 { 00037 namespace io 00038 { 00043 class ID3_CPP_EXPORT WindowedReader : public ID3_Reader 00044 { 00045 typedef ID3_Reader SUPER; 00046 00047 ID3_Reader& _reader; 00048 pos_type _beg, _end; 00049 00050 bool inWindow(pos_type cur) 00051 { return this->getBeg() <= cur && cur < this->getEnd(); } 00052 00053 public: 00054 explicit WindowedReader(ID3_Reader& reader) 00055 : _reader(reader), _beg(reader.getBeg()), _end(reader.getEnd()) { ; } 00056 00057 WindowedReader(ID3_Reader& reader, size_type size) 00058 : _reader(reader), _beg(reader.getBeg()), _end(reader.getEnd()) 00059 { this->setWindow(this->getCur(), size); } 00060 00061 WindowedReader(ID3_Reader& reader, pos_type beg, size_type size) 00062 : _reader(reader), _beg(reader.getBeg()), _end(reader.getEnd()) 00063 { this->setWindow(beg, size); } 00064 00065 void setWindow(pos_type beg, size_type size); 00066 00067 pos_type setBeg(pos_type); 00068 pos_type setCur(pos_type cur) 00069 { 00070 return _reader.setCur(mid(this->getBeg(), cur, this->getEnd())); 00071 } 00072 pos_type setEnd(pos_type); 00073 00074 pos_type getCur() { return _reader.getCur(); } 00075 pos_type getBeg() { return _beg; } 00076 pos_type getEnd() { return _end; } 00077 00078 bool inWindow() { return this->inWindow(this->getCur()); } 00079 00080 int_type readChar(); 00081 int_type peekChar(); 00082 00083 size_type readChars(char_type buf[], size_type len); 00084 size_type readChars(char buf[], size_type len) 00085 { 00086 return this->readChars((char_type*) buf, len); 00087 } 00088 00089 void close() { ; } 00090 }; 00091 00092 class ID3_CPP_EXPORT CharReader : public ID3_Reader 00093 { 00094 typedef ID3_Reader SUPER; 00095 00096 protected: 00097 ID3_Reader& _reader; 00098 00099 public: 00100 00101 CharReader(ID3_Reader& reader) : _reader(reader) { } 00102 virtual ~CharReader() { ; } 00103 00109 size_type readChars(char_type buf[], size_type len); 00110 size_type readChars(char buf[], size_type len) 00111 { 00112 return this->readChars((char_type*) buf, len); 00113 } 00114 00115 void close() { ; } 00116 int_type peekChar() { return _reader.peekChar(); } 00117 00118 pos_type getBeg() { return _reader.getBeg(); } 00119 pos_type getCur() { return _reader.getCur(); } 00120 pos_type getEnd() { return _reader.getEnd(); } 00121 00122 pos_type setCur(pos_type cur) { return _reader.setCur(cur); } 00123 }; 00124 00125 00126 class ID3_CPP_EXPORT LineFeedReader : public CharReader 00127 { 00128 typedef CharReader SUPER; 00129 00130 public: 00131 LineFeedReader(ID3_Reader& reader) : SUPER(reader) { ; } 00132 int_type readChar(); 00133 }; 00134 00135 class ID3_CPP_EXPORT UnsyncedReader : public CharReader 00136 { 00137 typedef CharReader SUPER; 00138 00139 public: 00140 UnsyncedReader(ID3_Reader& reader) : SUPER(reader) { } 00141 int_type readChar(); 00142 }; 00143 00144 class ID3_CPP_EXPORT CompressedReader : public ID3_MemoryReader 00145 { 00146 char_type* _uncompressed; 00147 public: 00148 CompressedReader(ID3_Reader& reader, size_type newSize); 00149 virtual ~CompressedReader(); 00150 }; 00151 00152 class ID3_CPP_EXPORT UnsyncedWriter : public ID3_Writer 00153 { 00154 typedef ID3_Writer SUPER; 00155 00156 ID3_Writer& _writer; 00157 int_type _last; 00158 size_type _numSyncs; 00159 00160 public: 00161 UnsyncedWriter(ID3_Writer& writer) 00162 : _writer(writer), _last('\0'), _numSyncs(0) 00163 { ; } 00164 00165 size_type getNumSyncs() const { return _numSyncs; } 00166 int_type writeChar(char_type ch); 00167 void flush(); 00168 00174 size_type writeChars(const char_type[], size_type len); 00175 size_type writeChars(const char buf[], size_type len) 00176 { 00177 return this->writeChars(reinterpret_cast<const char_type *>(buf), len); 00178 } 00179 00180 void close() { ; } 00181 00182 pos_type getBeg() { return _writer.getBeg(); } 00183 pos_type getCur() { return _writer.getCur(); } 00184 pos_type getEnd() { return _writer.getEnd(); } 00185 }; 00186 00187 class CompressedWriter : public ID3_Writer 00188 { 00189 typedef ID3_Writer SUPER; 00190 00191 ID3_Writer& _writer; 00192 BString _data; 00193 size_type _origSize; 00194 public: 00195 00196 explicit CompressedWriter(ID3_Writer& writer) 00197 : _writer(writer), _data(), _origSize(0) 00198 { ; } 00199 virtual ~CompressedWriter() { this->flush(); } 00200 00201 size_type getOrigSize() const { return _origSize; } 00202 00203 void flush(); 00204 00205 size_type writeChars(const char_type buf[], size_type len); 00206 size_type writeChars(const char buf[], size_type len) 00207 { 00208 return this->writeChars(reinterpret_cast<const char_type*>(buf), len); 00209 } 00210 00211 pos_type getCur() { return _data.size(); } 00212 void close() { ; } 00213 }; 00214 }; 00215 }; 00216 00217 #endif /* _ID3LIB_READER_DECORATORS_H_ */ 00218