id3lib 3.8.3

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

writers.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id: writers.h,v 1.11 2002/07/02 22:11:16 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_WRITERS_H_
29 #define _ID3LIB_WRITERS_H_
30
31 #include "id3/writer.h"
32 #include "id3/id3lib_streams.h"
33 #include "string.h"
34
35 class ID3_CPP_EXPORT ID3_OStreamWriter : public ID3_Writer
36 {
37 ostream& _stream;
38 pos_type _beg;
39 protected:
40 ostream& getWriter() const { return _stream; }
41 public:
42 ID3_OStreamWriter(ostream& writer) : _stream(writer), _beg(_stream.tellp()) { ; }
43 virtual ~ID3_OStreamWriter() { ; }
44
45 virtual void close() { ; }
46 virtual void flush() { _stream.flush(); }
47
48 virtual int_type writeChar(char_type ch)
49 {
50 _stream.put(ch);
51 return ch;
52 }
53
57 virtual size_type writeChars(const char buf[], size_type len)
58 {
59 _stream.write(buf, len);
60 return len;
61 }
62 virtual size_type writeChars(const char_type buf[], size_type len)
63 {
64 _stream.write(reinterpret_cast<const char*>(buf), len);
65 return len;
66 }
67
68 virtual pos_type getBeg() { return _beg; }
69 virtual pos_type getCur() { return _stream.tellp(); }
70 };
71
72 class ID3_CPP_EXPORT ID3_OFStreamWriter : public ID3_OStreamWriter
73 {
74 ofstream& _file;
75 public:
76 ID3_OFStreamWriter(ofstream& writer)
77 : ID3_OStreamWriter(writer), _file(writer) { ; }
78
79 virtual void close()
80 {
81 _file.close();
82 }
83 };
84
85 class ID3_CPP_EXPORT ID3_IOStreamWriter : public ID3_Writer
86 {
87 iostream& _stream;
88 pos_type _beg;
89 protected:
90 iostream& getWriter() const { return _stream; }
91 public:
92 ID3_IOStreamWriter(iostream& writer) : _stream(writer), _beg(_stream.tellp()) { ; }
93 virtual ~ID3_IOStreamWriter() { ; }
94
95 virtual void close() { ; }
96 virtual void flush() { _stream.flush(); }
97
98 virtual int_type writeChar(char_type ch)
99 {
100 _stream.put(ch);
101 return ch;
102 }
103
107 virtual size_type writeChars(const char buf[], size_type len)
108 {
109 _stream.write(buf, len);
110 return len;
111 }
112 virtual size_type writeChars(const char_type buf[], size_type len)
113 {
114 _stream.write(reinterpret_cast<const char*>(buf), len);
115 return len;
116 }
117
118 virtual pos_type getBeg() { return _beg; }
119 virtual pos_type getCur() { return _stream.tellp(); }
120 };
121
122 class ID3_CPP_EXPORT ID3_FStreamWriter : public ID3_IOStreamWriter
123 {
124 fstream& _file;
125 public:
126 ID3_FStreamWriter(fstream& writer)
127 : ID3_IOStreamWriter(writer), _file(writer) { ; }
128
129 virtual void close()
130 {
131 _file.close();
132 }
133 };
134
135 class ID3_CPP_EXPORT ID3_MemoryWriter : public ID3_Writer
136 {
137 const char_type* _beg;
138 /* */ char_type* _cur;
139 const char_type* _end;
140 protected:
141 void setBuffer(char_type* buf, size_t size)
142 {
143 _beg = buf;
144 _cur = buf;
145 _end = buf + size;
146 };
147 public:
148 ID3_MemoryWriter()
149 {
150 this->setBuffer(NULL, 0);
151 }
152 ID3_MemoryWriter(char_type buf[], size_t size)
153 {
154 this->setBuffer(buf, size);
155 }
156 virtual ~ID3_MemoryWriter() { ; }
157 virtual void close() { ; }
158 virtual void flush() { ; }
159
163 virtual size_type writeChars(const char buf[], size_type len)
164 {
165 return this->writeChars(reinterpret_cast<const char_type *>(buf), len);
166 }
167 virtual size_type writeChars(const char_type buf[], size_type len)
168 {
169 size_type remaining = _end - _cur;
170 size_type size = (remaining > len) ? len : remaining;
171 ::memcpy(_cur, buf, size);
172 _cur += size;
173 return size;
174 }
175
176 virtual pos_type getCur()
177 {
178 return _cur - _beg;
179 }
180
181 virtual pos_type getBeg()
182 {
183 return _beg - _beg;
184 }
185
186 virtual pos_type getEnd()
187 {
188 return _end - _beg;
189 }
190 };
191
192 #endif /* _ID3LIB_WRITERS_H_ */
193
ID3_IOStreamWriter::flush
virtual void flush()
Flush the writer.
Definition: writers.h:96
id3lib_streams.h
ID3_MemoryWriter::getCur
virtual pos_type getCur()
Return the next position that will be written to.
Definition: writers.h:176
ID3_MemoryWriter::~ID3_MemoryWriter
virtual ~ID3_MemoryWriter()
Definition: writers.h:156
ID3_OFStreamWriter::ID3_OFStreamWriter
ID3_OFStreamWriter(ofstream &writer)
Definition: writers.h:76
ID3_Writer::writeChars
virtual size_type writeChars(const char_type buf[], size_type len)=0
Write up to len characters into buf and advance the internal position accordingly.
ID3_MemoryWriter::flush
virtual void flush()
Flush the writer.
Definition: writers.h:158
ID3_IOStreamWriter::writeChar
virtual int_type writeChar(char_type ch)
Write a single character and advance the internal position.
Definition: writers.h:98
ID3_MemoryWriter
Definition: writers.h:135
ID3_CPP_EXPORT
#define ID3_CPP_EXPORT
Definition: globals.h:79
ID3_Writer::size_type
uint32 size_type
Definition: writer.h:36
ID3_IOStreamWriter::~ID3_IOStreamWriter
virtual ~ID3_IOStreamWriter()
Definition: writers.h:93
ID3_IOStreamWriter::close
virtual void close()
Close the writer.
Definition: writers.h:95
ID3_IOStreamWriter::writeChars
virtual size_type writeChars(const char_type buf[], size_type len)
Write up to len characters into buf and advance the internal position accordingly.
Definition: writers.h:112
ID3_OStreamWriter
Definition: writers.h:35
ID3_OStreamWriter::getBeg
virtual pos_type getBeg()
Return the beginning position in the writer.
Definition: writers.h:68
ID3_FStreamWriter
Definition: writers.h:122
ID3_OStreamWriter::getWriter
ostream & getWriter() const
Definition: writers.h:40
ID3_Writer::int_type
int16 int_type
Definition: writer.h:40
ID3_MemoryWriter::close
virtual void close()
Close the writer.
Definition: writers.h:157
ID3_OStreamWriter::~ID3_OStreamWriter
virtual ~ID3_OStreamWriter()
Definition: writers.h:43
ID3_MemoryWriter::setBuffer
void setBuffer(char_type *buf, size_t size)
Definition: writers.h:141
ID3_IOStreamWriter::getCur
virtual pos_type getCur()
Return the next position that will be written to.
Definition: writers.h:119
ID3_OStreamWriter::writeChars
virtual size_type writeChars(const char_type buf[], size_type len)
Write up to len characters into buf and advance the internal position accordingly.
Definition: writers.h:62
ID3_Writer::char_type
uint8 char_type
Definition: writer.h:37
ID3_OStreamWriter::close
virtual void close()
Close the writer.
Definition: writers.h:45
ID3_IOStreamWriter::writeChars
virtual size_type writeChars(const char buf[], size_type len)
Write up to len chars into buf and advance the internal position accordingly.
Definition: writers.h:107
ID3_OStreamWriter::writeChars
virtual size_type writeChars(const char buf[], size_type len)
Write up to len chars into buf and advance the internal position accordingly.
Definition: writers.h:57
ID3_MemoryWriter::ID3_MemoryWriter
ID3_MemoryWriter()
Definition: writers.h:148
ID3_OFStreamWriter::close
virtual void close()
Close the writer.
Definition: writers.h:79
ID3_MemoryWriter::ID3_MemoryWriter
ID3_MemoryWriter(char_type buf[], size_t size)
Definition: writers.h:152
ID3_Writer::pos_type
uint32 pos_type
Definition: writer.h:38
writer.h
ID3_MemoryWriter::writeChars
virtual size_type writeChars(const char buf[], size_type len)
Write up to len chars from buf and advance the internal position accordingly.
Definition: writers.h:163
ID3_OStreamWriter::writeChar
virtual int_type writeChar(char_type ch)
Write a single character and advance the internal position.
Definition: writers.h:48
ID3_IOStreamWriter::ID3_IOStreamWriter
ID3_IOStreamWriter(iostream &writer)
Definition: writers.h:92
ID3_MemoryWriter::getEnd
virtual pos_type getEnd()
Return the first position that can&#39;t be written to.
Definition: writers.h:186
ID3_IOStreamWriter::getWriter
iostream & getWriter() const
Definition: writers.h:90
NULL
#define NULL
Definition: globals.h:743
ID3_MemoryWriter::getBeg
virtual pos_type getBeg()
Return the beginning position in the writer.
Definition: writers.h:181
ID3_Writer
Definition: writer.h:33
ID3_FStreamWriter::ID3_FStreamWriter
ID3_FStreamWriter(fstream &writer)
Definition: writers.h:126
ID3_OStreamWriter::ID3_OStreamWriter
ID3_OStreamWriter(ostream &writer)
Definition: writers.h:42
ID3_OStreamWriter::getCur
virtual pos_type getCur()
Return the next position that will be written to.
Definition: writers.h:69
ID3_MemoryWriter::writeChars
virtual size_type writeChars(const char_type buf[], size_type len)
Write up to len characters into buf and advance the internal position accordingly.
Definition: writers.h:167
ID3_FStreamWriter::close
virtual void close()
Close the writer.
Definition: writers.h:129
ID3_IOStreamWriter
Definition: writers.h:85
ID3_OFStreamWriter
Definition: writers.h:72
ID3_IOStreamWriter::getBeg
virtual pos_type getBeg()
Return the beginning position in the writer.
Definition: writers.h:118
ID3_OStreamWriter::flush
virtual void flush()
Flush the writer.
Definition: writers.h:46