Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

src/c_wrapper.cpp

Go to the documentation of this file.
00001 // $Id: c_wrapper.cpp,v 1.17 2001/09/08 02:33:41 shadrack Exp $
00002 
00003 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags
00004 // Copyright 1999, 2000  Scott Thomas Haug
00005 
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Library General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or (at your
00009 // option) any later version.
00010 //
00011 // This library is distributed in the hope that it will be useful, but WITHOUT
00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 // License for more details.
00015 //
00016 // You should have received a copy of the GNU Library General Public License
00017 // along with this library; if not, write to the Free Software Foundation,
00018 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 
00020 // The id3lib authors encourage improvements and optimisations to be sent to
00021 // the id3lib coordinator.  Please see the README file for details on where to
00022 // send such submissions.  See the AUTHORS file for a list of people who have
00023 // contributed to id3lib.  See the ChangeLog file for a list of changes to
00024 // id3lib.  These files are distributed with id3lib at
00025 // http://download.sourceforge.net/id3lib/
00026 
00027 #include <string.h>
00028 #include "id3.h"
00029 #include "tag.h"
00030 #include "frame.h"
00031 #include "field.h"
00032 
00033 #if defined HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036 
00037 #ifdef __cplusplus
00038 extern "C"
00039 {
00040 #endif /* __cplusplus */
00041 
00042   // tag wrappers
00043 
00044 #define ID3_CATCH(code) try { code; } catch (...) { }
00045 
00046   ID3_C_EXPORT ID3Tag*
00047   ID3Tag_New(void)
00048   {
00049     ID3_Tag* tag = NULL;
00050     ID3_CATCH(tag = new ID3_Tag);
00051     return reinterpret_cast<ID3Tag *>(tag);
00052   }
00053 
00054 
00055   ID3_C_EXPORT void
00056   ID3Tag_Delete(ID3Tag *tag)
00057   {
00058     if (tag)
00059     {
00060       ID3_CATCH(delete reinterpret_cast<ID3_Tag*>(tag));
00061     }
00062   }
00063 
00064 
00065   ID3_C_EXPORT void
00066   ID3Tag_Clear(ID3Tag *tag)
00067   {
00068     if (tag)
00069     {
00070       ID3_CATCH(reinterpret_cast<ID3_Tag*>(tag)->Clear());
00071     }
00072   }
00073 
00074 
00075   ID3_C_EXPORT bool
00076   ID3Tag_HasChanged(const ID3Tag *tag)
00077   {
00078     bool changed = false;
00079   
00080     if (tag)
00081     {
00082       ID3_CATCH(changed = reinterpret_cast<const ID3_Tag * >(tag)->HasChanged());
00083     }
00084     
00085     return changed;
00086   }
00087 
00088 
00089   ID3_C_EXPORT void
00090   ID3Tag_SetUnsync(ID3Tag *tag, bool unsync)
00091   {
00092     if (tag)
00093     {
00094       ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->SetUnsync(unsync));
00095     }
00096   }
00097 
00098 
00099   ID3_C_EXPORT void
00100   ID3Tag_SetExtendedHeader(ID3Tag *tag, bool ext)
00101   {
00102     if (tag)
00103     {
00104       ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->SetExtendedHeader(ext));
00105     }
00106   }
00107   
00108   ID3_C_EXPORT void
00109   ID3Tag_SetPadding(ID3Tag *tag, bool pad)
00110   {
00111     if (tag)
00112     {
00113       ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->SetPadding(pad));
00114     }
00115   }
00116 
00117 
00118   ID3_C_EXPORT void
00119   ID3Tag_AddFrame(ID3Tag *tag, const ID3Frame *frame)
00120   {
00121     if (tag)
00122     {
00123       ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->AddFrame(reinterpret_cast<const ID3_Frame *>(frame)));
00124     }
00125   }
00126 
00127 
00128   ID3_C_EXPORT void
00129   ID3Tag_AttachFrame(ID3Tag *tag, ID3Frame *frame)
00130   {
00131     if (tag)
00132     {
00133       ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->AttachFrame(reinterpret_cast<ID3_Frame *>(frame)));
00134     }
00135   }
00136 
00137 
00138   ID3_C_EXPORT void
00139   ID3Tag_AddFrames(ID3Tag *tag, const ID3Frame *frames, size_t num)
00140   {
00141     if (tag)
00142     {
00143       ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->AddFrames(reinterpret_cast<const ID3_Frame *>(frames), num));
00144     }
00145   }
00146 
00147 
00148   ID3_C_EXPORT ID3Frame*
00149   ID3Tag_RemoveFrame(ID3Tag *tag, const ID3Frame *frame)
00150   {
00151     ID3_Frame* rem_frame = NULL;
00152     if (tag)
00153     {
00154       ID3_CATCH(rem_frame = reinterpret_cast<ID3_Tag *>(tag)->RemoveFrame(reinterpret_cast<const ID3_Frame *>(frame)));
00155     }
00156     return reinterpret_cast<ID3Frame*>(rem_frame);
00157   }
00158 
00159 
00160   ID3_C_EXPORT ID3_Err
00161   ID3Tag_Parse(ID3Tag *tag, const uchar header[ ID3_TAGHEADERSIZE ],
00162                const uchar *buffer)
00163   {
00164     size_t size = 0;
00165     if (tag)
00166     {
00167       ID3_CATCH(size = reinterpret_cast<ID3_Tag *>(tag)->Parse(header, buffer));
00168     }
00169     return ID3E_NoError;
00170   }
00171 
00172 
00173   ID3_C_EXPORT size_t
00174   ID3Tag_Link(ID3Tag *tag, const char *fileName)
00175   {
00176     size_t offset = 0;
00177     if (tag)
00178     {
00179       ID3_CATCH(offset = reinterpret_cast<ID3_Tag *>(tag)->Link(fileName));
00180     }
00181     return offset;
00182   }
00183 
00184   ID3_C_EXPORT size_t
00185   ID3Tag_LinkWithFlags(ID3Tag *tag, const char *fileName, flags_t flags)
00186   {
00187     size_t offset = 0;
00188     if (tag)
00189     {
00190       ID3_CATCH(offset = reinterpret_cast<ID3_Tag *>(tag)->Link(fileName,flags));
00191     }
00192     return offset;
00193   }
00194 
00195 
00196 
00197   ID3_C_EXPORT ID3_Err
00198   ID3Tag_Update(ID3Tag *tag)
00199   {
00200     flags_t flags = 0;
00201     if (tag)
00202     {
00203       ID3_CATCH(flags = reinterpret_cast<ID3_Tag *>(tag)->Update());
00204     }
00205     return ID3E_NoError;
00206   }
00207 
00208   ID3_C_EXPORT ID3_Err
00209   ID3Tag_UpdateByTagType(ID3Tag *tag, flags_t tag_type)
00210   {
00211     flags_t flags = 0;
00212     if (tag)
00213     {
00214       ID3_CATCH(flags = reinterpret_cast<ID3_Tag *>(tag)->Update(tag_type));
00215     }
00216     return ID3E_NoError;
00217   }
00218 
00219 
00220   ID3_C_EXPORT ID3_Err
00221   ID3Tag_Strip(ID3Tag *tag, flags_t ulTagFlags)
00222   {
00223     if (tag)
00224     {
00225       ID3_CATCH(reinterpret_cast<ID3_Tag *>(tag)->Strip(ulTagFlags));
00226     }
00227     return ID3E_NoError;
00228   }
00229 
00230 
00231   ID3_C_EXPORT ID3Frame*
00232   ID3Tag_FindFrameWithID(const ID3Tag *tag, ID3_FrameID id)
00233   {
00234     ID3_Frame *frame = NULL;
00235   
00236     if (tag)
00237     {
00238       ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id));
00239     }
00240 
00241     return reinterpret_cast<ID3Frame *>(frame);
00242   }
00243 
00244 
00245   ID3_C_EXPORT ID3Frame*
00246   ID3Tag_FindFrameWithINT(const ID3Tag *tag, ID3_FrameID id, 
00247                           ID3_FieldID fld, uint32 data)
00248   {
00249     ID3_Frame *frame = NULL;
00250   
00251     if (tag)
00252     {
00253       ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id, fld, data));
00254     }
00255     
00256     return reinterpret_cast<ID3Frame *>(frame);
00257   }
00258 
00259 
00260   ID3_C_EXPORT ID3Frame*
00261   ID3Tag_FindFrameWithASCII(const ID3Tag *tag, ID3_FrameID id, 
00262                             ID3_FieldID fld, const char *data)
00263   {
00264     ID3_Frame *frame = NULL;
00265   
00266     if (tag)
00267     {
00268       ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id, fld, data));
00269     }
00270     
00271     return reinterpret_cast<ID3Frame *>(frame);
00272   }
00273 
00274 
00275   ID3_C_EXPORT ID3Frame*
00276   ID3Tag_FindFrameWithUNICODE(const ID3Tag *tag, ID3_FrameID id, 
00277                               ID3_FieldID fld, const unicode_t *data)
00278   {
00279     ID3_Frame *frame = NULL;
00280   
00281     if (tag)
00282     {
00283       ID3_CATCH(frame = reinterpret_cast<const ID3_Tag *>(tag)->Find(id, fld, data));
00284     }
00285     
00286     return reinterpret_cast<ID3Frame *>(frame);
00287   }
00288 
00289 
00290   ID3_C_EXPORT size_t
00291   ID3Tag_NumFrames(const ID3Tag *tag)
00292   {
00293     size_t num = 0;
00294   
00295     if (tag)
00296     {
00297       ID3_CATCH(num = reinterpret_cast<const ID3_Tag *>(tag)->NumFrames());
00298     }
00299     
00300     return num;
00301   }
00302 
00303 
00304   ID3_C_EXPORT bool
00305   ID3Tag_HasTagType(const ID3Tag *tag, ID3_TagType tt)
00306   {
00307     bool has_tt = false;
00308   
00309     if (tag)
00310     {
00311       ID3_CATCH(has_tt = reinterpret_cast<const ID3_Tag *>(tag)->HasTagType(tt));
00312     }
00313     
00314     return has_tt;
00315   }
00316 
00317   ID3_C_EXPORT ID3TagIterator*
00318   ID3Tag_CreateIterator(ID3Tag* tag)
00319   {
00320     ID3_Tag::Iterator* iter = NULL;
00321 
00322     if (tag)
00323     {
00324       ID3_CATCH(iter = reinterpret_cast<ID3_Tag*>(tag)->CreateIterator());
00325     }
00326 
00327     return reinterpret_cast<ID3TagIterator*>(iter);
00328   }
00329 
00330   ID3_C_EXPORT ID3TagConstIterator*
00331   ID3Tag_CreateConstIterator(const ID3Tag* tag)
00332   {
00333     ID3_Tag::ConstIterator* iter = NULL;
00334 
00335     if (tag)
00336     {
00337       ID3_CATCH(iter = reinterpret_cast<const ID3_Tag*>(tag)->CreateIterator());
00338     }
00339 
00340     return reinterpret_cast<ID3TagConstIterator*>(iter);
00341   }
00342 
00343   ID3_C_EXPORT void
00344   ID3TagIterator_Delete(ID3TagIterator *iter)
00345   {
00346     if (iter)
00347     {
00348       ID3_CATCH(delete reinterpret_cast<ID3_Tag::Iterator*>(iter));
00349     }
00350   }
00351 
00352   ID3_C_EXPORT ID3Frame*
00353   ID3TagIterator_GetNext(ID3TagIterator *iter)
00354   {
00355     ID3_Frame* frame = NULL;
00356     if (iter)
00357     {
00358       ID3_CATCH(frame = reinterpret_cast<ID3_Tag::Iterator*>(iter)->GetNext());
00359     }
00360     return reinterpret_cast<ID3Frame*>(frame);
00361   }
00362 
00363   ID3_C_EXPORT void
00364   ID3TagConstIterator_Delete(ID3TagConstIterator *iter)
00365   {
00366     if (iter)
00367     {
00368       ID3_CATCH(delete reinterpret_cast<ID3_Tag::ConstIterator*>(iter));
00369     }
00370   }
00371 
00372   ID3_C_EXPORT const ID3Frame*
00373   ID3TagConstIterator_GetNext(ID3TagConstIterator *iter)
00374   {
00375     const ID3_Frame* frame = NULL;
00376     if (iter)
00377     {
00378       ID3_CATCH(frame = reinterpret_cast<ID3_Tag::ConstIterator*>(iter)->GetNext());
00379     }
00380     return reinterpret_cast<const ID3Frame*>(frame);
00381   }
00382 
00383   // frame wrappers
00384 
00385   ID3_C_EXPORT ID3Frame*
00386   ID3Frame_New(void)
00387   {
00388     ID3_Frame* frame = NULL;
00389     ID3_CATCH(frame = new ID3_Frame);
00390     return reinterpret_cast<ID3Frame *>(frame);
00391   }
00392 
00393   ID3_C_EXPORT ID3Frame*
00394   ID3Frame_NewID(ID3_FrameID id)
00395   {
00396     ID3_Frame* frame = NULL;
00397     ID3_CATCH(frame = new ID3_Frame(id));
00398     return reinterpret_cast<ID3Frame *>(frame);
00399   }
00400 
00401   ID3_C_EXPORT void
00402   ID3Frame_Delete(ID3Frame *frame)
00403   {
00404     if (frame)
00405     {
00406       ID3_CATCH(delete reinterpret_cast<ID3_Frame *>(frame));
00407     }
00408   }
00409 
00410 
00411   ID3_C_EXPORT void
00412   ID3Frame_Clear(ID3Frame *frame)
00413   {
00414     if (frame)
00415     {
00416       ID3_CATCH(reinterpret_cast<ID3_Frame *>(frame)->Clear());
00417     }
00418   }
00419 
00420 
00421   ID3_C_EXPORT void
00422   ID3Frame_SetID(ID3Frame *frame, ID3_FrameID id)
00423   {
00424     if (frame)
00425     {
00426       ID3_CATCH(reinterpret_cast<ID3_Frame *>(frame)->SetID(id));
00427     }
00428   }
00429 
00430 
00431   ID3_C_EXPORT
00432   ID3_FrameID ID3Frame_GetID(const ID3Frame *frame)
00433   {
00434     ID3_FrameID id = ID3FID_NOFRAME;
00435   
00436     if (frame)
00437     {
00438       ID3_CATCH(id = reinterpret_cast<const ID3_Frame *>(frame)->GetID());
00439     }
00440 
00441     return id;
00442   }
00443 
00444 
00445   ID3_C_EXPORT ID3Field*
00446   ID3Frame_GetField(const ID3Frame *frame, ID3_FieldID name)
00447   {
00448     ID3_Field *field = NULL;
00449   
00450     if (frame)
00451     {
00452       ID3_CATCH(field = reinterpret_cast<const ID3_Frame *>(frame)->GetField(name));
00453     }
00454     
00455     return reinterpret_cast<ID3Field *>(field);
00456   }
00457 
00458 
00459   ID3_C_EXPORT void
00460   ID3Frame_SetCompression(ID3Frame *frame, bool comp)
00461   {
00462     if (frame)
00463     {
00464       ID3_CATCH(reinterpret_cast<ID3_Frame *>(frame)->SetCompression(comp));
00465     }
00466   }
00467 
00468 
00469   ID3_C_EXPORT bool
00470   ID3Frame_GetCompression(const ID3Frame *frame)
00471   {
00472     bool compressed = false;
00473     if (frame)
00474     {
00475       ID3_CATCH(compressed = reinterpret_cast<const ID3_Frame *>(frame)->GetCompression());
00476     }
00477     return compressed;
00478   }
00479 
00480 
00481   // field wrappers
00482 
00483 
00484   ID3_C_EXPORT void
00485   ID3Field_Clear(ID3Field *field)
00486   {
00487     if (field)
00488     {
00489       ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Clear());
00490     }
00491   }
00492 
00493 
00494   ID3_C_EXPORT size_t
00495   ID3Field_Size(const ID3Field *field)
00496   {
00497     size_t size = 0;
00498   
00499     if (field)
00500     {
00501       ID3_CATCH(size = reinterpret_cast<const ID3_Field *>(field)->Size());
00502     }
00503     
00504     return size;
00505   }
00506 
00507 
00508   ID3_C_EXPORT size_t
00509   ID3Field_GetNumTextItems(const ID3Field *field)
00510   {
00511     size_t items = 0;
00512   
00513     if (field)
00514     {
00515       ID3_CATCH(items = reinterpret_cast<const ID3_Field *>(field)->GetNumTextItems());
00516     }
00517     
00518     return items;
00519   }
00520 
00521 
00522   ID3_C_EXPORT void
00523   ID3Field_SetINT(ID3Field *field, uint32 data)
00524   {
00525     if (field)
00526     {
00527       ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(data));
00528     }
00529   }
00530 
00531 
00532   ID3_C_EXPORT uint32
00533   ID3Field_GetINT(const ID3Field *field)
00534   {
00535     uint32 value = 0;
00536   
00537     if (field)
00538     {
00539       ID3_CATCH(value = reinterpret_cast<const ID3_Field *>(field)->Get());
00540     }
00541     
00542     return value;
00543   }
00544 
00545 
00546   ID3_C_EXPORT void
00547   ID3Field_SetUNICODE(ID3Field *field, const unicode_t *string)
00548   {
00549     if (field)
00550     {
00551       ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(string));
00552     }
00553   }
00554 
00555 
00556   ID3_C_EXPORT size_t
00557   ID3Field_GetUNICODE(const ID3Field *field, unicode_t *buffer, size_t maxChars)
00558   {
00559     size_t numChars = 0;
00560   
00561     if (field)
00562     {
00563       ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars));
00564     }
00565     
00566     return numChars;
00567   }
00568 
00569 
00570   ID3_C_EXPORT size_t
00571   ID3Field_GetUNICODEItem(const ID3Field *field, unicode_t *buffer, 
00572                           size_t maxChars, index_t itemNum)
00573   {
00574     size_t numChars = 0;
00575   
00576     if (field)
00577     {
00578       ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars, itemNum));
00579     }
00580     
00581     return numChars;
00582   }
00583 
00584 
00585   ID3_C_EXPORT void
00586   ID3Field_AddUNICODE(ID3Field *field, const unicode_t *string)
00587   {
00588     if (field)
00589     {
00590       ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Add(string));
00591     }
00592   }
00593 
00594 
00595   ID3_C_EXPORT void
00596   ID3Field_SetASCII(ID3Field *field, const char *string)
00597   {
00598     if (field)
00599     {
00600       ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(string));
00601     }
00602   }
00603 
00604 
00605   ID3_C_EXPORT size_t
00606   ID3Field_GetASCII(const ID3Field *field, char *buffer, size_t maxChars)
00607   {
00608     size_t numChars = 0;
00609   
00610     if (field)
00611     {
00612       ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars));
00613     }
00614     
00615     return numChars;
00616   }
00617 
00618   ID3_C_EXPORT size_t
00619   ID3Field_GetASCIIItem(const ID3Field *field, char *buffer, 
00620                         size_t maxChars, index_t itemNum)
00621   {
00622     size_t numChars = 0;
00623   
00624     if (field)
00625     {
00626       ID3_CATCH(numChars = reinterpret_cast<const ID3_Field *>(field)->Get(buffer, maxChars, itemNum));
00627     }
00628     
00629     return numChars;
00630   }
00631 
00632 
00633   ID3_C_EXPORT void
00634   ID3Field_AddASCII(ID3Field *field, const char *string)
00635   {
00636     if (field)
00637     {
00638       ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Add(string));
00639     }
00640   }
00641 
00642 
00643   ID3_C_EXPORT void
00644   ID3Field_SetBINARY(ID3Field *field, const uchar *data, size_t size)
00645   {
00646     if (field)
00647     {
00648       ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->Set(data, size));
00649     }
00650   }
00651 
00652 
00653   ID3_C_EXPORT void
00654   ID3Field_GetBINARY(const ID3Field *field, uchar *buffer, size_t buffLength)
00655   {
00656     if (field)
00657     {
00658       ID3_CATCH(reinterpret_cast<const ID3_Field *>(field)->Get(buffer, buffLength));
00659     }
00660   }
00661 
00662 
00663   ID3_C_EXPORT void
00664   ID3Field_FromFile(ID3Field *field, const char *fileName)
00665   {
00666     if (field)
00667     {
00668       ID3_CATCH(reinterpret_cast<ID3_Field *>(field)->FromFile(fileName));
00669     }
00670   }
00671 
00672 
00673   ID3_C_EXPORT void
00674   ID3Field_ToFile(const ID3Field *field, const char *fileName)
00675   {
00676     if (field)
00677     {
00678       ID3_CATCH(reinterpret_cast<const ID3_Field *>(field)->ToFile(fileName));
00679     }
00680   }
00681 
00682 #ifdef __cplusplus
00683 }
00684 #endif /* __cplusplus */

Generated at Sat Sep 8 15:51:08 2001 for id3lib by doxygen1.2.8 written by Dimitri van Heesch, © 1997-2001