id3lib  3.8.3
io_decorators.h
Go to the documentation of this file.
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  {
44  {
45  typedef ID3_Reader SUPER;
46 
47  ID3_Reader& _reader;
48  pos_type _beg, _end;
49 
50  bool inWindow(pos_type cur)
51  { return this->getBeg() <= cur && cur < this->getEnd(); }
52 
53  public:
54  explicit WindowedReader(ID3_Reader& reader)
55  : _reader(reader), _beg(reader.getBeg()), _end(reader.getEnd()) { ; }
56 
58  : _reader(reader), _beg(reader.getBeg()), _end(reader.getEnd())
59  { this->setWindow(this->getCur(), size); }
60 
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);
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 
74  pos_type getCur() { return _reader.getCur(); }
75  pos_type getBeg() { return _beg; }
76  pos_type getEnd() { return _end; }
77 
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);
84  size_type readChars(char buf[], size_type len)
85  {
86  return this->readChars((char_type*) buf, len);
87  }
88 
89  void close() { ; }
90  };
91 
93  {
94  typedef ID3_Reader SUPER;
95 
96  protected:
98 
99  public:
100 
101  CharReader(ID3_Reader& reader) : _reader(reader) { }
102  virtual ~CharReader() { ; }
103 
109  size_type readChars(char_type buf[], size_type len);
110  size_type readChars(char buf[], size_type len)
111  {
112  return this->readChars((char_type*) buf, len);
113  }
114 
115  void close() { ; }
116  int_type peekChar() { return _reader.peekChar(); }
117 
118  pos_type getBeg() { return _reader.getBeg(); }
119  pos_type getCur() { return _reader.getCur(); }
120  pos_type getEnd() { return _reader.getEnd(); }
121 
122  pos_type setCur(pos_type cur) { return _reader.setCur(cur); }
123  };
124 
125 
127  {
128  typedef CharReader SUPER;
129 
130  public:
131  LineFeedReader(ID3_Reader& reader) : SUPER(reader) { ; }
132  int_type readChar();
133  };
134 
136  {
137  typedef CharReader SUPER;
138 
139  public:
140  UnsyncedReader(ID3_Reader& reader) : SUPER(reader) { }
141  int_type readChar();
142  };
143 
145  {
146  char_type* _uncompressed;
147  public:
148  CompressedReader(ID3_Reader& reader, size_type newSize);
149  virtual ~CompressedReader();
150  };
151 
153  {
154  typedef ID3_Writer SUPER;
155 
156  ID3_Writer& _writer;
157  int_type _last;
158  size_type _numSyncs;
159 
160  public:
162  : _writer(writer), _last('\0'), _numSyncs(0)
163  { ; }
164 
165  size_type getNumSyncs() const { return _numSyncs; }
166  int_type writeChar(char_type ch);
167  void flush();
168 
174  size_type writeChars(const char_type[], 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 
180  void close() { ; }
181 
182  pos_type getBeg() { return _writer.getBeg(); }
183  pos_type getCur() { return _writer.getCur(); }
184  pos_type getEnd() { return _writer.getEnd(); }
185  };
186 
188  {
189  typedef ID3_Writer SUPER;
190 
191  ID3_Writer& _writer;
192  BString _data;
193  size_type _origSize;
194  public:
195 
196  explicit CompressedWriter(ID3_Writer& writer)
197  : _writer(writer), _data(), _origSize(0)
198  { ; }
199  virtual ~CompressedWriter() { this->flush(); }
200 
201  size_type getOrigSize() const { return _origSize; }
202 
203  void flush();
204 
205  size_type writeChars(const char_type 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 
211  pos_type getCur() { return _data.size(); }
212  void close() { ; }
213  };
214  };
215 };
216 
217 #endif /* _ID3LIB_READER_DECORATORS_H_ */
218 
dami::io::CompressedWriter::flush
void flush()
Flush the writer.
Definition: io_decorators.cpp:257
io_helpers.h
ID3_Reader::getCur
virtual pos_type getCur()=0
Return the current position in the reader.
dami::io::CharReader::_reader
ID3_Reader & _reader
Definition: io_decorators.h:97
ID3_Writer::getBeg
virtual pos_type getBeg()
Return the beginning position in the writer.
Definition: writer.h:50
ID3_Writer::pos_type
uint32 pos_type
Definition: writer.h:38
dami::io::WindowedReader::WindowedReader
WindowedReader(ID3_Reader &reader)
Definition: io_decorators.h:54
dami::io::UnsyncedReader::UnsyncedReader
UnsyncedReader(ID3_Reader &reader)
Definition: io_decorators.h:140
dami::io::CompressedWriter::CompressedWriter
CompressedWriter(ID3_Writer &writer)
Definition: io_decorators.h:196
dami::io::CompressedWriter::getCur
pos_type getCur()
Return the next position that will be written to.
Definition: io_decorators.h:211
dami::io::UnsyncedWriter::getEnd
pos_type getEnd()
Return the first position that can't be written to.
Definition: io_decorators.h:184
dami::io::WindowedReader
Set a window on the buffer.
Definition: io_decorators.h:43
dami::io::UnsyncedWriter::close
void close()
Close the writer.
Definition: io_decorators.h:180
dami::io::WindowedReader::WindowedReader
WindowedReader(ID3_Reader &reader, size_type size)
Definition: io_decorators.h:57
ID3_Writer::char_type
uint8 char_type
Definition: writer.h:37
dami::io::UnsyncedReader
Definition: io_decorators.h:135
dami::io::CharReader::getCur
pos_type getCur()
Return the current position in the reader.
Definition: io_decorators.h:119
dami::io::WindowedReader::getCur
pos_type getCur()
Return the current position in the reader.
Definition: io_decorators.h:74
dami::io::WindowedReader::readChars
size_type readChars(char buf[], size_type len)
Definition: io_decorators.h:84
dami::io::CharReader::CharReader
CharReader(ID3_Reader &reader)
Definition: io_decorators.h:101
dami::io::CompressedWriter::writeChars
size_type writeChars(const char buf[], size_type len)
Definition: io_decorators.h:206
ID3_Reader::pos_type
uint32 pos_type
Definition: reader.h:38
ID3_Reader::peekChar
virtual int_type peekChar()=0
Return the next character to be read without advancing the internal position.
dami::io::LineFeedReader::LineFeedReader
LineFeedReader(ID3_Reader &reader)
Definition: io_decorators.h:131
ID3_Reader
Definition: reader.h:33
dami::io::CompressedWriter::~CompressedWriter
virtual ~CompressedWriter()
Definition: io_decorators.h:199
ID3_Reader::int_type
int16 int_type
Definition: reader.h:40
dami::io::CharReader::getEnd
pos_type getEnd()
Return the ending position in the reader.
Definition: io_decorators.h:120
ID3_Reader::char_type
uint8 char_type
Definition: reader.h:37
dami::io::CharReader::close
void close()
Close the reader.
Definition: io_decorators.h:115
ID3_Reader::getEnd
virtual pos_type getEnd()
Return the ending position in the reader.
Definition: reader.h:51
dami::io::CompressedWriter::close
void close()
Close the writer.
Definition: io_decorators.h:212
readers.h
ID3_Reader::getBeg
virtual pos_type getBeg()
Return the beginning position in the reader.
Definition: reader.h:48
ID3_Writer::size_type
uint32 size_type
Definition: writer.h:36
ID3_Writer::getCur
virtual pos_type getCur()=0
Return the next position that will be written to.
dami
Definition: tag_impl.h:41
dami::io::UnsyncedWriter
Definition: io_decorators.h:152
dami::io::CharReader::setCur
pos_type setCur(pos_type cur)
Set the value of the current position for reading.
Definition: io_decorators.h:122
dami::io::UnsyncedWriter::UnsyncedWriter
UnsyncedWriter(ID3_Writer &writer)
Definition: io_decorators.h:161
dami::io::CompressedReader
Definition: io_decorators.h:144
dami::io::CompressedWriter::writeChars
size_type writeChars(const char_type buf[], size_type len)
Write up to len characters into buf and advance the internal position accordingly.
Definition: io_decorators.cpp:292
dami::io::UnsyncedWriter::getBeg
pos_type getBeg()
Return the beginning position in the writer.
Definition: io_decorators.h:182
dami::io::WindowedReader::getBeg
pos_type getBeg()
Return the beginning position in the reader.
Definition: io_decorators.h:75
dami::io::UnsyncedWriter::writeChars
size_type writeChars(const char buf[], size_type len)
Definition: io_decorators.h:175
dami::io::UnsyncedWriter::getCur
pos_type getCur()
Return the next position that will be written to.
Definition: io_decorators.h:183
dami::io::CompressedWriter
Definition: io_decorators.h:187
dami::io::CharReader
Definition: io_decorators.h:92
dami::io::WindowedReader::setCur
pos_type setCur(pos_type cur)
Set the value of the current position for reading.
Definition: io_decorators.h:68
ID3_Writer
Definition: writer.h:33
ID3_Reader::size_type
uint32 size_type
Definition: reader.h:36
ID3_Writer::getEnd
virtual pos_type getEnd()
Return the first position that can't be written to.
Definition: writer.h:55
dami::io::LineFeedReader
Definition: io_decorators.h:126
ID3_Reader::setCur
virtual pos_type setCur(pos_type pos)=0
Set the value of the current position for reading.
dami::io::CharReader::readChars
size_type readChars(char buf[], size_type len)
Definition: io_decorators.h:110
dami::io::CharReader::~CharReader
virtual ~CharReader()
Definition: io_decorators.h:102
dami::io::CharReader::getBeg
pos_type getBeg()
Return the beginning position in the reader.
Definition: io_decorators.h:118
dami::io::WindowedReader::WindowedReader
WindowedReader(ID3_Reader &reader, pos_type beg, size_type size)
Definition: io_decorators.h:61
ID3_CPP_EXPORT
#define ID3_CPP_EXPORT
Definition: globals.h:79
dami::io::CompressedWriter::getOrigSize
size_type getOrigSize() const
Definition: io_decorators.h:201
dami::io::CharReader::peekChar
int_type peekChar()
Return the next character to be read without advancing the internal position.
Definition: io_decorators.h:116
ID3_MemoryReader
Definition: readers.h:88
dami::io::WindowedReader::inWindow
bool inWindow()
Definition: io_decorators.h:78
dami::io::UnsyncedWriter::getNumSyncs
size_type getNumSyncs() const
Definition: io_decorators.h:165
dami::io::WindowedReader::close
void close()
Close the reader.
Definition: io_decorators.h:89
dami::io::WindowedReader::getEnd
pos_type getEnd()
Return the ending position in the reader.
Definition: io_decorators.h:76