~njh-aelius/maxosx/musicbrainz-tags

« back to all changes in this revision

Viewing changes to Frameworks/taglib/taglib/taglib/toolkit/tfile.h

  • Committer: stephen_booth
  • Date: 2008-04-30 01:48:01 UTC
  • Revision ID: svn-v4:6b6cea13-1402-0410-9567-a7afb52bf336:trunk:1371
Fixing the taglib source tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
    copyright            : (C) 2002 - 2008 by Scott Wheeler
3
 
    email                : wheeler@kde.org
4
 
 ***************************************************************************/
5
 
 
6
 
/***************************************************************************
7
 
 *   This library is free software; you can redistribute it and/or modify  *
8
 
 *   it under the terms of the GNU Lesser General Public License version   *
9
 
 *   2.1 as published by the Free Software Foundation.                     *
10
 
 *                                                                         *
11
 
 *   This library is distributed in the hope that it will be useful, but   *
12
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
13
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
14
 
 *   Lesser General Public License for more details.                       *
15
 
 *                                                                         *
16
 
 *   You should have received a copy of the GNU Lesser General Public      *
17
 
 *   License along with this library; if not, write to the Free Software   *
18
 
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
19
 
 *   USA                                                                   *
20
 
 *                                                                         *
21
 
 *   Alternatively, this file is available under the Mozilla Public        *
22
 
 *   License Version 1.1.  You may obtain a copy of the License at         *
23
 
 *   http://www.mozilla.org/MPL/                                           *
24
 
 ***************************************************************************/
25
 
 
26
 
#ifndef TAGLIB_FILE_H
27
 
#define TAGLIB_FILE_H
28
 
 
29
 
#include "taglib_export.h"
30
 
#include "taglib.h"
31
 
#include "tbytevector.h"
32
 
 
33
 
namespace TagLib {
34
 
 
35
 
  class String;
36
 
  class Tag;
37
 
  class AudioProperties;
38
 
 
39
 
 
40
 
#ifdef _WIN32
41
 
  class TAGLIB_EXPORT FileName
42
 
  {
43
 
  public:
44
 
    FileName(const wchar_t *name) : m_wname(name) {}
45
 
    FileName(const char *name) : m_name(name) {}
46
 
    operator const wchar_t *() const { return m_wname.c_str(); }
47
 
    operator const char *() const { return m_name.c_str(); }
48
 
  private:
49
 
    std::string m_name;
50
 
    std::wstring m_wname;
51
 
  };
52
 
#else
53
 
  typedef const char *FileName;
54
 
#endif
55
 
 
56
 
  //! A file class with some useful methods for tag manipulation
57
 
 
58
 
  /*!
59
 
   * This class is a basic file class with some methods that are particularly
60
 
   * useful for tag editors.  It has methods to take advantage of
61
 
   * ByteVector and a binary search method for finding patterns in a file.
62
 
   */
63
 
 
64
 
  class TAGLIB_EXPORT File
65
 
  {
66
 
  public:
67
 
    /*!
68
 
     * Position in the file used for seeking.
69
 
     */
70
 
    enum Position {
71
 
      //! Seek from the beginning of the file.
72
 
      Beginning,
73
 
      //! Seek from the current position in the file.
74
 
      Current,
75
 
      //! Seek from the end of the file.
76
 
      End
77
 
    };
78
 
 
79
 
    /*!
80
 
     * Destroys this File instance.
81
 
     */
82
 
    virtual ~File();
83
 
 
84
 
    /*!
85
 
     * Returns the file name in the local file system encoding.
86
 
     */
87
 
    FileName name() const;
88
 
 
89
 
    /*!
90
 
     * Returns a pointer to this file's tag.  This should be reimplemented in
91
 
     * the concrete subclasses.
92
 
     */
93
 
    virtual Tag *tag() const = 0;
94
 
 
95
 
    /*!
96
 
     * Returns a pointer to this file's audio properties.  This should be
97
 
     * reimplemented in the concrete subclasses.  If no audio properties were
98
 
     * read then this will return a null pointer.
99
 
     */
100
 
    virtual AudioProperties *audioProperties() const = 0;
101
 
 
102
 
    /*!
103
 
     * Save the file and its associated tags.  This should be reimplemented in
104
 
     * the concrete subclasses.  Returns true if the save succeeds.
105
 
     *
106
 
     * \warning On UNIX multiple processes are able to write to the same file at
107
 
     * the same time.  This can result in serious file corruption.  If you are
108
 
     * developing a program that makes use of TagLib from multiple processes you
109
 
     * must insure that you are only doing writes to a particular file from one
110
 
     * of them.
111
 
     */
112
 
    virtual bool save() = 0;
113
 
 
114
 
    /*!
115
 
     * Reads a block of size \a length at the current get pointer.
116
 
     */
117
 
    ByteVector readBlock(ulong length);
118
 
 
119
 
    /*!
120
 
     * Attempts to write the block \a data at the current get pointer.  If the
121
 
     * file is currently only opened read only -- i.e. readOnly() returns true --
122
 
     * this attempts to reopen the file in read/write mode.
123
 
     *
124
 
     * \note This should be used instead of using the streaming output operator
125
 
     * for a ByteVector.  And even this function is significantly slower than
126
 
     * doing output with a char[].
127
 
     */
128
 
    void writeBlock(const ByteVector &data);
129
 
 
130
 
    /*!
131
 
     * Returns the offset in the file that \a pattern occurs at or -1 if it can
132
 
     * not be found.  If \a before is set, the search will only continue until the
133
 
     * pattern \a before is found.  This is useful for tagging purposes to search
134
 
     * for a tag before the synch frame.
135
 
     *
136
 
     * Searching starts at \a fromOffset, which defaults to the beginning of the
137
 
     * file.
138
 
     *
139
 
     * \note This has the practial limitation that \a pattern can not be longer
140
 
     * than the buffer size used by readBlock().  Currently this is 1024 bytes.
141
 
     */
142
 
    long find(const ByteVector &pattern,
143
 
              long fromOffset = 0,
144
 
              const ByteVector &before = ByteVector::null);
145
 
 
146
 
    /*!
147
 
     * Returns the offset in the file that \a pattern occurs at or -1 if it can
148
 
     * not be found.  If \a before is set, the search will only continue until the
149
 
     * pattern \a before is found.  This is useful for tagging purposes to search
150
 
     * for a tag before the synch frame.
151
 
     *
152
 
     * Searching starts at \a fromOffset and proceeds from the that point to the
153
 
     * beginning of the file and defaults to the end of the file.
154
 
     *
155
 
     * \note This has the practial limitation that \a pattern can not be longer
156
 
     * than the buffer size used by readBlock().  Currently this is 1024 bytes.
157
 
     */
158
 
    long rfind(const ByteVector &pattern,
159
 
               long fromOffset = 0,
160
 
               const ByteVector &before = ByteVector::null);
161
 
 
162
 
    /*!
163
 
     * Insert \a data at position \a start in the file overwriting \a replace
164
 
     * bytes of the original content.
165
 
     *
166
 
     * \note This method is slow since it requires rewriting all of the file
167
 
     * after the insertion point.
168
 
     */
169
 
    void insert(const ByteVector &data, ulong start = 0, ulong replace = 0);
170
 
 
171
 
    /*!
172
 
     * Removes a block of the file starting a \a start and continuing for
173
 
     * \a length bytes.
174
 
     *
175
 
     * \note This method is slow since it involves rewriting all of the file
176
 
     * after the removed portion.
177
 
     */
178
 
    void removeBlock(ulong start = 0, ulong length = 0);
179
 
 
180
 
    /*!
181
 
     * Returns true if the file is read only (or if the file can not be opened).
182
 
     */
183
 
    bool readOnly() const;
184
 
 
185
 
    /*!
186
 
     * Since the file can currently only be opened as an argument to the
187
 
     * constructor (sort-of by design), this returns if that open succeeded.
188
 
     */
189
 
    bool isOpen() const;
190
 
 
191
 
    /*!
192
 
     * Returns true if the file is open and readble and valid information for
193
 
     * the Tag and / or AudioProperties was found.
194
 
     */
195
 
    bool isValid() const;
196
 
 
197
 
    /*!
198
 
     * Move the I/O pointer to \a offset in the file from position \a p.  This
199
 
     * defaults to seeking from the beginning of the file.
200
 
     *
201
 
     * \see Position
202
 
     */
203
 
    void seek(long offset, Position p = Beginning);
204
 
 
205
 
    /*!
206
 
     * Reset the end-of-file and error flags on the file.
207
 
     */
208
 
    void clear();
209
 
 
210
 
    /*!
211
 
     * Returns the current offset withing the file.
212
 
     */
213
 
    long tell() const;
214
 
 
215
 
    /*!
216
 
     * Returns the length of the file.
217
 
     */
218
 
    long length();
219
 
 
220
 
    /*!
221
 
     * Returns true if \a file can be opened for reading.  If the file does not
222
 
     * exist, this will return false.
223
 
     *
224
 
     * \deprecated
225
 
     */
226
 
    static bool isReadable(const char *file);
227
 
 
228
 
    /*!
229
 
     * Returns true if \a file can be opened for writing.
230
 
     *
231
 
     * \deprecated
232
 
     */
233
 
    static bool isWritable(const char *name);
234
 
 
235
 
  protected:
236
 
    /*!
237
 
     * Construct a File object and opens the \a file.  \a file should be a
238
 
     * be a C-string in the local file system encoding.
239
 
     *
240
 
     * \note Constructor is protected since this class should only be
241
 
     * instantiated through subclasses.
242
 
     */
243
 
    File(FileName file);
244
 
 
245
 
    /*!
246
 
     * Marks the file as valid or invalid.
247
 
     *
248
 
     * \see isValid()
249
 
     */
250
 
    void setValid(bool valid);
251
 
 
252
 
    /*!
253
 
     * Truncates the file to a \a length.
254
 
     */
255
 
    void truncate(long length);
256
 
 
257
 
    /*!
258
 
     * Returns the buffer size that is used for internal buffering.
259
 
     */
260
 
    static uint bufferSize();
261
 
 
262
 
  private:
263
 
    File(const File &);
264
 
    File &operator=(const File &);
265
 
 
266
 
    class FilePrivate;
267
 
    FilePrivate *d;
268
 
  };
269
 
 
270
 
}
271
 
 
272
 
#endif