id3lib 3.8.3

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

readers.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: readers.h,v 1.12 2002/06/29 17:43:42 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_READERS_H_
29 #define _ID3LIB_READERS_H_
30
31 #include "id3/id3lib_streams.h"
32 #include "id3/reader.h"
33
34 class ID3_CPP_EXPORT ID3_IStreamReader : public ID3_Reader
35 {
36 istream& _stream;
37 protected:
38 istream& getReader() const { return _stream; }
39 public:
40 ID3_IStreamReader(istream& reader) : _stream(reader) { ; }
41 virtual ~ID3_IStreamReader() { ; }
42 virtual void close() { ; }
43
44 virtual int_type peekChar() { return _stream.peek(); }
45
49 virtual size_type readChars(char buf[], size_type len)
50 {
51 return this->readChars(reinterpret_cast<uchar *>(buf), len);
52 }
53 virtual size_type readChars(char_type buf[], size_type len)
54 {
55 _stream.read((char *)buf, len);
56 return _stream.gcount();
57 }
58
59 virtual pos_type getBeg() { return 0; }
60 virtual pos_type getCur() { return _stream.tellg(); }
61 virtual pos_type getEnd()
62 {
63 pos_type cur = this->getCur();
64 _stream.seekg(0, ios::end);
65 pos_type end = this->getCur();
66 this->setCur(cur);
67 return end;
68 }
69
72 virtual pos_type setCur(pos_type pos) { _stream.seekg(pos); return pos; }
73 };
74
75 class ID3_CPP_EXPORT ID3_IFStreamReader : public ID3_IStreamReader
76 {
77 ifstream& _file;
78 public:
79 ID3_IFStreamReader(ifstream& reader)
80 : ID3_IStreamReader(reader), _file(reader) { ; }
81
82 virtual void close()
83 {
84 _file.close();
85 }
86 };
87
88 class ID3_CPP_EXPORT ID3_MemoryReader : public ID3_Reader
89 {
90 const char_type* _beg;
91 const char_type* _cur;
92 const char_type* _end;
93 protected:
94 void setBuffer(const char_type* buf, size_type size)
95 {
96 _beg = buf;
97 _cur = buf;
98 _end = buf + size;
99 };
100 public:
101 ID3_MemoryReader()
102 {
103 this->setBuffer(NULL, 0);
104 }
105 ID3_MemoryReader(const char_type* buf, size_type size)
106 {
107 this->setBuffer(buf, size);
108 };
109 ID3_MemoryReader(const char* buf, size_type size)
110 {
111 this->setBuffer(reinterpret_cast<const char_type*>(buf), size);
112 };
113 virtual ~ID3_MemoryReader() { ; }
114 virtual void close() { ; }
115
116 virtual int_type peekChar()
117 {
118 if (!this->atEnd())
119 {
120 return *_cur;
121 }
122 return END_OF_READER;
123 }
124
128 virtual size_type readChars(char buf[], size_type len)
129 {
130 return this->readChars(reinterpret_cast<char_type *>(buf), len);
131 }
132 virtual size_type readChars(char_type buf[], size_type len);
133
134 virtual pos_type getCur()
135 {
136 return _cur - _beg;
137 }
138
139 virtual pos_type getBeg()
140 {
141 return _beg - _beg;
142 }
143
144 virtual pos_type getEnd()
145 {
146 return _end - _beg;
147 }
148
151 virtual pos_type setCur(pos_type pos)
152 {
153 pos_type end = this->getEnd();
154 size_type size = (pos < end) ? pos : end;
155 _cur = _beg + size;
156 return this->getCur();
157 }
158 };
159
160 #endif /* _ID3LIB_READERS_H_ */
161
id3lib_streams.h
ID3_MemoryReader::ID3_MemoryReader
ID3_MemoryReader(const char_type *buf, size_type size)
Definition: readers.h:105
ID3_Reader::END_OF_READER
static const int_type END_OF_READER
Definition: reader.h:41
ID3_IFStreamReader
Definition: readers.h:75
ID3_IStreamReader::getEnd
virtual pos_type getEnd()
Return the ending position in the reader.
Definition: readers.h:61
ID3_MemoryReader::ID3_MemoryReader
ID3_MemoryReader()
Definition: readers.h:101
reader.h
ID3_CPP_EXPORT
#define ID3_CPP_EXPORT
Definition: globals.h:79
ID3_IStreamReader::close
virtual void close()
Close the reader.
Definition: readers.h:42
ID3_Reader::getCur
virtual pos_type getCur()=0
Return the current position in the reader.
ID3_MemoryReader::setCur
virtual pos_type setCur(pos_type pos)
Set the value of the internal position for reading.
Definition: readers.h:151
ID3_Reader::setCur
virtual pos_type setCur(pos_type pos)=0
Set the value of the current position for reading.
ID3_IStreamReader
Definition: readers.h:34
ID3_IStreamReader::setCur
virtual pos_type setCur(pos_type pos)
Set the value of the internal position for reading.
Definition: readers.h:72
ID3_MemoryReader::getCur
virtual pos_type getCur()
Return the current position in the reader.
Definition: readers.h:134
ID3_Reader::readChars
virtual size_type readChars(char_type buf[], size_type len)=0
Read up to len characters into buf and advance the internal position accordingly. ...
ID3_MemoryReader::setBuffer
void setBuffer(const char_type *buf, size_type size)
Definition: readers.h:94
ID3_IStreamReader::getReader
istream & getReader() const
Definition: readers.h:38
ID3_Reader::int_type
int16 int_type
Definition: reader.h:40
ID3_IFStreamReader::ID3_IFStreamReader
ID3_IFStreamReader(ifstream &reader)
Definition: readers.h:79
ID3_MemoryReader::close
virtual void close()
Close the reader.
Definition: readers.h:114
ID3_Reader
Definition: reader.h:33
ID3_IStreamReader::readChars
virtual size_type readChars(char buf[], size_type len)
Read up to len chars into buf and advance the internal position accordingly.
Definition: readers.h:49
ID3_MemoryReader::getBeg
virtual pos_type getBeg()
Return the beginning position in the reader.
Definition: readers.h:139
ID3_IStreamReader::ID3_IStreamReader
ID3_IStreamReader(istream &reader)
Definition: readers.h:40
ID3_IStreamReader::peekChar
virtual int_type peekChar()
Return the next character to be read without advancing the internal position.
Definition: readers.h:44
ID3_Reader::getEnd
virtual pos_type getEnd()
Return the ending position in the reader.
Definition: reader.h:51
ID3_MemoryReader::getEnd
virtual pos_type getEnd()
Return the ending position in the reader.
Definition: readers.h:144
ID3_MemoryReader::peekChar
virtual int_type peekChar()
Return the next character to be read without advancing the internal position.
Definition: readers.h:116
ID3_IStreamReader::getBeg
virtual pos_type getBeg()
Return the beginning position in the reader.
Definition: readers.h:59
ID3_MemoryReader::readChars
virtual size_type readChars(char buf[], size_type len)
Read up to len chars into buf and advance the internal position accordingly.
Definition: readers.h:128
ID3_MemoryReader::~ID3_MemoryReader
virtual ~ID3_MemoryReader()
Definition: readers.h:113
ID3_Reader::size_type
uint32 size_type
Definition: reader.h:36
NULL
#define NULL
Definition: globals.h:743
ID3_Reader::atEnd
virtual bool atEnd()
Definition: reader.h:125
ID3_Reader::pos_type
uint32 pos_type
Definition: reader.h:38
ID3_IStreamReader::~ID3_IStreamReader
virtual ~ID3_IStreamReader()
Definition: readers.h:41
ID3_MemoryReader::ID3_MemoryReader
ID3_MemoryReader(const char *buf, size_type size)
Definition: readers.h:109
ID3_MemoryReader
Definition: readers.h:88
ID3_Reader::char_type
uint8 char_type
Definition: reader.h:37
ID3_IStreamReader::getCur
virtual pos_type getCur()
Return the current position in the reader.
Definition: readers.h:60
ID3_IStreamReader::readChars
virtual size_type readChars(char_type buf[], size_type len)
Read up to len characters into buf and advance the internal position accordingly. ...
Definition: readers.h:53
ID3_IFStreamReader::close
virtual void close()
Close the reader.
Definition: readers.h:82