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