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
35namespace 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
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);
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);
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
uint32 pos_type
Definition reader.h:38
int16 int_type
Definition reader.h:40
uint32 size_type
Definition reader.h:36
uint8 char_type
Definition reader.h:37
int16 int_type
Definition writer.h:40
uint8 char_type
Definition writer.h:37
uint32 pos_type
Definition writer.h:38
uint32 size_type
Definition writer.h:36
size_type readChars(char buf[], size_type len)
pos_type setCur(pos_type cur)
Set the value of the current position for reading.
int_type peekChar()
Return the next character to be read without advancing the internal position.
CharReader(ID3_Reader &reader)
pos_type getBeg()
Return the beginning position in the reader.
size_type readChars(char_type buf[], size_type len)
Read len characters into the array buf.
pos_type getEnd()
Return the ending position in the reader.
void close()
Close the reader.
pos_type getCur()
Return the current position in the reader.
CompressedReader(ID3_Reader &reader, size_type newSize)
CompressedWriter(ID3_Writer &writer)
pos_type getCur()
Return the next position that will be written to.
void close()
Close the writer.
size_type getOrigSize() const
void flush()
Flush the writer.
size_type writeChars(const char_type buf[], size_type len)
Write up to len characters into buf and advance the internal position accordingly.
size_type writeChars(const char buf[], size_type len)
LineFeedReader(ID3_Reader &reader)
UnsyncedReader(ID3_Reader &reader)
pos_type getBeg()
Return the beginning position in the writer.
size_type getNumSyncs() const
size_type writeChars(const char_type[], size_type len)
Write len characters into the array buf.
size_type writeChars(const char buf[], size_type len)
void close()
Close the writer.
pos_type getEnd()
Return the first position that can't be written to.
pos_type getCur()
Return the next position that will be written to.
UnsyncedWriter(ID3_Writer &writer)
pos_type getCur()
Return the current position in the reader.
WindowedReader(ID3_Reader &reader)
size_type readChars(char buf[], size_type len)
void setWindow(pos_type beg, size_type size)
pos_type getBeg()
Return the beginning position in the reader.
pos_type setCur(pos_type cur)
Set the value of the current position for reading.
pos_type getEnd()
Return the ending position in the reader.
WindowedReader(ID3_Reader &reader, size_type size)
void close()
Close the reader.
size_type readChars(char_type buf[], size_type len)
Read up to len characters into buf and advance the internal position accordingly.
WindowedReader(ID3_Reader &reader, pos_type beg, size_type size)
#define ID3_CPP_EXPORT
Definition globals.h:79