Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 2c9d30f3cf217a6cae41860ebc0d6704 > files > 191

libid3lib3.8_0-devel-3.8.0-0.pre2.1.1mdk.i586.rpm

<!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/tag_impl.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> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
<hr><h1>src/tag_impl.cpp</h1><a href="tag__impl_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// $Id: tag_impl.cpp,v 1.8 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 &lt;config.h&gt;</font>
00029 <font class="preprocessor">#endif</font>
00030 <font class="preprocessor"></font>
00031 
00032 
00033 <font class="preprocessor">#if defined HAVE_SYS_PARAM_H</font>
00034 <font class="preprocessor"></font><font class="preprocessor">#include &lt;sys/param.h&gt;</font>
00035 <font class="preprocessor">#endif</font>
00036 <font class="preprocessor"></font>
00037 <font class="preprocessor">#include &lt;string.h&gt;</font>
00038 
00039 <font class="preprocessor">#include "<a class="code" href="tag__impl_8h.html">tag_impl.h</a>"</font>
00040 <font class="preprocessor">#include "utils.h"</font>
00041 <font class="preprocessor">#include "io_helpers.h"</font>
00042 <font class="preprocessor">#include "io_strings.h"</font>
00043 
00044 <font class="keyword">using</font> <font class="keyword">namespace </font>dami;
00045 
<a name="l00046"></a><a class="code" href="class_i_d3___tag_impl.html#d0">00046</a> size_t <a class="code" href="class_i_d3___tag_impl.html#d0">ID3_TagImpl::IsV2Tag</a>(<a class="code" href="class_i_d3___reader.html">ID3_Reader</a>&amp; reader)
00047 {
00048   io::ExitTrigger et(reader);
00049   size_t tagSize = 0;
00050   String id = io::readText(reader, <a class="code" href="class_i_d3___tag_header.html#s10s3">ID3_TagHeader::ID_SIZE</a>);
00051   String ver = io::readText(reader, 2);
00052   <font class="keywordtype">char</font> flags = reader.<a class="code" href="class_i_d3___reader.html#a5">readChar</a>();
00053   String size = io::readText(reader, 4);
00054   
00055   <font class="keywordflow">if</font> (id == <a class="code" href="class_i_d3___tag_header.html#p0">ID3_TagHeader::ID</a> &amp;&amp;
00056       (uchar) ver [0] &lt; 0xFF   &amp;&amp;      (uchar) ver [1] &lt; 0xFF   &amp;&amp;
00057       (uchar) size[0] &lt; 0x80   &amp;&amp;      (uchar) size[1] &lt; 0x80   &amp;&amp;
00058       (uchar) size[2] &lt; 0x80   &amp;&amp;      (uchar) size[3] &lt; 0x80)
00059   {
00060     io::StringReader sr(size);
00061     tagSize = io::readUInt28(sr) + <a class="code" href="class_i_d3___tag_header.html#s10s8">ID3_TagHeader::SIZE</a>;
00062   }
00063   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (id != <a class="code" href="class_i_d3___tag_header.html#p0">ID3_TagHeader::ID</a>)
00064   {
00065     <font class="comment">// clog &lt;&lt; "*** IsV2Tag: Not an id3v2 tag header" &lt;&lt; endl;</font>
00066   }
00067   <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((uchar)ver[0] &gt;= 0xFF)
00068   {
00069     <font class="comment">// clog &lt;&lt; "*** IsV2Tag: Major offset" &lt;&lt; endl;</font>
00070   }
00071   <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((uchar)ver[1] &gt;= 0xFF)
00072   {
00073     <font class="comment">// clog &lt;&lt; "*** ISV2Tag: Minor offset" &lt;&lt; endl;</font>
00074   }
00075   <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((uchar)size[0] &gt;= 0x80)
00076   {
00077     <font class="comment">// clog &lt;&lt; "*** ISV2Tag: 1st size offset" &lt;&lt; endl;</font>
00078   }
00079   <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((uchar)size[1] &gt;= 0x80)
00080   {
00081     <font class="comment">// clog &lt;&lt; "*** ISV2Tag: 2nd size offset" &lt;&lt; endl;</font>
00082   }
00083   <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((uchar)size[2] &gt;= 0x80)
00084   {
00085     <font class="comment">// clog &lt;&lt; "*** ISV2Tag: 3rd size offset" &lt;&lt; endl;</font>
00086   }
00087   <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((uchar)size[3] &gt;= 0x80)
00088   {
00089     <font class="comment">// clog &lt;&lt; "*** ISV2Tag: 4th size offset" &lt;&lt; endl;</font>
00090   }
00091   <font class="keywordflow">else</font>
00092   {
00093     <font class="comment">// clog &lt;&lt; "*** shouldn't get here!" &lt;&lt; endl;</font>
00094   }
00095   
00096   <font class="keywordflow">return</font> tagSize;
00097 }
00098 
<a name="l00099"></a><a class="code" href="class_i_d3___tag_impl.html#a0">00099</a> <a class="code" href="class_i_d3___tag_impl.html#a0">ID3_TagImpl::ID3_TagImpl</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *name)
00100   : _frames(),
00101     _cursor(_frames.begin()),
00102     _file_name(),
00103     _file_size(0),
00104     _prepended_bytes(0),
00105     _appended_bytes(0),
00106     _is_file_writable(false)
00107 {
00108   this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a3">Clear</a>();
00109   <font class="keywordflow">if</font> (name)
00110   {
00111     this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a18">Link</a>(name);
00112   }
00113 }
00114 
<a name="l00115"></a><a class="code" href="class_i_d3___tag_impl.html#a1">00115</a> <a class="code" href="class_i_d3___tag_impl.html#a0">ID3_TagImpl::ID3_TagImpl</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> &amp;tag)
00116   : _frames(),
00117     _cursor(_frames.begin()),
00118     _file_name(),
00119     _file_size(0),
00120     _prepended_bytes(0),
00121     _appended_bytes(0),
00122     _is_file_writable(false)
00123 {
00124   *<font class="keyword">this</font> = tag;
00125 }
00126 
<a name="l00127"></a><a class="code" href="class_i_d3___tag_impl.html#a2">00127</a> <a class="code" href="class_i_d3___tag_impl.html#a2">ID3_TagImpl::~ID3_TagImpl</a>()
00128 {
00129   this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a3">Clear</a>();
00130 }
00131 
<a name="l00132"></a><a class="code" href="class_i_d3___tag_impl.html#a3">00132</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___tag_impl.html#a3">ID3_TagImpl::Clear</a>()
00133 {
00134   <font class="keywordflow">for</font> (<a class="code" href="class_i_d3___tag_impl.html#s0">iterator</a> cur = _frames.begin(); cur != _frames.end(); ++cur)
00135   {
00136     <font class="keywordflow">if</font> (*cur)
00137     {
00138       <font class="keyword">delete</font> *cur;
00139       *cur = <a class="code" href="globals_8h.html#a24">NULL</a>;
00140     }
00141   }
00142   _frames.clear();
00143   _cursor = _frames.begin();
00144   _is_padded = <font class="keyword">true</font>;
00145   
00146   _hdr.<a class="code" href="class_i_d3___header.html#a6">Clear</a>();
00147   _hdr.<a class="code" href="class_i_d3___tag_header.html#a3">SetSpec</a>(<a class="code" href="globals_8h.html#a216a58">ID3V2_LATEST</a>);
00148   
00149   _tags_to_parse.<a class="code" href="class_i_d3___flags.html#a7">clear</a>();
00150 
00151   _changed = <font class="keyword">true</font>;
00152 }
00153 
00154 
<a name="l00155"></a><a class="code" href="class_i_d3___tag_impl.html#a14">00155</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___tag_impl.html#a14">ID3_TagImpl::AddFrame</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>&amp; frame)
00156 {
00157   this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a14">AddFrame</a>(&amp;frame);
00158 }
00159 
<a name="l00160"></a><a class="code" href="class_i_d3___tag_impl.html#a15">00160</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___tag_impl.html#a14">ID3_TagImpl::AddFrame</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame)
00161 {
00162   <font class="keywordflow">if</font> (frame)
00163   {
00164     <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frm = <font class="keyword">new</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>(*frame);
00165     this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a16">AttachFrame</a>(frm);
00166   }
00167 }
00168 
<a name="l00169"></a><a class="code" href="class_i_d3___tag_impl.html#a16">00169</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___tag_impl.html#a16">ID3_TagImpl::AttachFrame</a>(<a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame)
00170 {
00171   
00172   <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> == frame)
00173   {
00174     <font class="comment">// log this</font>
00175     <font class="keywordflow">return</font>;
00176     <font class="comment">//ID3_THROW(ID3E_NoData);</font>
00177   }
00178 
00179   _frames.push_back(frame);
00180   _cursor = _frames.begin();
00181   
00182   _changed = <font class="keyword">true</font>;
00183 }
00184 
00185 
<a name="l00186"></a><a class="code" href="class_i_d3___tag_impl.html#a17">00186</a> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* <a class="code" href="class_i_d3___tag_impl.html#a17">ID3_TagImpl::RemoveFrame</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frame)
00187 {
00188   <a class="code" href="class_i_d3___frame.html">ID3_Frame</a> *frm = <a class="code" href="globals_8h.html#a24">NULL</a>;
00189   
00190   <a class="code" href="class_i_d3___tag_impl.html#s0">iterator</a> fi = <a class="code" href="class_i_d3___tag_impl.html#a25">Find</a>(frame);
00191   <font class="keywordflow">if</font> (fi != _frames.end())
00192   {
00193     frm = *fi;
00194     _frames.erase(fi);
00195     _cursor = _frames.begin();
00196     _changed = <font class="keyword">true</font>;
00197   }
00198     
00199   <font class="keywordflow">return</font> frm;
00200 }
00201 
00202 
<a name="l00203"></a><a class="code" href="class_i_d3___tag_impl.html#a4">00203</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___tag_impl.html#a4">ID3_TagImpl::HasChanged</a>()<font class="keyword"> const</font>
00204 <font class="keyword"></font>{
00205   <font class="keywordtype">bool</font> changed = _changed;
00206   
00207   <font class="keywordflow">if</font> (! changed)
00208   {
00209     <font class="keywordflow">for</font> (<a class="code" href="class_i_d3___tag_impl.html#s1">const_iterator</a> fi = _frames.begin(); fi != _frames.end(); ++fi)
00210     {
00211       <font class="keywordflow">if</font> (*fi)
00212       {
00213         changed = (*fi)-&gt;HasChanged();
00214       }
00215         
00216       <font class="keywordflow">if</font> (changed)
00217       {
00218         <font class="keywordflow">break</font>;
00219       }
00220     }
00221   }
00222   
00223   <font class="keywordflow">return</font> changed;
00224 }
00225 
<a name="l00226"></a><a class="code" href="class_i_d3___tag_impl.html#a33">00226</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___tag_impl.html#a33">ID3_TagImpl::SetSpec</a>(<a class="code" href="globals_8h.html#a216">ID3_V2Spec</a> spec)
00227 {
00228   <font class="keywordtype">bool</font> changed = _hdr.<a class="code" href="class_i_d3___tag_header.html#a3">SetSpec</a>(spec);
00229   _changed = _changed || changed;
00230   <font class="keywordflow">return</font> changed;
00231 }
00232 
<a name="l00233"></a><a class="code" href="class_i_d3___tag_impl.html#a32">00233</a> <a class="code" href="globals_8h.html#a216">ID3_V2Spec</a> <a class="code" href="class_i_d3___tag_impl.html#a32">ID3_TagImpl::GetSpec</a>()<font class="keyword"> const</font>
00234 <font class="keyword"></font>{
00235   <font class="keywordflow">return</font> _hdr.<a class="code" href="class_i_d3___header.html#a3">GetSpec</a>();
00236 }
00237 
<a name="l00238"></a><a class="code" href="class_i_d3___tag_impl.html#a7">00238</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___tag_impl.html#a7">ID3_TagImpl::SetUnsync</a>(<font class="keywordtype">bool</font> b)
00239 {
00240   <font class="keywordtype">bool</font> changed = _hdr.<a class="code" href="class_i_d3___tag_header.html#a8">SetUnsync</a>(b);
00241   _changed = changed || _changed;
00242   <font class="keywordflow">return</font> changed;
00243 }
00244 
<a name="l00245"></a><a class="code" href="class_i_d3___tag_impl.html#a8">00245</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___tag_impl.html#a8">ID3_TagImpl::SetExtended</a>(<font class="keywordtype">bool</font> ext)
00246 {
00247   <font class="keywordtype">bool</font> changed = _hdr.<a class="code" href="class_i_d3___tag_header.html#a10">SetExtended</a>(ext);
00248   _changed = changed || _changed;
00249   <font class="keywordflow">return</font> changed;
00250 }
00251 
<a name="l00252"></a><a class="code" href="class_i_d3___tag_impl.html#a9">00252</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___tag_impl.html#a9">ID3_TagImpl::SetExperimental</a>(<font class="keywordtype">bool</font> exp)
00253 {
00254   <font class="keywordtype">bool</font> changed = _hdr.<a class="code" href="class_i_d3___tag_header.html#a12">SetExperimental</a>(exp);
00255   _changed = changed || _changed;
00256   <font class="keywordflow">return</font> changed;
00257 }
00258 
<a name="l00259"></a><a class="code" href="class_i_d3___tag_impl.html#a11">00259</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___tag_impl.html#a11">ID3_TagImpl::GetUnsync</a>()<font class="keyword"> const</font>
00260 <font class="keyword"></font>{
00261   <font class="keywordflow">return</font> _hdr.<a class="code" href="class_i_d3___tag_header.html#a9">GetUnsync</a>();
00262 }
00263 
<a name="l00264"></a><a class="code" href="class_i_d3___tag_impl.html#a12">00264</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___tag_impl.html#a12">ID3_TagImpl::GetExtended</a>()<font class="keyword"> const</font>
00265 <font class="keyword"></font>{
00266   <font class="keywordflow">return</font> _hdr.<a class="code" href="class_i_d3___tag_header.html#a11">GetExtended</a>();
00267 }
00268 
<a name="l00269"></a><a class="code" href="class_i_d3___tag_impl.html#a13">00269</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___tag_impl.html#a13">ID3_TagImpl::GetExperimental</a>()<font class="keyword"> const</font>
00270 <font class="keyword"></font>{
00271   <font class="keywordflow">return</font> _hdr.<a class="code" href="class_i_d3___tag_header.html#a13">GetExperimental</a>();
00272 }
00273 
<a name="l00274"></a><a class="code" href="class_i_d3___tag_impl.html#a10">00274</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___tag_impl.html#a10">ID3_TagImpl::SetPadding</a>(<font class="keywordtype">bool</font> pad)
00275 {
00276   <font class="keywordtype">bool</font> changed = (_is_padded != pad);
00277   _changed = changed || _changed;
00278   <font class="keywordflow">if</font> (changed)
00279   {
00280     _is_padded = pad;
00281   }
00282   
00283   <font class="keywordflow">return</font> changed;
00284 }
00285 
00286 
00287 <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a> &amp;
<a name="l00288"></a><a class="code" href="class_i_d3___tag_impl.html#a30">00288</a> <a class="code" href="class_i_d3___tag_impl.html#a30">ID3_TagImpl::operator=</a>( <font class="keyword">const</font> <a class="code" href="class_i_d3___tag.html">ID3_Tag</a> &amp;rTag )
00289 {
00290   this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a3">Clear</a>();
00291 
00292   this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a7">SetUnsync</a>(rTag.<a class="code" href="class_i_d3___tag.html#a9">GetUnsync</a>());
00293   this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a8">SetExtended</a>(rTag.<a class="code" href="class_i_d3___tag.html#a10">GetExtendedHeader</a>());
00294   this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a9">SetExperimental</a>(rTag.<a class="code" href="class_i_d3___tag.html#a11">GetExperimental</a>());
00295 
00296   <a class="code" href="class_i_d3___tag_1_1_const_iterator.html">ID3_Tag::ConstIterator</a>* iter = rTag.<a class="code" href="class_i_d3___tag.html#a33">CreateIterator</a>();
00297   <font class="keyword">const</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>* frame = <a class="code" href="globals_8h.html#a24">NULL</a>;
00298   <font class="keywordflow">while</font> (NULL != (frame = iter-&gt;<a class="code" href="class_i_d3___tag_1_1_const_iterator.html#a0">GetNext</a>()))
00299   {
00300     this-&gt;<a class="code" href="class_i_d3___tag_impl.html#a16">AttachFrame</a>(<font class="keyword">new</font> <a class="code" href="class_i_d3___frame.html">ID3_Frame</a>(*frame));
00301   }
00302   <font class="keyword">delete</font> iter;
00303   <font class="keywordflow">return</font> *<font class="keyword">this</font>;
00304 }
00305 
<a name="l00306"></a><a class="code" href="tag__impl_8cpp.html#a0">00306</a> size_t <a class="code" href="tag__impl_8h.html#a0">ID3_GetDataSize</a>(<font class="keyword">const</font> <a class="code" href="class_i_d3___tag_impl.html">ID3_TagImpl</a>&amp; tag)
00307 {
00308   <font class="keywordflow">return</font> tag.<a class="code" href="class_i_d3___tag_impl.html#a23">GetFileSize</a>() - tag.<a class="code" href="class_i_d3___tag_impl.html#a21">GetPrependedBytes</a>() - tag.<a class="code" href="class_i_d3___tag_impl.html#a22">GetAppendedBytes</a>();
00309 }
00310 
</pre></div><hr><address><small>Generated on Thu Jan 3 07:35:56 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>,
 &copy;&nbsp;1997-2001</small></address>
</body>
</html>