<!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/field_binary.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/field_binary.cpp</h1><a href="field__binary_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">// $Id: field_binary.cpp,v 1.25 2001/08/26 23:33:02 dmazzoni 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 00028 <font class="preprocessor">#if defined HAVE_CONFIG_H</font> 00029 <font class="preprocessor"></font><font class="preprocessor">#include <config.h></font> 00030 <font class="preprocessor">#endif</font> 00031 <font class="preprocessor"></font> 00032 <font class="preprocessor">#include <stdio.h></font> 00033 <font class="preprocessor">#include <string.h></font> 00034 <font class="preprocessor">#include <memory.h></font> 00035 00036 <font class="preprocessor">#include "<a class="code" href="field__impl_8h.html">field_impl.h</a>"</font> 00037 <font class="preprocessor">#include "<a class="code" href="reader_8h.html">reader.h</a>"</font> 00038 <font class="preprocessor">#include "<a class="code" href="writer_8h.html">writer.h</a>"</font> 00039 <font class="preprocessor">#include "io_helpers.h"</font> 00040 <font class="preprocessor">#include "utils.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___field_impl.html#a28">00044</a> size_t <a class="code" href="class_i_d3___field_impl.html#a6">ID3_FieldImpl::Set</a>(<font class="keyword">const</font> <a class="code" href="globals_8h.html#a33">uchar</a>* data, size_t len) 00045 { 00046 size_t size = 0; 00047 <font class="keywordflow">if</font> (this-><a class="code" href="class_i_d3___field_impl.html#a39">GetType</a>() == <a class="code" href="globals_8h.html#a222a188">ID3FTY_BINARY</a>) 00048 { 00049 BString str(data, len); 00050 size = dami::min(len, this->SetBinary(str)); 00051 } 00052 <font class="keywordflow">return</font> size; 00053 } 00054 <a name="l00060"></a><a class="code" href="class_i_d3___field_impl.html#a34">00060</a> size_t <a class="code" href="class_i_d3___field_impl.html#a34">ID3_FieldImpl::SetBinary</a>(BString data) <font class="comment">//< data to assign to this field.</font> 00061 { 00062 size_t size = 0; 00063 <font class="keywordflow">if</font> (this->GetType() == <a class="code" href="globals_8h.html#a222a188">ID3FTY_BINARY</a>) 00064 { 00065 this->Clear(); 00066 size_t fixed = _fixed_size; 00067 size = data.size(); 00068 <font class="keywordflow">if</font> (fixed == 0) 00069 { 00070 _binary = data; 00071 } 00072 <font class="keywordflow">else</font> 00073 { 00074 _binary.assign(data, 0, dami::min(size, fixed)); 00075 <font class="keywordflow">if</font> (size < fixed) 00076 { 00077 _binary.append(fixed - size, <font class="charliteral">'\0'</font>); 00078 } 00079 } 00080 size = _binary.size(); 00081 _changed = <font class="keyword">true</font>; 00082 } 00083 <font class="keywordflow">return</font> size; 00084 } 00085 <a name="l00086"></a><a class="code" href="class_i_d3___field_impl.html#a35">00086</a> BString <a class="code" href="class_i_d3___field_impl.html#a35">ID3_FieldImpl::GetBinary</a>()<font class="keyword"> const</font> 00087 <font class="keyword"></font>{ 00088 BString data; 00089 <font class="keywordflow">if</font> (this-><a class="code" href="class_i_d3___field_impl.html#a39">GetType</a>() == <a class="code" href="globals_8h.html#a222a188">ID3FTY_BINARY</a>) 00090 { 00091 data = _binary; 00092 } 00093 <font class="keywordflow">return</font> data; 00094 } 00095 00096 <a name="l00097"></a><a class="code" href="class_i_d3___field_impl.html#a31">00097</a> <font class="keyword">const</font> <a class="code" href="globals_8h.html#a33">uchar</a>* <a class="code" href="class_i_d3___field_impl.html#a31">ID3_FieldImpl::GetRawBinary</a>()<font class="keyword"> const</font> 00098 <font class="keyword"></font>{ 00099 <font class="keyword">const</font> <a class="code" href="globals_8h.html#a33">uchar</a>* data = <a class="code" href="globals_8h.html#a24">NULL</a>; 00100 <font class="keywordflow">if</font> (this-><a class="code" href="class_i_d3___field_impl.html#a39">GetType</a>() == <a class="code" href="globals_8h.html#a222a188">ID3FTY_BINARY</a>) 00101 { 00102 data = _binary.data(); 00103 } 00104 <font class="keywordflow">return</font> data; 00105 } 00106 00107 <a name="l00118"></a><a class="code" href="class_i_d3___field_impl.html#a30">00118</a> size_t <a class="code" href="class_i_d3___field_impl.html#a7">ID3_FieldImpl::Get</a>(<a class="code" href="globals_8h.html#a33">uchar</a> *buffer, <font class="comment">//< Destination of retrieved string</font> 00119 size_t max_bytes <font class="comment">//< Max number of bytes to copy</font> 00120 )<font class="keyword"> const</font> 00121 <font class="keyword"></font>{ 00122 size_t bytes = 0; 00123 <font class="keywordflow">if</font> (this-><a class="code" href="class_i_d3___field_impl.html#a39">GetType</a>() == <a class="code" href="globals_8h.html#a222a188">ID3FTY_BINARY</a>) 00124 { 00125 bytes = dami::min(max_bytes, this->Size()); 00126 <font class="keywordflow">if</font> (<a class="code" href="globals_8h.html#a24">NULL</a> != buffer && bytes > 0) 00127 { 00128 ::memcpy(buffer, _binary.data(), bytes); 00129 } 00130 } 00131 <font class="keywordflow">return</font> bytes; 00132 } 00133 00134 <a name="l00141"></a><a class="code" href="class_i_d3___field_impl.html#a32">00141</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___field_impl.html#a32">ID3_FieldImpl::FromFile</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *info <font class="comment">//< Source filename</font> 00142 ) 00143 { 00144 <font class="keywordflow">if</font> (this-><a class="code" href="class_i_d3___field_impl.html#a39">GetType</a>() != <a class="code" href="globals_8h.html#a222a188">ID3FTY_BINARY</a> || <a class="code" href="globals_8h.html#a24">NULL</a> == info) 00145 { 00146 <font class="keywordflow">return</font>; 00147 } 00148 00149 FILE* temp_file = ::fopen(info, <font class="stringliteral">"rb"</font>); 00150 <font class="keywordflow">if</font> (temp_file != <a class="code" href="globals_8h.html#a24">NULL</a>) 00151 { 00152 ::fseek(temp_file, 0, SEEK_END); 00153 size_t fileSize = ::ftell(temp_file); 00154 ::fseek(temp_file, 0, SEEK_SET); 00155 00156 <a class="code" href="globals_8h.html#a33">uchar</a>* buffer = <font class="keyword">new</font> <a class="code" href="globals_8h.html#a33">uchar</a>[fileSize]; 00157 <font class="keywordflow">if</font> (buffer != <a class="code" href="globals_8h.html#a24">NULL</a>) 00158 { 00159 ::fread(buffer, 1, fileSize, temp_file); 00160 00161 this-><a class="code" href="class_i_d3___field_impl.html#a6">Set</a>(buffer, fileSize); 00162 00163 <font class="keyword">delete</font> [] buffer; 00164 } 00165 00166 ::fclose(temp_file); 00167 } 00168 } 00169 00170 <a name="l00177"></a><a class="code" href="class_i_d3___field_impl.html#a33">00177</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___field_impl.html#a33">ID3_FieldImpl::ToFile</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *info <font class="comment">//< Destination filename</font> 00178 )<font class="keyword"> const</font> 00179 <font class="keyword"></font>{ 00180 <font class="keywordflow">if</font> (this-><a class="code" href="class_i_d3___field_impl.html#a39">GetType</a>() != <a class="code" href="globals_8h.html#a222a188">ID3FTY_BINARY</a> || <a class="code" href="globals_8h.html#a24">NULL</a> == info) 00181 { 00182 <font class="keywordflow">return</font>; 00183 } 00184 00185 size_t size = this-><a class="code" href="class_i_d3___field_impl.html#a2">Size</a>(); 00186 <font class="keywordflow">if</font> (size > 0) 00187 { 00188 FILE* temp_file = ::fopen(info, <font class="stringliteral">"wb"</font>); 00189 <font class="keywordflow">if</font> (temp_file != <a class="code" href="globals_8h.html#a24">NULL</a>) 00190 { 00191 ::fwrite(_binary.data(), 1, size, temp_file); 00192 ::fclose(temp_file); 00193 } 00194 } 00195 00196 <font class="keywordflow">return</font> ; 00197 } 00198 00199 <a name="l00200"></a><a class="code" href="class_i_d3___field_impl.html#b5">00200</a> <font class="keywordtype">bool</font> <a class="code" href="class_i_d3___field_impl.html#b5">ID3_FieldImpl::ParseBinary</a>(<a class="code" href="class_i_d3___reader.html">ID3_Reader</a>& reader) 00201 { 00202 <font class="comment">// copy the remaining bytes, unless we're fixed length, in which case copy</font> 00203 <font class="comment">// the minimum of the remaining bytes vs. the fixed length</font> 00204 _binary = io::readAllBinary(reader); 00205 <font class="keywordflow">return</font> <font class="keyword">true</font>; 00206 } 00207 <a name="l00208"></a><a class="code" href="class_i_d3___field_impl.html#b2">00208</a> <font class="keywordtype">void</font> <a class="code" href="class_i_d3___field_impl.html#b2">ID3_FieldImpl::RenderBinary</a>(<a class="code" href="class_i_d3___writer.html">ID3_Writer</a>& writer)<font class="keyword"> const</font> 00209 <font class="keyword"></font>{ 00210 writer.<a class="code" href="class_i_d3___writer.html#a8">writeChars</a>(this->GetRawBinary(), this-><a class="code" href="class_i_d3___field_impl.html#a2">Size</a>()); 00211 } 00212 </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>