id3lib  3.8.3
reader.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: reader.h,v 1.13 2002/07/02 22:10:57 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_H_
29 #define _ID3LIB_READER_H_
30 
31 #include "id3/globals.h" //has <stdlib.h> "id3/sized_types.h"
32 
34 {
35  public:
36  typedef uint32 size_type;
37  typedef uint8 char_type;
38  typedef uint32 pos_type;
39  typedef int32 off_type;
40  typedef int16 int_type;
41  static const int_type END_OF_READER;
42 
45  virtual void close() = 0;
46 
48  virtual pos_type getBeg() { return static_cast<pos_type>(0); }
49 
51  virtual pos_type getEnd() { return static_cast<pos_type>(-1); }
52 
54  virtual pos_type getCur() = 0;
55 
58  virtual pos_type setCur(pos_type pos) = 0;
59 
65  virtual int_type readChar()
66  {
67  if (this->atEnd())
68  {
69  return END_OF_READER;
70  }
71  char_type ch;
72  this->readChars(&ch, 1);
73  return ch;
74  }
75 
80  virtual int_type peekChar() = 0;
81 
87  virtual size_type readChars(char_type buf[], size_type len) = 0;
88  virtual size_type readChars(char buf[], size_type len)
89  {
90  return this->readChars(reinterpret_cast<char_type *>(buf), len);
91  }
92 
98  {
99  const size_type SIZE = 1024;
100  char_type bytes[SIZE];
101  size_type remaining = len;
102  while (!this->atEnd() && remaining > 0)
103  {
104  remaining -= this->readChars(bytes, (remaining < SIZE ? remaining : SIZE));
105  }
106  return len - remaining;
107  }
108 
110  {
111  pos_type end = this->getEnd(), cur = this->getCur();
112  if (end == pos_type(-1))
113  {
114  return size_type(-1);
115  }
116 
117  if (end >= cur)
118  {
119  return end - cur;
120  }
121 
122  return 0;
123  }
124 
125  virtual bool atEnd() { return this->getCur() >= this->getEnd(); }
126 };
127 
128 #endif /* _ID3LIB_READER_H_ */
129 
virtual size_type readChars(char buf[], size_type len)
Definition: reader.h:88
virtual size_type skipChars(size_type len)
Skip up to len chars in the stream and advance the internal position accordingly.
Definition: reader.h:97
virtual pos_type setCur(pos_type pos)=0
Set the value of the current position for reading.
static const int_type END_OF_READER
Definition: reader.h:41
virtual pos_type getCur()=0
Return the current position in the reader.
virtual size_type readChars(char_type buf[], size_type len)=0
Read up to len characters into buf and advance the internal position accordingly.
virtual bool atEnd()
Definition: reader.h:125
virtual int_type readChar()
Read a single character and advance the internal position.
Definition: reader.h:65
int32 off_type
Definition: reader.h:39
virtual pos_type getEnd()
Return the ending position in the reader.
Definition: reader.h:51
uint32 pos_type
Definition: reader.h:38
virtual size_type remainingBytes()
Definition: reader.h:109
int16 int_type
Definition: reader.h:40
uint32 size_type
Definition: reader.h:36
uint8 char_type
Definition: reader.h:37
virtual pos_type getBeg()
Return the beginning position in the reader.
Definition: reader.h:48
virtual int_type peekChar()=0
Return the next character to be read without advancing the internal position.
virtual void close()=0
Close the reader.
#define ID3_CPP_EXPORT
Definition: globals.h:79