<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>src/header_frame.cpp Source File</title> <link href="id3lib.css" rel="stylesheet" type="text/css"> </head><body bgcolor="#ffffff"> <!-- Generated by Doxygen 1.2.12 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center> <hr><h1>src/header_frame.cpp</h1><a href="header__frame_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// $Id: header_frame.cpp,v 1.20 2000/10/29 01:37:29 eldamitri Exp $</font> 00002 00003 <font class="comment">// id3lib: a C++ library for creating and manipulating id3v1/v2 tags</font> 00004 <font class="comment">// Copyright 1999, 2000 Scott Thomas Haug</font> 00005 00006 <font class="comment">// This library is free software; you can redistribute it and/or modify it</font> 00007 <font class="comment">// under the terms of the GNU Library General Public License as published by</font> 00008 <font class="comment">// the Free Software Foundation; either version 2 of the License, or (at your</font> 00009 <font class="comment">// option) any later version.</font> 00010 <font class="comment">//</font> 00011 <font class="comment">// This library is distributed in the hope that it will be useful, but WITHOUT</font> 00012 <font class="comment">// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or</font> 00013 <font class="comment">// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public</font> 00014 <font class="comment">// License for more details.</font> 00015 <font class="comment">//</font> 00016 <font class="comment">// You should have received a copy of the GNU Library General Public License</font> 00017 <font class="comment">// along with this library; if not, write to the Free Software Foundation,</font> 00018 <font class="comment">// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</font> 00019 00020 <font class="comment">// The id3lib authors encourage improvements and optimisations to be sent to</font> 00021 <font class="comment">// the id3lib coordinator. Please see the README file for details on where to</font> 00022 <font class="comment">// send such submissions. See the AUTHORS file for a list of people who have</font> 00023 <font class="comment">// contributed to id3lib. See the ChangeLog file for a list of changes to</font> 00024 <font class="comment">// id3lib. These files are distributed with id3lib at</font> 00025 <font class="comment">// http://download.sourceforge.net/id3lib/</font> 00026 00027 <font class="preprocessor">#if defined HAVE_CONFIG_H</font> 00028 <font class="preprocessor"></font><font class="preprocessor">#include <config.h></font> 00029 <font class="preprocessor">#endif</font> 00030 <font class="preprocessor"></font> 00031 00032 00033 <font class="preprocessor">#include <string.h></font> 00034 <font class="preprocessor">#include <memory.h></font> 00035 <font class="preprocessor">#include "<a class="code" href="header__frame_8h.html">header_frame.h</a>"</font> 00036 <font class="preprocessor">#include "utils.h"</font> 00037 <font class="preprocessor">#include "<a class="code" href="frame__def_8h.html">frame_def.h</a>"</font> 00038 <font class="preprocessor">#include "<a class="code" href="field__def_8h.html">field_def.h</a>"</font> 00039 <font class="preprocessor">#include "<a class="code" href="field__impl_8h.html">field_impl.h</a>"</font> 00040 <font class="preprocessor">#include "io_helpers.h"</font> 00041 00042 <font class="keyword">using</font> <font class="keyword">namespace </font>dami; 00043 <a name="l00044"></a><a class="code" href="class_i_d3___frame_header.html#b1">00044</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___frame_header.html#b1">ID3_FrameHeader::SetUnknownFrame</a>(<font class="keyword">const</font> <font class="keywordtype">char</font>* id) 00045 { 00046 <a class="code" href="class_i_d3___frame_header.html#a9">Clear</a>(); 00047 _frame_def = <font class="keyword">new</font> <a class="code" href="struct_i_d3___frame_def.html">ID3_FrameDef</a>; 00048 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == _frame_def) 00049 { 00050 <font class="comment">// log this;</font> 00051 <font class="keywordflow">return</font>; 00052 } 00053 _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m0">eID</a> = <a class="code" href="globals_8h.html#a219a95">ID3FID_NOFRAME</a>; 00054 _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m3">bTagDiscard</a> = <font class="keyword">false</font>; 00055 _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m4">bFileDiscard</a> = <font class="keyword">false</font>; 00056 _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m5">aeFieldDefs</a> = <a class="code" href="struct_i_d3___field_def.html#p0">ID3_FieldDef::DEFAULT</a>; 00057 _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m6">sDescription</a> = <a class="code" href="globals_8h.html#a24">NULL</a>; 00058 <font class="keywordflow">if</font> (strlen(id) <= 3) 00059 { 00060 strcpy(_frame_def-><a class="code" href="struct_i_d3___frame_def.html#m1">sShortTextID</a>, id); 00061 strcpy(_frame_def-><a class="code" href="struct_i_d3___frame_def.html#m2">sLongTextID</a>, <font class="stringliteral">""</font>); 00062 } 00063 <font class="keywordflow">else</font> 00064 { 00065 strcpy(_frame_def-><a class="code" href="struct_i_d3___frame_def.html#m2">sLongTextID</a>, id); 00066 strcpy(_frame_def-><a class="code" href="struct_i_d3___frame_def.html#m1">sShortTextID</a>, <font class="stringliteral">""</font>); 00067 } 00068 _dyn_frame_def = <font class="keyword">true</font>; 00069 } 00070 <a name="l00071"></a><a class="code" href="class_i_d3___frame_header.html#a5">00071</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___frame_header.html#a5">ID3_FrameHeader::SetFrameID</a>(<a class="code" href="globals_8h.html#a219">ID3_FrameID</a> id) 00072 { 00073 <font class="keywordflow">if</font> (id == <a class="code" href="globals_8h.html#a219a95">ID3FID_NOFRAME</a> || id == this-><a class="code" href="class_i_d3___frame_header.html#a6">GetFrameID</a>()) 00074 { 00075 <font class="keywordflow">return</font> <font class="keyword">false</font>; 00076 } 00077 _frame_def = <a class="code" href="field__impl_8h.html#a19">ID3_FindFrameDef</a>(id); 00078 <a class="code" href="class_i_d3___header.html#n2">_flags</a>.<a class="code" href="class_i_d3___flags.html#a4">set</a>(<a class="code" href="class_i_d3___frame_header.html#s6s0">TAGALTER</a>, _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m3">bTagDiscard</a>); 00079 <a class="code" href="class_i_d3___header.html#n2">_flags</a>.<a class="code" href="class_i_d3___flags.html#a4">set</a>(<a class="code" href="class_i_d3___frame_header.html#s6s1">FILEALTER</a>, _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m4">bFileDiscard</a>); 00080 00081 <a class="code" href="class_i_d3___header.html#n4">_changed</a> = <font class="keyword">true</font>; 00082 <font class="keywordflow">return</font> <font class="keyword">true</font>; 00083 } 00084 <a name="l00085"></a><a class="code" href="class_i_d3___frame_header.html#a2">00085</a> size_t <a class="code" href="class_i_d3___frame_header.html#a2">ID3_FrameHeader::Size</a>()<font class="keyword"> const</font> 00086 <font class="keyword"></font>{ 00087 <font class="keywordflow">if</font> (!<a class="code" href="class_i_d3___header.html#n3">_info</a>) 00088 { 00089 <font class="keywordflow">return</font> 0; 00090 } 00091 <font class="keywordflow">return</font> 00092 <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_id + 00093 <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_size + 00094 <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_flags; 00095 } 00096 <a name="l00097"></a><a class="code" href="class_i_d3___frame_header.html#a3">00097</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___frame_header.html#a3">ID3_FrameHeader::Parse</a>(<a class="code" href="class_i_d3___reader.html">ID3_Reader</a>& reader) 00098 { 00099 ID3D_NOTICE( <font class="stringliteral">"ID3_FrameHeader::Parse(): getCur() = "</font> << reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() ); 00100 io::ExitTrigger et(reader); 00101 <font class="keywordflow">if</font> (!<a class="code" href="class_i_d3___header.html#n3">_info</a>) 00102 { 00103 <font class="keywordflow">return</font> <font class="keyword">false</font>; 00104 } 00105 <font class="keywordflow">if</font> (reader.<a class="code" href="class_i_d3___reader.html#a2">getEnd</a>() < reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() + 10) 00106 { 00107 <font class="keywordflow">return</font> <font class="keyword">false</font>; 00108 } 00109 00110 String textID = io::readText(reader, <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_id); 00111 00112 ID3D_NOTICE( <font class="stringliteral">"ID3_FrameHeader::Parse: textID = "</font> << textID ); 00113 ID3D_NOTICE( <font class="stringliteral">"ID3_FrameHeader::Parse: getCur() = "</font> << reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() ); 00114 00115 <a class="code" href="globals_8h.html#a219">ID3_FrameID</a> fid = <a class="code" href="field__impl_8h.html#a20">ID3_FindFrameID</a>(textID.c_str()); 00116 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a219a95">ID3FID_NOFRAME</a> == fid) 00117 { 00118 this-><a class="code" href="class_i_d3___frame_header.html#b1">SetUnknownFrame</a>(textID.c_str()); 00119 ID3D_NOTICE( <font class="stringliteral">"ID3_FrameHeader::Parse: unknown frame id"</font> ); 00120 } 00121 <font class="keywordflow">else</font> 00122 { 00123 this-><a class="code" href="class_i_d3___frame_header.html#a5">SetFrameID</a>(fid); 00124 } 00125 00126 <a class="code" href="sized__types_8h.html#a4">uint32</a> dataSize = io::readBENumber(reader, <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_size); 00127 ID3D_NOTICE( <font class="stringliteral">"ID3_FrameHeader::Parse: dataSize = "</font> << dataSize ); 00128 ID3D_NOTICE( <font class="stringliteral">"ID3_FrameHeader::Parse: getCur() = "</font> << reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() ); 00129 this-><a class="code" href="class_i_d3___header.html#a4">SetDataSize</a>(dataSize); 00130 00131 <a class="code" href="sized__types_8h.html#a4">uint32</a> flags = io::readBENumber(reader, <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_flags); 00132 <a class="code" href="class_i_d3___header.html#n2">_flags</a>.<a class="code" href="class_i_d3___flags.html#a5">add</a>(flags); 00133 00134 ID3D_NOTICE( <font class="stringliteral">"ID3_FrameHeader::Parse: flags = "</font> << flags ); 00135 ID3D_NOTICE( <font class="stringliteral">"ID3_FrameHeader::Parse: getCur() = "</font> << reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>() ); 00136 et.setExitPos(reader.<a class="code" href="class_i_d3___reader.html#a3">getCur</a>()); 00137 00138 <font class="keywordflow">return</font> <font class="keyword">true</font>; 00139 } 00140 <a name="l00141"></a><a class="code" href="class_i_d3___frame_header.html#a4">00141</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___frame_header.html#a4">ID3_FrameHeader::Render</a>(<a class="code" href="class_i_d3___writer.html">ID3_Writer</a>& writer)<font class="keyword"> const</font> 00142 <font class="keyword"></font>{ 00143 size_t size = 0; 00144 00145 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == _frame_def) 00146 { 00147 <font class="comment">// TODO: log this</font> 00148 ID3D_WARNING( <font class="stringliteral">"ID3_FrameHeader::Render(): _frame_def is NULL!"</font> ); 00149 <font class="keywordflow">return</font>; 00150 <font class="comment">//ID3_THROW(ID3E_InvalidFrameID);</font> 00151 } 00152 <font class="keywordtype">char</font> *textID; 00153 <font class="keywordflow">if</font> (<a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_id == strlen(_frame_def-><a class="code" href="struct_i_d3___frame_def.html#m1">sShortTextID</a>)) 00154 { 00155 textID = _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m1">sShortTextID</a>; 00156 } 00157 <font class="keywordflow">else</font> 00158 { 00159 textID = _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m2">sLongTextID</a>; 00160 } 00161 00162 ID3D_NOTICE( <font class="stringliteral">"ID3_FrameHeader::Render(): writing "</font> << textID << <font class="stringliteral">", "</font> << (<font class="keywordtype">int</font>) <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_size << <font class="stringliteral">" bytes"</font>); 00163 writer.<a class="code" href="class_i_d3___writer.html#a8">writeChars</a>((<a class="code" href="globals_8h.html#a33">uchar</a> *) textID, <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_id); 00164 00165 io::writeBENumber(writer, <a class="code" href="class_i_d3___header.html#n1">_data_size</a>, <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_size); 00166 io::writeBENumber(writer, <a class="code" href="class_i_d3___header.html#n2">_flags</a>.<a class="code" href="class_i_d3___flags.html#a2">get</a>(), <a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_flags); 00167 } 00168 <a name="l00169"></a><a class="code" href="class_i_d3___frame_header.html#a7">00169</a> <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="class_i_d3___frame_header.html#a7">ID3_FrameHeader::GetTextID</a>()<font class="keyword"> const</font> 00170 <font class="keyword"></font>{ 00171 <font class="keywordtype">char</font> *textID = <font class="stringliteral">""</font>; 00172 <font class="keywordflow">if</font> (<a class="code" href="class_i_d3___header.html#n3">_info</a> && _frame_def) 00173 { 00174 <font class="keywordflow">if</font> (<a class="code" href="class_i_d3___header.html#n3">_info</a>->frame_bytes_id == strlen(_frame_def-><a class="code" href="struct_i_d3___frame_def.html#m1">sShortTextID</a>)) 00175 { 00176 textID = _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m1">sShortTextID</a>; 00177 } 00178 <font class="keywordflow">else</font> 00179 { 00180 textID = _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m2">sLongTextID</a>; 00181 } 00182 } 00183 <font class="keywordflow">return</font> textID; 00184 } 00185 <a name="l00186"></a><a class="code" href="class_i_d3___frame_header.html#a10">00186</a> <a class="code" href="class_i_d3___frame_header.html">ID3_FrameHeader</a>& <a class="code" href="class_i_d3___frame_header.html#a10">ID3_FrameHeader::operator=</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___frame_header.html">ID3_FrameHeader</a>& hdr) 00187 { 00188 <font class="keywordflow">if</font> (<font class="keyword">this</font> != &hdr) 00189 { 00190 this-><a class="code" href="class_i_d3___frame_header.html#a9">Clear</a>(); 00191 this-><a class="code" href="class_i_d3___header.html#a10">ID3_Header::operator=</a>(hdr); 00192 <font class="keywordflow">if</font> (!hdr.<a class="code" href="class_i_d3___frame_header.html#o1">_dyn_frame_def</a>) 00193 { 00194 _frame_def = hdr.<a class="code" href="class_i_d3___frame_header.html#o0">_frame_def</a>; 00195 } 00196 <font class="keywordflow">else</font> 00197 { 00198 _frame_def = <font class="keyword">new</font> <a class="code" href="struct_i_d3___frame_def.html">ID3_FrameDef</a>; 00199 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == _frame_def) 00200 { 00201 <font class="comment">// TODO: throw something here...</font> 00202 } 00203 _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m0">eID</a> = hdr.<a class="code" href="class_i_d3___frame_header.html#o0">_frame_def</a>-><a class="code" href="struct_i_d3___frame_def.html#m0">eID</a>; 00204 _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m3">bTagDiscard</a> = hdr.<a class="code" href="class_i_d3___frame_header.html#o0">_frame_def</a>-><a class="code" href="struct_i_d3___frame_def.html#m3">bTagDiscard</a>; 00205 _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m4">bFileDiscard</a> = hdr.<a class="code" href="class_i_d3___frame_header.html#o0">_frame_def</a>-><a class="code" href="struct_i_d3___frame_def.html#m4">bFileDiscard</a>; 00206 _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m5">aeFieldDefs</a> = hdr.<a class="code" href="class_i_d3___frame_header.html#o0">_frame_def</a>-><a class="code" href="struct_i_d3___frame_def.html#m5">aeFieldDefs</a>; 00207 strcpy(_frame_def-><a class="code" href="struct_i_d3___frame_def.html#m1">sShortTextID</a>, hdr.<a class="code" href="class_i_d3___frame_header.html#o0">_frame_def</a>-><a class="code" href="struct_i_d3___frame_def.html#m1">sShortTextID</a>); 00208 strcpy(_frame_def-><a class="code" href="struct_i_d3___frame_def.html#m2">sLongTextID</a>, hdr.<a class="code" href="class_i_d3___frame_header.html#o0">_frame_def</a>-><a class="code" href="struct_i_d3___frame_def.html#m2">sLongTextID</a>); 00209 _dyn_frame_def = <font class="keyword">true</font>; 00210 } 00211 } 00212 <font class="keywordflow">return</font> *<font class="keyword">this</font>; 00213 } 00214 <a name="l00215"></a><a class="code" href="class_i_d3___frame_header.html#a6">00215</a> <a class="code" href="globals_8h.html#a219">ID3_FrameID</a> <a class="code" href="class_i_d3___frame_header.html#a6">ID3_FrameHeader::GetFrameID</a>()<font class="keyword"> const</font> 00216 <font class="keyword"></font>{ 00217 <a class="code" href="globals_8h.html#a219">ID3_FrameID</a> eID = <a class="code" href="globals_8h.html#a219a95">ID3FID_NOFRAME</a>; 00218 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> != _frame_def) 00219 { 00220 eID = _frame_def-><a class="code" href="struct_i_d3___frame_def.html#m0">eID</a>; 00221 } 00222 00223 <font class="keywordflow">return</font> eID; 00224 } 00225 <a name="l00226"></a><a class="code" href="class_i_d3___frame_header.html#a8">00226</a> <font class="keyword">const</font> <a class="code" href="struct_i_d3___frame_def.html">ID3_FrameDef</a> *<a class="code" href="class_i_d3___frame_header.html#a8">ID3_FrameHeader::GetFrameDef</a>()<font class="keyword"> const</font> 00227 <font class="keyword"></font>{ 00228 <font class="keywordflow">return</font> _frame_def; 00229 } 00230 <a name="l00231"></a><a class="code" href="class_i_d3___frame_header.html#a9">00231</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___frame_header.html#a9">ID3_FrameHeader::Clear</a>() 00232 { 00233 <font class="keywordtype">bool</font> changed = this-><a class="code" href="class_i_d3___header.html#a6">ID3_Header::Clear</a>(); 00234 <font class="keywordflow">if</font> (_dyn_frame_def) 00235 { 00236 <font class="keyword">delete</font> _frame_def; 00237 _dyn_frame_def = <font class="keyword">false</font>; 00238 changed = <font class="keyword">true</font>; 00239 } 00240 <font class="keywordflow">if</font> (_frame_def) 00241 { 00242 _frame_def = <a class="code" href="globals_8h.html#a24">NULL</a>; 00243 changed = <font class="keyword">true</font>; 00244 } 00245 <font class="keywordflow">return</font> changed; 00246 } </pre></div><hr><address><small>Generated on Thu Jan 3 07:35:55 2002 for id3lib by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.gif" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.12 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>, © 1997-2001</small></address> </body> </html>