id3lib  3.8.3
io_strings.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: io_strings.h,v 1.6 2002/06/29 17:43:24 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_IO_STRINGS_H_
29 #define _ID3LIB_IO_STRINGS_H_
30 
31 #include "id3/id3lib_strings.h"
32 #include "reader.h"
33 #include "writer.h"
34 
35 #ifndef min
36 #define min(a,b) (((a) < (b)) ? (a) : (b))
37 #endif
38 
39 namespace dami
40 {
41  namespace io
42  {
44  {
45  const String& _string;
46  pos_type _cur;
47  public:
48  StringReader(const String& string) : _string(string), _cur(0) { ; }
49  virtual ~StringReader() { ; }
50 
51  virtual void close() { ; }
52  virtual int_type peekChar()
53  {
54  if (!this->atEnd())
55  {
56  return _string[_cur];
57  }
58  return END_OF_READER;
59  }
60 
64  size_type readChars(char buf[], size_type len)
65  {
66  return this->readChars((char_type*) buf, len);
67  }
68  virtual size_type readChars(char_type buf[], size_type len)
69  {
70  size_type size = min((unsigned int)len, (unsigned int)(_string.size() - _cur));
71  _string.copy(reinterpret_cast<String::value_type *>(buf), size, _cur);
72  _cur += size;
73  return size;
74  }
75 
76  virtual pos_type getCur()
77  {
78  return _cur;
79  }
80 
81  virtual pos_type getBeg()
82  {
83  return 0;
84  }
85 
86  virtual pos_type getEnd()
87  {
88  return _string.size();
89  }
90 
93  virtual pos_type setCur(pos_type pos)
94  {
95  pos_type end = this->getEnd();
96  _cur = (pos < end) ? pos : end;
97  return _cur;
98  }
99 
100  virtual bool atEnd()
101  {
102  return _cur >= _string.size();
103  }
104 
106  {
107  size_type size = min((unsigned int)len, (unsigned int)(_string.size() - _cur));
108  _cur += size;
109  return size;
110  }
111  };
112 
114  {
115  const BString& _string;
116  pos_type _cur;
117  public:
118  BStringReader(const BString& string) : _string(string), _cur(0) { ; }
119  virtual ~BStringReader() { ; }
120 
121  virtual void close() { ; }
122  virtual int_type peekChar()
123  {
124  if (!this->atEnd())
125  {
126  return _string[_cur];
127  }
128  return END_OF_READER;
129  }
130 
134  size_type readChars(char buf[], size_type len)
135  {
136  return this->readChars((char_type*) buf, len);
137  }
139  {
140  size_type size = min((unsigned int)len, (unsigned int)(_string.size() - _cur));
141  _string.copy(reinterpret_cast<BString::value_type *>(buf), size, _cur);
142  _cur += size;
143  return size;
144  }
145 
146  virtual pos_type getCur()
147  {
148  return _cur;
149  }
150 
151  virtual pos_type getBeg()
152  {
153  return 0;
154  }
155 
156  virtual pos_type getEnd()
157  {
158  return _string.size();
159  }
160 
163  virtual pos_type setCur(pos_type pos)
164  {
165  pos_type end = this->getEnd();
166  _cur = (pos < end) ? pos : end;
167  return _cur;
168  }
169 
170  virtual bool atEnd()
171  {
172  return _cur >= _string.size();
173  }
174 
176  {
177  size_type size = min((unsigned int)len,(unsigned int)( _string.size() - _cur));
178  _cur += size;
179  return size;
180  }
181  };
182 
184  {
185  String& _string;
186  public:
187  StringWriter(String& string) : _string(string) { ; }
188  virtual ~StringWriter() { ; }
189 
190  void close() { ; }
191  void flush() { ; }
192  virtual size_type writeChars(const char buf[], size_type len)
193  {
194  _string.append(reinterpret_cast<const String::value_type *>(buf), len);
195  return len;
196  }
198  {
199  _string.append(reinterpret_cast<const String::value_type *>(buf), len);
200  return len;
201  }
202 
204  {
205  return _string.size();
206  }
207  };
208 
210  {
211  BString& _string;
212  public:
213  BStringWriter(BString& string) : _string(string) { ; }
214  virtual ~BStringWriter() { ; }
215 
216  void close() { ; }
217  void flush() { ; }
218  virtual size_type writeChars(const char buf[], size_type len)
219  {
220  _string.append(reinterpret_cast<const BString::value_type *>(buf), len);
221  return len;
222  }
224  {
225  _string.append(reinterpret_cast<const BString::value_type *>(buf), len);
226  return len;
227  }
228 
230  {
231  return _string.size();
232  }
233  };
234  };
235 };
236 
237 #endif /* _ID3LIB_IO_STRINGS_H_ */
238 
virtual int_type peekChar()
Return the next character to be read without advancing the internal position.
Definition: io_strings.h:122
pos_type getCur()
Return the next position that will be written to.
Definition: io_strings.h:229
void flush()
Flush the writer.
Definition: io_strings.h:217
size_type readChars(char buf[], size_type len)
Read up to len chars into buf and advance the internal position accordingly.
Definition: io_strings.h:134
virtual pos_type getBeg()
Return the beginning position in the reader.
Definition: io_strings.h:151
virtual pos_type getEnd()
Return the ending position in the reader.
Definition: io_strings.h:156
virtual ~StringReader()
Definition: io_strings.h:49
#define ID3_CPP_EXPORT
Definition: globals.h:79
virtual size_type skipChars(size_type len)
Skip up to len chars in the stream and advance the internal position accordingly. ...
Definition: io_strings.h:105
uint32 size_type
Definition: writer.h:36
pos_type getCur()
Return the next position that will be written to.
Definition: io_strings.h:203
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_strings.h:223
virtual size_type readChars(char_type buf[], size_type len)
Read up to len characters into buf and advance the internal position accordingly. ...
Definition: io_strings.h:68
StringWriter(String &string)
Definition: io_strings.h:187
#define min(a, b)
Definition: io_strings.h:36
uint8 char_type
Definition: writer.h:37
virtual pos_type getEnd()
Return the ending position in the reader.
Definition: io_strings.h:86
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_strings.h:197
virtual int_type peekChar()
Return the next character to be read without advancing the internal position.
Definition: io_strings.h:52
int16 int_type
Definition: reader.h:40
virtual size_type writeChars(const char buf[], size_type len)
Definition: io_strings.h:192
Definition: tag_impl.h:41
size_type readChars(char buf[], size_type len)
Read up to len chars into buf and advance the internal position accordingly.
Definition: io_strings.h:64
void close()
Close the writer.
Definition: io_strings.h:216
virtual void close()
Close the reader.
Definition: io_strings.h:51
virtual pos_type getBeg()
Return the beginning position in the reader.
Definition: io_strings.h:81
uint32 pos_type
Definition: writer.h:38
virtual pos_type setCur(pos_type pos)
Set the value of the internal position for reading.
Definition: io_strings.h:93
BStringReader(const BString &string)
Definition: io_strings.h:118
virtual size_type readChars(char_type buf[], size_type len)
Read up to len characters into buf and advance the internal position accordingly. ...
Definition: io_strings.h:138
virtual bool atEnd()
Definition: io_strings.h:170
virtual pos_type getCur()
Return the current position in the reader.
Definition: io_strings.h:146
BStringWriter(BString &string)
Definition: io_strings.h:213
uint32 size_type
Definition: reader.h:36
virtual pos_type setCur(pos_type pos)
Set the value of the internal position for reading.
Definition: io_strings.h:163
virtual size_type writeChars(const char buf[], size_type len)
Definition: io_strings.h:218
uint32 pos_type
Definition: reader.h:38
virtual size_type skipChars(size_type len)
Skip up to len chars in the stream and advance the internal position accordingly. ...
Definition: io_strings.h:175
void flush()
Flush the writer.
Definition: io_strings.h:191
StringReader(const String &string)
Definition: io_strings.h:48
virtual bool atEnd()
Definition: io_strings.h:100
void close()
Close the writer.
Definition: io_strings.h:190
uint8 char_type
Definition: reader.h:37
virtual void close()
Close the reader.
Definition: io_strings.h:121
virtual pos_type getCur()
Return the current position in the reader.
Definition: io_strings.h:76