00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
#ifndef _ID3LIB_IO_STRINGS_H_
00029
#define _ID3LIB_IO_STRINGS_H_
00030
00031
#include "id3/id3lib_strings.h"
00032
#include "reader.h"
00033
#include "writer.h"
00034
00035
#ifndef min
00036 #define min(a,b) (((a) < (b)) ? (a) : (b))
00037
#endif
00038
00039
namespace dami
00040 {
00041
namespace io
00042 {
00043 class ID3_CPP_EXPORT StringReader :
public ID3_Reader
00044 {
00045
const String& _string;
00046 pos_type _cur;
00047
public:
00048 StringReader(
const String& string) : _string(string), _cur(0) { ; }
00049 virtual ~StringReader() { ; }
00050
00051 virtual void close() { ; }
00052 virtual int_type peekChar()
00053 {
00054
if (!this->atEnd())
00055 {
00056
return _string[_cur];
00057 }
00058
return END_OF_READER;
00059 }
00060
00064 size_type readChars(
char buf[], size_type len)
00065 {
00066
return this->readChars((char_type*) buf, len);
00067 }
00068 virtual size_type readChars(char_type buf[], size_type len)
00069 {
00070 size_type size =
min((
unsigned int)len, (
unsigned int)(_string.size() - _cur));
00071 _string.copy(reinterpret_cast<String::value_type *>(buf), size, _cur);
00072 _cur += size;
00073
return size;
00074 }
00075
00076 virtual pos_type getCur()
00077 {
00078
return _cur;
00079 }
00080
00081 virtual pos_type getBeg()
00082 {
00083
return 0;
00084 }
00085
00086 virtual pos_type getEnd()
00087 {
00088
return _string.size();
00089 }
00090
00093 virtual pos_type setCur(pos_type pos)
00094 {
00095 pos_type end = this->getEnd();
00096 _cur = (pos < end) ? pos : end;
00097
return _cur;
00098 }
00099
00100 virtual bool atEnd()
00101 {
00102
return _cur >= _string.size();
00103 }
00104
00105 virtual size_type skipChars(size_type len)
00106 {
00107 size_type size =
min((
unsigned int)len, (
unsigned int)(_string.size() - _cur));
00108 _cur += size;
00109
return size;
00110 }
00111 };
00112
00113 class ID3_CPP_EXPORT BStringReader :
public ID3_Reader
00114 {
00115
const BString& _string;
00116 pos_type _cur;
00117
public:
00118 BStringReader(
const BString& string) : _string(string), _cur(0) { ; }
00119 virtual ~BStringReader() { ; }
00120
00121 virtual void close() { ; }
00122 virtual int_type peekChar()
00123 {
00124
if (!this->atEnd())
00125 {
00126
return _string[_cur];
00127 }
00128
return END_OF_READER;
00129 }
00130
00134 size_type readChars(
char buf[], size_type len)
00135 {
00136
return this->readChars((char_type*) buf, len);
00137 }
00138 virtual size_type readChars(char_type buf[], size_type len)
00139 {
00140 size_type size =
min((
unsigned int)len, (
unsigned int)(_string.size() - _cur));
00141 _string.copy(reinterpret_cast<BString::value_type *>(buf), size, _cur);
00142 _cur += size;
00143
return size;
00144 }
00145
00146 virtual pos_type getCur()
00147 {
00148
return _cur;
00149 }
00150
00151 virtual pos_type getBeg()
00152 {
00153
return 0;
00154 }
00155
00156 virtual pos_type getEnd()
00157 {
00158
return _string.size();
00159 }
00160
00163 virtual pos_type setCur(pos_type pos)
00164 {
00165 pos_type end = this->getEnd();
00166 _cur = (pos < end) ? pos : end;
00167
return _cur;
00168 }
00169
00170 virtual bool atEnd()
00171 {
00172
return _cur >= _string.size();
00173 }
00174
00175 virtual size_type skipChars(size_type len)
00176 {
00177 size_type size =
min((
unsigned int)len,(
unsigned int)( _string.size() - _cur));
00178 _cur += size;
00179
return size;
00180 }
00181 };
00182
00183 class ID3_CPP_EXPORT StringWriter :
public ID3_Writer
00184 {
00185 String& _string;
00186
public:
00187 StringWriter(String& string) : _string(string) { ; }
00188 virtual ~StringWriter() { ; }
00189
00190 void close() { ; }
00191 void flush() { ; }
00192 virtual size_type writeChars(
const char buf[], size_type len)
00193 {
00194 _string.append(reinterpret_cast<const String::value_type *>(buf), len);
00195
return len;
00196 }
00197 size_type writeChars(
const char_type buf[], size_type len)
00198 {
00199 _string.append(reinterpret_cast<const String::value_type *>(buf), len);
00200
return len;
00201 }
00202
00203 pos_type getCur()
00204 {
00205
return _string.size();
00206 }
00207 };
00208
00209 class ID3_CPP_EXPORT BStringWriter :
public ID3_Writer
00210 {
00211 BString& _string;
00212
public:
00213 BStringWriter(BString& string) : _string(string) { ; }
00214 virtual ~BStringWriter() { ; }
00215
00216 void close() { ; }
00217 void flush() { ; }
00218 virtual size_type writeChars(
const char buf[], size_type len)
00219 {
00220 _string.append(reinterpret_cast<const BString::value_type *>(buf), len);
00221
return len;
00222 }
00223 size_type writeChars(
const char_type buf[], size_type len)
00224 {
00225 _string.append(reinterpret_cast<const BString::value_type *>(buf), len);
00226
return len;
00227 }
00228
00229 pos_type getCur()
00230 {
00231
return _string.size();
00232 }
00233 };
00234 };
00235 };
00236
00237
#endif
00238