<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>id3lib: include/id3/readers.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="id3lib.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.3 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <h1>include/id3/readers.h</h1><a href="readers_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// -*- C++ -*-</span> <a name="l00002"></a>00002 <span class="comment">// $Id: readers.h,v 1.12 2002/06/29 17:43:42 t1mpy Exp $</span> <a name="l00003"></a>00003 <a name="l00004"></a>00004 <span class="comment">// id3lib: a software library for creating and manipulating id3v1/v2 tags</span> <a name="l00005"></a>00005 <span class="comment">// Copyright 1999, 2000 Scott Thomas Haug</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 <span class="comment">// This library is free software; you can redistribute it and/or modify it</span> <a name="l00008"></a>00008 <span class="comment">// under the terms of the GNU Library General Public License as published by</span> <a name="l00009"></a>00009 <span class="comment">// the Free Software Foundation; either version 2 of the License, or (at your</span> <a name="l00010"></a>00010 <span class="comment">// option) any later version.</span> <a name="l00011"></a>00011 <span class="comment">//</span> <a name="l00012"></a>00012 <span class="comment">// This library is distributed in the hope that it will be useful, but WITHOUT</span> <a name="l00013"></a>00013 <span class="comment">// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</span> <a name="l00014"></a>00014 <span class="comment">// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public</span> <a name="l00015"></a>00015 <span class="comment">// License for more details.</span> <a name="l00016"></a>00016 <span class="comment">//</span> <a name="l00017"></a>00017 <span class="comment">// You should have received a copy of the GNU Library General Public License</span> <a name="l00018"></a>00018 <span class="comment">// along with this library; if not, write to the Free Software Foundation,</span> <a name="l00019"></a>00019 <span class="comment">// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <span class="comment">// The id3lib authors encourage improvements and optimisations to be sent to</span> <a name="l00022"></a>00022 <span class="comment">// the id3lib coordinator. Please see the README file for details on where to</span> <a name="l00023"></a>00023 <span class="comment">// send such submissions. See the AUTHORS file for a list of people who have</span> <a name="l00024"></a>00024 <span class="comment">// contributed to id3lib. See the ChangeLog file for a list of changes to</span> <a name="l00025"></a>00025 <span class="comment">// id3lib. These files are distributed with id3lib at</span> <a name="l00026"></a>00026 <span class="comment">// http://download.sourceforge.net/id3lib/</span> <a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="preprocessor">#ifndef _ID3LIB_READERS_H_</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define _ID3LIB_READERS_H_</span> <a name="l00030"></a>00030 <span class="preprocessor"></span> <a name="l00031"></a>00031 <span class="preprocessor">#include "id3/id3lib_streams.h"</span> <a name="l00032"></a>00032 <span class="preprocessor">#include "<a class="code" href="reader_8h.html">id3/reader.h</a>"</span> <a name="l00033"></a>00033 <a name="l00034"></a><a class="code" href="class_i_d3___i_stream_reader.html">00034</a> <span class="keyword">class </span><a class="code" href="globals_8h.html#aa7668e1ebc5c8b89aef71dd98e547f77">ID3_CPP_EXPORT</a> <a class="code" href="class_i_d3___i_stream_reader.html">ID3_IStreamReader</a> : <span class="keyword">public</span> <a class="code" href="class_i_d3___reader.html">ID3_Reader</a> <a name="l00035"></a>00035 { <a name="l00036"></a>00036 istream& _stream; <a name="l00037"></a>00037 <span class="keyword">protected</span>: <a name="l00038"></a><a class="code" href="class_i_d3___i_stream_reader.html#a78bc19b52a437d0096f53c2efc12ff20">00038</a> istream& <a class="code" href="class_i_d3___i_stream_reader.html#a78bc19b52a437d0096f53c2efc12ff20">getReader</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _stream; } <a name="l00039"></a>00039 <span class="keyword">public</span>: <a name="l00040"></a><a class="code" href="class_i_d3___i_stream_reader.html#a9e7a987da828c3e68c200ad8734a57f9">00040</a> <a class="code" href="class_i_d3___i_stream_reader.html#a9e7a987da828c3e68c200ad8734a57f9">ID3_IStreamReader</a>(istream& reader) : _stream(reader) { ; } <a name="l00041"></a><a class="code" href="class_i_d3___i_stream_reader.html#a103bf92404d004bf43640d8ea25c21da">00041</a> <span class="keyword">virtual</span> <a class="code" href="class_i_d3___i_stream_reader.html#a103bf92404d004bf43640d8ea25c21da">~ID3_IStreamReader</a>() { ; } <a name="l00042"></a><a class="code" href="class_i_d3___i_stream_reader.html#aa9afe811196cc5f3195a04283508c0f4">00042</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="class_i_d3___i_stream_reader.html#aa9afe811196cc5f3195a04283508c0f4" title="Close the reader.">close</a>() { ; } <a name="l00043"></a>00043 <a name="l00044"></a><a class="code" href="class_i_d3___i_stream_reader.html#a4f62667272a106f978414f57b0addbd7">00044</a> <span class="keyword">virtual</span> int_type <a class="code" href="class_i_d3___i_stream_reader.html#a4f62667272a106f978414f57b0addbd7" title="Return the next character to be read without advancing the internal position.">peekChar</a>() { <span class="keywordflow">return</span> _stream.peek(); } <a name="l00045"></a>00045 <a name="l00049"></a><a class="code" href="class_i_d3___i_stream_reader.html#a4a55e63a025be2476b882bef42681b9e">00049</a> <span class="keyword">virtual</span> size_type <a class="code" href="class_i_d3___reader.html#a271015a0481e80ca63bfea9ff9320a50" title="Read up to len characters into buf and advance the internal position accordingly...">readChars</a>(<span class="keywordtype">char</span> buf[], size_type len) <a name="l00050"></a>00050 { <a name="l00051"></a>00051 <span class="keywordflow">return</span> this-><a class="code" href="class_i_d3___reader.html#a271015a0481e80ca63bfea9ff9320a50" title="Read up to len characters into buf and advance the internal position accordingly...">readChars</a>(reinterpret_cast<uchar *>(buf), len); <a name="l00052"></a>00052 } <a name="l00053"></a><a class="code" href="class_i_d3___i_stream_reader.html#abb918ea450bc65552e7e2f0009aaf03f">00053</a> <span class="keyword">virtual</span> size_type <a class="code" href="class_i_d3___reader.html#a271015a0481e80ca63bfea9ff9320a50" title="Read up to len characters into buf and advance the internal position accordingly...">readChars</a>(char_type buf[], size_type len) <a name="l00054"></a>00054 { <a name="l00055"></a>00055 _stream.read((<span class="keywordtype">char</span> *)buf, len); <a name="l00056"></a>00056 <span class="keywordflow">return</span> _stream.gcount(); <a name="l00057"></a>00057 } <a name="l00058"></a>00058 <a name="l00059"></a><a class="code" href="class_i_d3___i_stream_reader.html#a1c9f2552b6f25f2348dc04e4a283dc71">00059</a> <span class="keyword">virtual</span> pos_type <a class="code" href="class_i_d3___i_stream_reader.html#a1c9f2552b6f25f2348dc04e4a283dc71" title="Return the beginning position in the reader.">getBeg</a>() { <span class="keywordflow">return</span> 0; } <a name="l00060"></a><a class="code" href="class_i_d3___i_stream_reader.html#ac078db2a5d070087599ae5bf7417701e">00060</a> <span class="keyword">virtual</span> pos_type <a class="code" href="class_i_d3___i_stream_reader.html#ac078db2a5d070087599ae5bf7417701e" title="Return the current position in the reader.">getCur</a>() { <span class="keywordflow">return</span> _stream.tellg(); } <a name="l00061"></a><a class="code" href="class_i_d3___i_stream_reader.html#a7ed8f110ac744ddb6b0a789b20df3548">00061</a> <span class="keyword">virtual</span> pos_type <a class="code" href="class_i_d3___reader.html#a5872b6813a652d831b770bfb7d65aec8" title="Return the ending position in the reader.">getEnd</a>() <a name="l00062"></a>00062 { <a name="l00063"></a>00063 pos_type cur = this-><a class="code" href="class_i_d3___reader.html#a232935e138e44ea49e5a289fb8d7ac94" title="Return the current position in the reader.">getCur</a>(); <a name="l00064"></a>00064 _stream.seekg(0, ios::end); <a name="l00065"></a>00065 pos_type end = this-><a class="code" href="class_i_d3___reader.html#a232935e138e44ea49e5a289fb8d7ac94" title="Return the current position in the reader.">getCur</a>(); <a name="l00066"></a>00066 this-><a class="code" href="class_i_d3___reader.html#a1630f369cc7aa65a2279542715e9f483" title="Set the value of the current position for reading.">setCur</a>(cur); <a name="l00067"></a>00067 <span class="keywordflow">return</span> end; <a name="l00068"></a>00068 } <a name="l00069"></a>00069 <a name="l00072"></a><a class="code" href="class_i_d3___i_stream_reader.html#acf335334973e5a654125fcebdc129844">00072</a> <span class="keyword">virtual</span> pos_type <a class="code" href="class_i_d3___i_stream_reader.html#acf335334973e5a654125fcebdc129844" title="Set the value of the internal position for reading.">setCur</a>(pos_type pos) { _stream.seekg(pos); <span class="keywordflow">return</span> pos; } <a name="l00073"></a>00073 }; <a name="l00074"></a>00074 <a name="l00075"></a><a class="code" href="class_i_d3___i_f_stream_reader.html">00075</a> <span class="keyword">class </span><a class="code" href="globals_8h.html#aa7668e1ebc5c8b89aef71dd98e547f77">ID3_CPP_EXPORT</a> <a class="code" href="class_i_d3___i_f_stream_reader.html">ID3_IFStreamReader</a> : <span class="keyword">public</span> <a class="code" href="class_i_d3___i_stream_reader.html">ID3_IStreamReader</a> <a name="l00076"></a>00076 { <a name="l00077"></a>00077 ifstream& _file; <a name="l00078"></a>00078 <span class="keyword">public</span>: <a name="l00079"></a><a class="code" href="class_i_d3___i_f_stream_reader.html#a3c68c024eee5c0b1645a69af3670fb6a">00079</a> <a class="code" href="class_i_d3___i_f_stream_reader.html">ID3_IFStreamReader</a>(ifstream& reader) <a name="l00080"></a>00080 : <a class="code" href="class_i_d3___i_stream_reader.html">ID3_IStreamReader</a>(reader), _file(reader) { ; } <a name="l00081"></a>00081 <a name="l00082"></a><a class="code" href="class_i_d3___i_f_stream_reader.html#a26b103da4bed0649b360d20ac5c2717d">00082</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="class_i_d3___i_stream_reader.html#aa9afe811196cc5f3195a04283508c0f4" title="Close the reader.">close</a>() <a name="l00083"></a>00083 { <a name="l00084"></a>00084 _file.close(); <a name="l00085"></a>00085 } <a name="l00086"></a>00086 }; <a name="l00087"></a>00087 <a name="l00088"></a><a class="code" href="class_i_d3___memory_reader.html">00088</a> <span class="keyword">class </span><a class="code" href="globals_8h.html#aa7668e1ebc5c8b89aef71dd98e547f77">ID3_CPP_EXPORT</a> <a class="code" href="class_i_d3___memory_reader.html">ID3_MemoryReader</a> : <span class="keyword">public</span> <a class="code" href="class_i_d3___reader.html">ID3_Reader</a> <a name="l00089"></a>00089 { <a name="l00090"></a>00090 <span class="keyword">const</span> char_type* _beg; <a name="l00091"></a>00091 <span class="keyword">const</span> char_type* _cur; <a name="l00092"></a>00092 <span class="keyword">const</span> char_type* _end; <a name="l00093"></a>00093 <span class="keyword">protected</span>: <a name="l00094"></a><a class="code" href="class_i_d3___memory_reader.html#a9ecad00b4e5e465878658c0cca102f88">00094</a> <span class="keywordtype">void</span> setBuffer(<span class="keyword">const</span> char_type* buf, size_type size) <a name="l00095"></a>00095 { <a name="l00096"></a>00096 _beg = buf; <a name="l00097"></a>00097 _cur = buf; <a name="l00098"></a>00098 _end = buf + size; <a name="l00099"></a>00099 }; <a name="l00100"></a>00100 <span class="keyword">public</span>: <a name="l00101"></a><a class="code" href="class_i_d3___memory_reader.html#a4336b7684a069de93d84d758a5a534ea">00101</a> <a class="code" href="class_i_d3___memory_reader.html">ID3_MemoryReader</a>() <a name="l00102"></a>00102 { <a name="l00103"></a>00103 this->setBuffer(<a class="code" href="globals_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>, 0); <a name="l00104"></a>00104 } <a name="l00105"></a><a class="code" href="class_i_d3___memory_reader.html#a3ff40d2949548f69ff1826243778c553">00105</a> <a class="code" href="class_i_d3___memory_reader.html">ID3_MemoryReader</a>(<span class="keyword">const</span> char_type* buf, size_type size) <a name="l00106"></a>00106 { <a name="l00107"></a>00107 this->setBuffer(buf, size); <a name="l00108"></a>00108 }; <a name="l00109"></a><a class="code" href="class_i_d3___memory_reader.html#adb749fdc582301af03458c6d187add30">00109</a> <a class="code" href="class_i_d3___memory_reader.html">ID3_MemoryReader</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* buf, size_type size) <a name="l00110"></a>00110 { <a name="l00111"></a>00111 this->setBuffer(reinterpret_cast<const char_type*>(buf), size); <a name="l00112"></a>00112 }; <a name="l00113"></a><a class="code" href="class_i_d3___memory_reader.html#a767d09a7917863cf132d52d49d565c7c">00113</a> <span class="keyword">virtual</span> <a class="code" href="class_i_d3___memory_reader.html#a767d09a7917863cf132d52d49d565c7c">~ID3_MemoryReader</a>() { ; } <a name="l00114"></a><a class="code" href="class_i_d3___memory_reader.html#ab9661770c682dcdbc4e03f396c12593d">00114</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="class_i_d3___memory_reader.html#ab9661770c682dcdbc4e03f396c12593d" title="Close the reader.">close</a>() { ; } <a name="l00115"></a>00115 <a name="l00116"></a><a class="code" href="class_i_d3___memory_reader.html#a11f090c8191b9e96589e381fefb91fc4">00116</a> <span class="keyword">virtual</span> int_type <a class="code" href="class_i_d3___reader.html#af2b67659b76a3f28dac16e3522b552cf" title="Return the next character to be read without advancing the internal position.">peekChar</a>() <a name="l00117"></a>00117 { <a name="l00118"></a>00118 <span class="keywordflow">if</span> (!this-><a class="code" href="class_i_d3___reader.html#a2d7e9a6e4c4c5f751035ea507c6cadb5">atEnd</a>()) <a name="l00119"></a>00119 { <a name="l00120"></a>00120 <span class="keywordflow">return</span> *_cur; <a name="l00121"></a>00121 } <a name="l00122"></a>00122 <span class="keywordflow">return</span> END_OF_READER; <a name="l00123"></a>00123 } <a name="l00124"></a>00124 <a name="l00128"></a><a class="code" href="class_i_d3___memory_reader.html#a6a811816f23cb5b84438ee364fecb7ae">00128</a> <span class="keyword">virtual</span> size_type <a class="code" href="class_i_d3___reader.html#a271015a0481e80ca63bfea9ff9320a50" title="Read up to len characters into buf and advance the internal position accordingly...">readChars</a>(<span class="keywordtype">char</span> buf[], size_type len) <a name="l00129"></a>00129 { <a name="l00130"></a>00130 <span class="keywordflow">return</span> this-><a class="code" href="class_i_d3___reader.html#a271015a0481e80ca63bfea9ff9320a50" title="Read up to len characters into buf and advance the internal position accordingly...">readChars</a>(reinterpret_cast<char_type *>(buf), len); <a name="l00131"></a>00131 } <a name="l00132"></a>00132 <span class="keyword">virtual</span> size_type <a class="code" href="class_i_d3___reader.html#a271015a0481e80ca63bfea9ff9320a50" title="Read up to len characters into buf and advance the internal position accordingly...">readChars</a>(char_type buf[], size_type len); <a name="l00133"></a>00133 <a name="l00134"></a><a class="code" href="class_i_d3___memory_reader.html#a2c55aed7fecd258ca9978d1ff11c8cad">00134</a> <span class="keyword">virtual</span> pos_type <a class="code" href="class_i_d3___reader.html#a232935e138e44ea49e5a289fb8d7ac94" title="Return the current position in the reader.">getCur</a>() <a name="l00135"></a>00135 { <a name="l00136"></a>00136 <span class="keywordflow">return</span> _cur - _beg; <a name="l00137"></a>00137 } <a name="l00138"></a>00138 <a name="l00139"></a><a class="code" href="class_i_d3___memory_reader.html#a99c80395434141c096be5dec661e8dca">00139</a> <span class="keyword">virtual</span> pos_type <a class="code" href="class_i_d3___reader.html#aeaf468ffe03c08731dcaf268fff3391b" title="Return the beginning position in the reader.">getBeg</a>() <a name="l00140"></a>00140 { <a name="l00141"></a>00141 <span class="keywordflow">return</span> _beg - _beg; <a name="l00142"></a>00142 } <a name="l00143"></a>00143 <a name="l00144"></a><a class="code" href="class_i_d3___memory_reader.html#a4f146a43b254394359d75646b603d0e2">00144</a> <span class="keyword">virtual</span> pos_type <a class="code" href="class_i_d3___reader.html#a5872b6813a652d831b770bfb7d65aec8" title="Return the ending position in the reader.">getEnd</a>() <a name="l00145"></a>00145 { <a name="l00146"></a>00146 <span class="keywordflow">return</span> _end - _beg; <a name="l00147"></a>00147 } <a name="l00148"></a>00148 <a name="l00151"></a><a class="code" href="class_i_d3___memory_reader.html#aa36a396beb22ffa57feac4d14631f3e4">00151</a> <span class="keyword">virtual</span> pos_type <a class="code" href="class_i_d3___reader.html#a1630f369cc7aa65a2279542715e9f483" title="Set the value of the current position for reading.">setCur</a>(pos_type pos) <a name="l00152"></a>00152 { <a name="l00153"></a>00153 pos_type end = this-><a class="code" href="class_i_d3___reader.html#a5872b6813a652d831b770bfb7d65aec8" title="Return the ending position in the reader.">getEnd</a>(); <a name="l00154"></a>00154 size_type size = (pos < end) ? pos : end; <a name="l00155"></a>00155 _cur = _beg + size; <a name="l00156"></a>00156 <span class="keywordflow">return</span> this-><a class="code" href="class_i_d3___reader.html#a232935e138e44ea49e5a289fb8d7ac94" title="Return the current position in the reader.">getCur</a>(); <a name="l00157"></a>00157 } <a name="l00158"></a>00158 }; <a name="l00159"></a>00159 <a name="l00160"></a>00160 <span class="preprocessor">#endif </span><span class="comment">/* _ID3LIB_READERS_H_ */</span> <a name="l00161"></a>00161 </pre></div></div> <hr class="footer"/><address style="text-align: right;"><small>Generated on Wed Jan 12 23:46:35 2011 for id3lib by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address> </body> </html>