tfile.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     copyright            : (C) 2002 - 2008 by Scott Wheeler
00003     email                : wheeler@kde.org
00004  ***************************************************************************/
00005 
00006 /***************************************************************************
00007  *   This library is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU Lesser General Public License version   *
00009  *   2.1 as published by the Free Software Foundation.                     *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful, but   *
00012  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the Free Software   *
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00019  *   USA                                                                   *
00020  *                                                                         *
00021  *   Alternatively, this file is available under the Mozilla Public        *
00022  *   License Version 1.1.  You may obtain a copy of the License at         *
00023  *   http://www.mozilla.org/MPL/                                           *
00024  ***************************************************************************/
00025 
00026 #ifndef TAGLIB_FILE_H
00027 #define TAGLIB_FILE_H
00028 
00029 #include "taglib_export.h"
00030 #include "taglib.h"
00031 #include "tbytevector.h"
00032 
00033 namespace TagLib {
00034 
00035   class String;
00036   class Tag;
00037   class AudioProperties;
00038 
00039 #ifdef _WIN32
00040   class TAGLIB_EXPORT FileName
00041   {
00042   public:
00043     FileName(const wchar_t *name) : m_wname(name) {}
00044     FileName(const char *name) : m_name(name) {}
00045     operator const wchar_t *() const { return m_wname.c_str(); }
00046     operator const char *() const { return m_name.c_str(); }
00047   private:
00048     std::string m_name;
00049     std::wstring m_wname;
00050   };
00051 #else
00052   typedef const char *FileName;
00053 #endif
00054 
00056 
00063   class TAGLIB_EXPORT File
00064   {
00065   public:
00069     enum Position {
00071       Beginning,
00073       Current,
00075       End
00076     };
00077 
00081     virtual ~File();
00082 
00086     FileName name() const;
00087 
00092     virtual Tag *tag() const = 0;
00093 
00099     virtual AudioProperties *audioProperties() const = 0;
00100 
00111     virtual bool save() = 0;
00112 
00116     ByteVector readBlock(ulong length);
00117 
00127     void writeBlock(const ByteVector &data);
00128 
00141     long find(const ByteVector &pattern,
00142               long fromOffset = 0,
00143               const ByteVector &before = ByteVector::null);
00144 
00157     long rfind(const ByteVector &pattern,
00158                long fromOffset = 0,
00159                const ByteVector &before = ByteVector::null);
00160 
00168     void insert(const ByteVector &data, ulong start = 0, ulong replace = 0);
00169 
00177     void removeBlock(ulong start = 0, ulong length = 0);
00178 
00182     bool readOnly() const;
00183 
00188     bool isOpen() const;
00189 
00193     bool isValid() const;
00194 
00201     void seek(long offset, Position p = Beginning);
00202 
00206     void clear();
00207 
00211     long tell() const;
00212 
00216     long length();
00217 
00224     static bool isReadable(const char *file);
00225 
00231     static bool isWritable(const char *name);
00232 
00233   protected:
00241     File(FileName file);
00242 
00248     void setValid(bool valid);
00249 
00253     void truncate(long length);
00254 
00258     static uint bufferSize();
00259 
00260   private:
00261     File(const File &);
00262     File &operator=(const File &);
00263 
00264     class FilePrivate;
00265     FilePrivate *d;
00266   };
00267 
00268 }
00269 
00270 #endif