Go to the documentation of this file.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_WRITERS_H_
00029 #define _ID3LIB_WRITERS_H_
00030
00031 #include "id3/writer.h"
00032 #include "id3/id3lib_streams.h"
00033 #include <cstring>
00034
00035 class ID3_CPP_EXPORT ID3_OStreamWriter : public ID3_Writer
00036 {
00037 ostream& _stream;
00038 pos_type _beg;
00039 protected:
00040 ostream& getWriter() const { return _stream; }
00041 public:
00042 ID3_OStreamWriter(ostream& writer) : _stream(writer), _beg(_stream.tellp()) { ; }
00043 virtual ~ID3_OStreamWriter() { ; }
00044
00045 virtual void close() { ; }
00046 virtual void flush() { _stream.flush(); }
00047
00048 virtual int_type writeChar(char_type ch)
00049 {
00050 _stream.put(ch);
00051 return ch;
00052 }
00053
00057 virtual size_type writeChars(const char buf[], size_type len)
00058 {
00059 _stream.write(buf, len);
00060 return len;
00061 }
00062 virtual size_type writeChars(const char_type buf[], size_type len)
00063 {
00064 _stream.write(reinterpret_cast<const char*>(buf), len);
00065 return len;
00066 }
00067
00068 virtual pos_type getBeg() { return _beg; }
00069 virtual pos_type getCur() { return _stream.tellp(); }
00070 };
00071
00072 class ID3_CPP_EXPORT ID3_OFStreamWriter : public ID3_OStreamWriter
00073 {
00074 ofstream& _file;
00075 public:
00076 ID3_OFStreamWriter(ofstream& writer)
00077 : ID3_OStreamWriter(writer), _file(writer) { ; }
00078
00079 virtual void close()
00080 {
00081 _file.close();
00082 }
00083 };
00084
00085 class ID3_CPP_EXPORT ID3_IOStreamWriter : public ID3_Writer
00086 {
00087 iostream& _stream;
00088 pos_type _beg;
00089 protected:
00090 iostream& getWriter() const { return _stream; }
00091 public:
00092 ID3_IOStreamWriter(iostream& writer) : _stream(writer), _beg(_stream.tellp()) { ; }
00093 virtual ~ID3_IOStreamWriter() { ; }
00094
00095 virtual void close() { ; }
00096 virtual void flush() { _stream.flush(); }
00097
00098 virtual int_type writeChar(char_type ch)
00099 {
00100 _stream.put(ch);
00101 return ch;
00102 }
00103
00107 virtual size_type writeChars(const char buf[], size_type len)
00108 {
00109 _stream.write(buf, len);
00110 return len;
00111 }
00112 virtual size_type writeChars(const char_type buf[], size_type len)
00113 {
00114 _stream.write(reinterpret_cast<const char*>(buf), len);
00115 return len;
00116 }
00117
00118 virtual pos_type getBeg() { return _beg; }
00119 virtual pos_type getCur() { return _stream.tellp(); }
00120 };
00121
00122 class ID3_CPP_EXPORT ID3_FStreamWriter : public ID3_IOStreamWriter
00123 {
00124 fstream& _file;
00125 public:
00126 ID3_FStreamWriter(fstream& writer)
00127 : ID3_IOStreamWriter(writer), _file(writer) { ; }
00128
00129 virtual void close()
00130 {
00131 _file.close();
00132 }
00133 };
00134
00135 class ID3_CPP_EXPORT ID3_MemoryWriter : public ID3_Writer
00136 {
00137 const char_type* _beg;
00138 char_type* _cur;
00139 const char_type* _end;
00140 protected:
00141 void setBuffer(char_type* buf, size_t size)
00142 {
00143 _beg = buf;
00144 _cur = buf;
00145 _end = buf + size;
00146 };
00147 public:
00148 ID3_MemoryWriter()
00149 {
00150 this->setBuffer(NULL, 0);
00151 }
00152 ID3_MemoryWriter(char_type buf[], size_t size)
00153 {
00154 this->setBuffer(buf, size);
00155 }
00156 virtual ~ID3_MemoryWriter() { ; }
00157 virtual void close() { ; }
00158 virtual void flush() { ; }
00159
00163 virtual size_type writeChars(const char buf[], size_type len)
00164 {
00165 return this->writeChars(reinterpret_cast<const char_type *>(buf), len);
00166 }
00167 virtual size_type writeChars(const char_type buf[], size_type len)
00168 {
00169 size_type remaining = _end - _cur;
00170 size_type size = (remaining > len) ? len : remaining;
00171 ::memcpy(_cur, buf, size);
00172 _cur += size;
00173 return size;
00174 }
00175
00176 virtual pos_type getCur()
00177 {
00178 return _cur - _beg;
00179 }
00180
00181 virtual pos_type getBeg()
00182 {
00183 return _beg - _beg;
00184 }
00185
00186 virtual pos_type getEnd()
00187 {
00188 return _end - _beg;
00189 }
00190 };
00191
00192 #endif
00193