1 // -*- C++ -*- 2 // $Id: io_decorators.h,v 1.5 2002/07/02 22:10:51 t1mpy Exp $ 3 4 // id3lib: a software library for creating and manipulating id3v1/v2 tags 5 // Copyright 1999, 2000 Scott Thomas Haug 6 7 // This library is free software; you can redistribute it and/or modify it 8 // under the terms of the GNU Library General Public License as published by 9 // the Free Software Foundation; either version 2 of the License, or (at your 10 // option) any later version. 11 // 12 // This library is distributed in the hope that it will be useful, but WITHOUT 13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 15 // License for more details. 16 // 17 // You should have received a copy of the GNU Library General Public License 18 // along with this library; if not, write to the Free Software Foundation, 19 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 21 // The id3lib authors encourage improvements and optimisations to be sent to 22 // the id3lib coordinator. Please see the README file for details on where to 23 // send such submissions. See the AUTHORS file for a list of people who have 24 // contributed to id3lib. See the ChangeLog file for a list of changes to 25 // id3lib. These files are distributed with id3lib at 26 // http://download.sourceforge.net/id3lib/ 27 28 #ifndef _ID3LIB_READER_DECORATORS_H_ 29 #define _ID3LIB_READER_DECORATORS_H_ 30 31 #include "readers.h" 32 #include "io_helpers.h" 33 #include "id3/utils.h" // has <config.h> "id3/id3lib_streams.h" "id3/globals.h" "id3/id3lib_strings.h" 34 35 namespace dami 36 { 37 namespace io 38 { 39 /** 40 * Set a window on the buffer. Characters can only be read within this 41 * window. 42 */ 43 class ID3_CPP_EXPORT WindowedReader : public ID3_Reader 44 { 45 typedef ID3_Reader SUPER; 46 47 ID3_Reader& _reader; 48 pos_type _beg, _end; 49 inWindow(pos_type cur)50 bool inWindow(pos_type cur) 51 { return this->getBeg() <= cur && cur < this->getEnd(); } 52 53 public: WindowedReader(ID3_Reader & reader)54 explicit WindowedReader(ID3_Reader& reader) 55 : _reader(reader), _beg(reader.getBeg()), _end(reader.getEnd()) { ; } 56 WindowedReader(ID3_Reader & reader,size_type size)57 WindowedReader(ID3_Reader& reader, size_type size) 58 : _reader(reader), _beg(reader.getBeg()), _end(reader.getEnd()) 59 { this->setWindow(this->getCur(), size); } 60 WindowedReader(ID3_Reader & reader,pos_type beg,size_type size)61 WindowedReader(ID3_Reader& reader, pos_type beg, size_type size) 62 : _reader(reader), _beg(reader.getBeg()), _end(reader.getEnd()) 63 { this->setWindow(beg, size); } 64 65 void setWindow(pos_type beg, size_type size); 66 67 pos_type setBeg(pos_type); setCur(pos_type cur)68 pos_type setCur(pos_type cur) 69 { 70 return _reader.setCur(mid(this->getBeg(), cur, this->getEnd())); 71 } 72 pos_type setEnd(pos_type); 73 getCur()74 pos_type getCur() { return _reader.getCur(); } getBeg()75 pos_type getBeg() { return _beg; } getEnd()76 pos_type getEnd() { return _end; } 77 inWindow()78 bool inWindow() { return this->inWindow(this->getCur()); } 79 80 int_type readChar(); 81 int_type peekChar(); 82 83 size_type readChars(char_type buf[], size_type len); readChars(char buf[],size_type len)84 size_type readChars(char buf[], size_type len) 85 { 86 return this->readChars((char_type*) buf, len); 87 } 88 close()89 void close() { ; } 90 }; 91 92 class ID3_CPP_EXPORT CharReader : public ID3_Reader 93 { 94 typedef ID3_Reader SUPER; 95 96 protected: 97 ID3_Reader& _reader; 98 99 public: 100 CharReader(ID3_Reader & reader)101 CharReader(ID3_Reader& reader) : _reader(reader) { } ~CharReader()102 virtual ~CharReader() { ; } 103 104 /** 105 * Read \c len characters into the array \c buf. Since the stream needs 106 * might have been unsynced, this function copies the characters one at a 107 * time. 108 */ 109 size_type readChars(char_type buf[], size_type len); readChars(char buf[],size_type len)110 size_type readChars(char buf[], size_type len) 111 { 112 return this->readChars((char_type*) buf, len); 113 } 114 close()115 void close() { ; } peekChar()116 int_type peekChar() { return _reader.peekChar(); } 117 getBeg()118 pos_type getBeg() { return _reader.getBeg(); } getCur()119 pos_type getCur() { return _reader.getCur(); } getEnd()120 pos_type getEnd() { return _reader.getEnd(); } 121 setCur(pos_type cur)122 pos_type setCur(pos_type cur) { return _reader.setCur(cur); } 123 }; 124 125 126 class ID3_CPP_EXPORT LineFeedReader : public CharReader 127 { 128 typedef CharReader SUPER; 129 130 public: LineFeedReader(ID3_Reader & reader)131 LineFeedReader(ID3_Reader& reader) : SUPER(reader) { ; } 132 int_type readChar(); 133 }; 134 135 class ID3_CPP_EXPORT UnsyncedReader : public CharReader 136 { 137 typedef CharReader SUPER; 138 139 public: UnsyncedReader(ID3_Reader & reader)140 UnsyncedReader(ID3_Reader& reader) : SUPER(reader) { } 141 int_type readChar(); 142 }; 143 144 class ID3_CPP_EXPORT CompressedReader : public ID3_MemoryReader 145 { 146 char_type* _uncompressed; 147 public: 148 CompressedReader(ID3_Reader& reader, size_type newSize); 149 virtual ~CompressedReader(); 150 }; 151 152 class ID3_CPP_EXPORT UnsyncedWriter : public ID3_Writer 153 { 154 typedef ID3_Writer SUPER; 155 156 ID3_Writer& _writer; 157 int_type _last; 158 size_type _numSyncs; 159 160 public: UnsyncedWriter(ID3_Writer & writer)161 UnsyncedWriter(ID3_Writer& writer) 162 : _writer(writer), _last('\0'), _numSyncs(0) 163 { ; } 164 getNumSyncs()165 size_type getNumSyncs() const { return _numSyncs; } 166 int_type writeChar(char_type ch); 167 void flush(); 168 169 /** 170 * Write \c len characters into the array \c buf. Since the stream needs 171 * might have been unsynced, this function copies the characters one at a 172 * time. 173 */ 174 size_type writeChars(const char_type[], size_type len); writeChars(const char buf[],size_type len)175 size_type writeChars(const char buf[], size_type len) 176 { 177 return this->writeChars(reinterpret_cast<const char_type *>(buf), len); 178 } 179 close()180 void close() { ; } 181 getBeg()182 pos_type getBeg() { return _writer.getBeg(); } getCur()183 pos_type getCur() { return _writer.getCur(); } getEnd()184 pos_type getEnd() { return _writer.getEnd(); } 185 }; 186 187 class CompressedWriter : public ID3_Writer 188 { 189 typedef ID3_Writer SUPER; 190 191 ID3_Writer& _writer; 192 BString _data; 193 size_type _origSize; 194 public: 195 CompressedWriter(ID3_Writer & writer)196 explicit CompressedWriter(ID3_Writer& writer) 197 : _writer(writer), _data(), _origSize(0) 198 { ; } ~CompressedWriter()199 virtual ~CompressedWriter() { this->flush(); } 200 getOrigSize()201 size_type getOrigSize() const { return _origSize; } 202 203 void flush(); 204 205 size_type writeChars(const char_type buf[], size_type len); writeChars(const char buf[],size_type len)206 size_type writeChars(const char buf[], size_type len) 207 { 208 return this->writeChars(reinterpret_cast<const char_type*>(buf), len); 209 } 210 getCur()211 pos_type getCur() { return _data.size(); } close()212 void close() { ; } 213 }; 214 }; 215 }; 216 217 #endif /* _ID3LIB_READER_DECORATORS_H_ */ 218 219