src/libFLAC/stream_decoder.c : Fix buffer read overflow.
[platform/upstream/flac.git] / include / FLAC++ / metadata.h
1 /* libFLAC++ - Free Lossless Audio Codec library
2  * Copyright (C) 2002-2009  Josh Coalson
3  * Copyright (C) 2011-2013  Xiph.Org Foundation
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Xiph.org Foundation nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef FLACPP__METADATA_H
34 #define FLACPP__METADATA_H
35
36 #include "export.h"
37
38 #include "FLAC/metadata.h"
39
40 // ===============================================================
41 //
42 //  Full documentation for the metadata interface can be found
43 //  in the C layer in include/FLAC/metadata.h
44 //
45 // ===============================================================
46
47 /** \file include/FLAC++/metadata.h
48  *
49  *  \brief
50  *  This module provides classes for creating and manipulating FLAC
51  *  metadata blocks in memory, and three progressively more powerful
52  *  interfaces for traversing and editing metadata in FLAC files.
53  *
54  *  See the detailed documentation for each interface in the
55  *  \link flacpp_metadata metadata \endlink module.
56  */
57
58 /** \defgroup flacpp_metadata FLAC++/metadata.h: metadata interfaces
59  *  \ingroup flacpp
60  *
61  *  \brief
62  *  This module provides classes for creating and manipulating FLAC
63  *  metadata blocks in memory, and three progressively more powerful
64  *  interfaces for traversing and editing metadata in FLAC files.
65  *
66  *  The behavior closely mimics the C layer interface; be sure to read
67  *  the detailed description of the
68  *  \link flac_metadata C metadata module \endlink.  Note that like the
69  *  C layer, currently only the Chain interface (level 2) supports Ogg
70  *  FLAC files, and it is read-only i.e. no writing back changed
71  *  metadata to file.
72  */
73
74
75 namespace FLAC {
76         namespace Metadata {
77
78                 // ============================================================
79                 //
80                 //  Metadata objects
81                 //
82                 // ============================================================
83
84                 /** \defgroup flacpp_metadata_object FLAC++/metadata.h: metadata object classes
85                  *  \ingroup flacpp_metadata
86                  *
87                  * This module contains classes representing FLAC metadata
88                  * blocks in memory.
89                  *
90                  * The behavior closely mimics the C layer interface; be
91                  * sure to read the detailed description of the
92                  * \link flac_metadata_object C metadata object module \endlink.
93                  *
94                  * Any time a metadata object is constructed or assigned, you
95                  * should check is_valid() to make sure the underlying
96                  * ::FLAC__StreamMetadata object was able to be created.
97                  *
98                  * \warning
99                  * When the get_*() methods of any metadata object method
100                  * return you a const pointer, DO NOT disobey and write into it.
101                  * Always use the set_*() methods.
102                  *
103                  * \{
104                  */
105
106                 /** Base class for all metadata block types.
107                  *  See the \link flacpp_metadata_object overview \endlink for more.
108                  */
109                 class FLACPP_API Prototype {
110                 protected:
111                         //@{
112                         /** Constructs a copy of the given object.  This form
113                          *  always performs a deep copy.
114                          */
115                         Prototype(const Prototype &);
116                         Prototype(const ::FLAC__StreamMetadata &);
117                         Prototype(const ::FLAC__StreamMetadata *);
118                         //@}
119
120                         /** Constructs an object with copy control.  When \a copy
121                          *  is \c true, behaves identically to
122                          *  FLAC::Metadata::Prototype::Prototype(const ::FLAC__StreamMetadata *object).
123                          *  When \a copy is \c false, the instance takes ownership of
124                          *  the pointer and the ::FLAC__StreamMetadata object will
125                          *  be freed by the destructor.
126                          *
127                          *  \assert
128                          *    \code object != NULL \endcode
129                          */
130                         Prototype(::FLAC__StreamMetadata *object, bool copy);
131
132                         //@{
133                         /** Assign from another object.  Always performs a deep copy. */
134                         Prototype &operator=(const Prototype &);
135                         Prototype &operator=(const ::FLAC__StreamMetadata &);
136                         Prototype &operator=(const ::FLAC__StreamMetadata *);
137                         //@}
138
139                         /** Assigns an object with copy control.  See
140                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
141                          */
142                         Prototype &assign_object(::FLAC__StreamMetadata *object, bool copy);
143
144                         /** Deletes the underlying ::FLAC__StreamMetadata object.
145                          */
146                         virtual void clear();
147
148                         ::FLAC__StreamMetadata *object_;
149                 public:
150                         /** Deletes the underlying ::FLAC__StreamMetadata object.
151                          */
152                         virtual ~Prototype();
153
154                         //@{
155                         /** Check for equality, performing a deep compare by following pointers.
156                          */
157                         inline bool operator==(const Prototype &) const;
158                         inline bool operator==(const ::FLAC__StreamMetadata &) const;
159                         inline bool operator==(const ::FLAC__StreamMetadata *) const;
160                         //@}
161
162                         //@{
163                         /** Check for inequality, performing a deep compare by following pointers. */
164                         inline bool operator!=(const Prototype &) const;
165                         inline bool operator!=(const ::FLAC__StreamMetadata &) const;
166                         inline bool operator!=(const ::FLAC__StreamMetadata *) const;
167                         //@}
168
169                         friend class SimpleIterator;
170                         friend class Iterator;
171
172                         /** Returns \c true if the object was correctly constructed
173                          *  (i.e. the underlying ::FLAC__StreamMetadata object was
174                          *  properly allocated), else \c false.
175                          */
176                         inline bool is_valid() const;
177
178                         /** Returns \c true if this block is the last block in a
179                          *  stream, else \c false.
180                          *
181                          * \assert
182                          *   \code is_valid() \endcode
183                          */
184                         bool get_is_last() const;
185
186                         /** Returns the type of the block.
187                          *
188                          * \assert
189                          *   \code is_valid() \endcode
190                          */
191                         ::FLAC__MetadataType get_type() const;
192
193                         /** Returns the stream length of the metadata block.
194                          *
195                          * \note
196                          *   The length does not include the metadata block header,
197                          *   per spec.
198                          *
199                          * \assert
200                          *   \code is_valid() \endcode
201                          */
202                         unsigned get_length() const;
203
204                         /** Sets the "is_last" flag for the block.  When using the iterators
205                          *  it is not necessary to set this flag; they will do it for you.
206                          *
207                          * \assert
208                          *   \code is_valid() \endcode
209                          */
210                         void set_is_last(bool);
211
212                         /** Returns a pointer to the underlying ::FLAC__StreamMetadata
213                          *  object.  This can be useful for plugging any holes between
214                          *  the C++ and C interfaces.
215                          *
216                          * \assert
217                          *   \code is_valid() \endcode
218                          */
219                         inline operator const ::FLAC__StreamMetadata *() const;
220                 private:
221                         /** Private and undefined so you can't use it. */
222                         Prototype();
223
224                         // These are used only by Iterator
225                         bool is_reference_;
226                         inline void set_reference(bool x) { is_reference_ = x; }
227                 };
228
229 #ifdef _MSC_VER
230 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
231 #pragma warning ( disable : 4800 )
232 #endif
233
234                 inline bool Prototype::operator==(const Prototype &object) const
235                 { return (bool)::FLAC__metadata_object_is_equal(object_, object.object_); }
236
237                 inline bool Prototype::operator==(const ::FLAC__StreamMetadata &object) const
238                 { return (bool)::FLAC__metadata_object_is_equal(object_, &object); }
239
240                 inline bool Prototype::operator==(const ::FLAC__StreamMetadata *object) const
241                 { return (bool)::FLAC__metadata_object_is_equal(object_, object); }
242
243 #ifdef _MSC_VER
244 // @@@ how to re-enable?  the following doesn't work
245 // #pragma warning ( enable : 4800 )
246 #endif
247
248                 inline bool Prototype::operator!=(const Prototype &object) const
249                 { return !operator==(object); }
250
251                 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata &object) const
252                 { return !operator==(object); }
253
254                 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata *object) const
255                 { return !operator==(object); }
256
257                 inline bool Prototype::is_valid() const
258                 { return 0 != object_; }
259
260                 inline Prototype::operator const ::FLAC__StreamMetadata *() const
261                 { return object_; }
262
263                 /** Create a deep copy of an object and return it. */
264                 FLACPP_API Prototype *clone(const Prototype *);
265
266
267                 /** STREAMINFO metadata block.
268                  *  See the \link flacpp_metadata_object overview \endlink for more,
269                  *  and the <A HREF="../format.html#metadata_block_streaminfo">format specification</A>.
270                  */
271                 class FLACPP_API StreamInfo : public Prototype {
272                 public:
273                         StreamInfo();
274
275                         //@{
276                         /** Constructs a copy of the given object.  This form
277                          *  always performs a deep copy.
278                          */
279                         inline StreamInfo(const StreamInfo &object): Prototype(object) { }
280                         inline StreamInfo(const ::FLAC__StreamMetadata &object): Prototype(object) { }
281                         inline StreamInfo(const ::FLAC__StreamMetadata *object): Prototype(object) { }
282                         //@}
283
284                         /** Constructs an object with copy control.  See
285                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
286                          */
287                         inline StreamInfo(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
288
289                         ~StreamInfo();
290
291                         //@{
292                         /** Assign from another object.  Always performs a deep copy. */
293                         inline StreamInfo &operator=(const StreamInfo &object) { Prototype::operator=(object); return *this; }
294                         inline StreamInfo &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
295                         inline StreamInfo &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
296                         //@}
297
298                         /** Assigns an object with copy control.  See
299                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
300                          */
301                         inline StreamInfo &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
302
303                         //@{
304                         /** Check for equality, performing a deep compare by following pointers. */
305                         inline bool operator==(const StreamInfo &object) const { return Prototype::operator==(object); }
306                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
307                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
308                         //@}
309
310                         //@{
311                         /** Check for inequality, performing a deep compare by following pointers. */
312                         inline bool operator!=(const StreamInfo &object) const { return Prototype::operator!=(object); }
313                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
314                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
315                         //@}
316
317                         //@{
318                         /** See <A HREF="../format.html#metadata_block_streaminfo">format specification</A>. */
319                         unsigned get_min_blocksize() const;
320                         unsigned get_max_blocksize() const;
321                         unsigned get_min_framesize() const;
322                         unsigned get_max_framesize() const;
323                         unsigned get_sample_rate() const;
324                         unsigned get_channels() const;
325                         unsigned get_bits_per_sample() const;
326                         FLAC__uint64 get_total_samples() const;
327                         const FLAC__byte *get_md5sum() const;
328
329                         void set_min_blocksize(unsigned value);
330                         void set_max_blocksize(unsigned value);
331                         void set_min_framesize(unsigned value);
332                         void set_max_framesize(unsigned value);
333                         void set_sample_rate(unsigned value);
334                         void set_channels(unsigned value);
335                         void set_bits_per_sample(unsigned value);
336                         void set_total_samples(FLAC__uint64 value);
337                         void set_md5sum(const FLAC__byte value[16]);
338                         //@}
339                 };
340
341                 /** PADDING metadata block.
342                  *  See the \link flacpp_metadata_object overview \endlink for more,
343                  *  and the <A HREF="../format.html#metadata_block_padding">format specification</A>.
344                  */
345                 class FLACPP_API Padding : public Prototype {
346                 public:
347                         Padding();
348
349                         //@{
350                         /** Constructs a copy of the given object.  This form
351                          *  always performs a deep copy.
352                          */
353                         inline Padding(const Padding &object): Prototype(object) { }
354                         inline Padding(const ::FLAC__StreamMetadata &object): Prototype(object) { }
355                         inline Padding(const ::FLAC__StreamMetadata *object): Prototype(object) { }
356                         //@}
357
358                         /** Constructs an object with copy control.  See
359                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
360                          */
361                         inline Padding(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
362
363                         /** Constructs an object with the given length.
364                          */
365                         Padding(unsigned length);
366
367                         ~Padding();
368
369                         //@{
370                         /** Assign from another object.  Always performs a deep copy. */
371                         inline Padding &operator=(const Padding &object) { Prototype::operator=(object); return *this; }
372                         inline Padding &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
373                         inline Padding &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
374                         //@}
375
376                         /** Assigns an object with copy control.  See
377                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
378                          */
379                         inline Padding &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
380
381                         //@{
382                         /** Check for equality, performing a deep compare by following pointers. */
383                         inline bool operator==(const Padding &object) const { return Prototype::operator==(object); }
384                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
385                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
386                         //@}
387
388                         //@{
389                         /** Check for inequality, performing a deep compare by following pointers. */
390                         inline bool operator!=(const Padding &object) const { return Prototype::operator!=(object); }
391                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
392                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
393                         //@}
394
395                         /** Sets the length in bytes of the padding block.
396                          */
397                         void set_length(unsigned length);
398                 };
399
400                 /** APPLICATION metadata block.
401                  *  See the \link flacpp_metadata_object overview \endlink for more,
402                  *  and the <A HREF="../format.html#metadata_block_application">format specification</A>.
403                  */
404                 class FLACPP_API Application : public Prototype {
405                 public:
406                         Application();
407                         //
408                         //@{
409                         /** Constructs a copy of the given object.  This form
410                          *  always performs a deep copy.
411                          */
412                         inline Application(const Application &object): Prototype(object) { }
413                         inline Application(const ::FLAC__StreamMetadata &object): Prototype(object) { }
414                         inline Application(const ::FLAC__StreamMetadata *object): Prototype(object) { }
415                         //@}
416
417                         /** Constructs an object with copy control.  See
418                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
419                          */
420                         inline Application(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
421
422                         ~Application();
423
424                         //@{
425                         /** Assign from another object.  Always performs a deep copy. */
426                         inline Application &operator=(const Application &object) { Prototype::operator=(object); return *this; }
427                         inline Application &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
428                         inline Application &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
429                         //@}
430
431                         /** Assigns an object with copy control.  See
432                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
433                          */
434                         inline Application &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
435
436                         //@{
437                         /** Check for equality, performing a deep compare by following pointers. */
438                         inline bool operator==(const Application &object) const { return Prototype::operator==(object); }
439                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
440                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
441                         //@}
442
443                         //@{
444                         /** Check for inequality, performing a deep compare by following pointers. */
445                         inline bool operator!=(const Application &object) const { return Prototype::operator!=(object); }
446                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
447                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
448                         //@}
449
450                         const FLAC__byte *get_id() const;
451                         const FLAC__byte *get_data() const;
452
453                         void set_id(const FLAC__byte value[4]);
454                         //! This form always copies \a data
455                         bool set_data(const FLAC__byte *data, unsigned length);
456                         bool set_data(FLAC__byte *data, unsigned length, bool copy);
457                 };
458
459                 /** SEEKTABLE metadata block.
460                  *  See the \link flacpp_metadata_object overview \endlink for more,
461                  *  and the <A HREF="../format.html#metadata_block_seektable">format specification</A>.
462                  */
463                 class FLACPP_API SeekTable : public Prototype {
464                 public:
465                         SeekTable();
466
467                         //@{
468                         /** Constructs a copy of the given object.  This form
469                          *  always performs a deep copy.
470                          */
471                         inline SeekTable(const SeekTable &object): Prototype(object) { }
472                         inline SeekTable(const ::FLAC__StreamMetadata &object): Prototype(object) { }
473                         inline SeekTable(const ::FLAC__StreamMetadata *object): Prototype(object) { }
474                         //@}
475
476                         /** Constructs an object with copy control.  See
477                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
478                          */
479                         inline SeekTable(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
480
481                         ~SeekTable();
482
483                         //@{
484                         /** Assign from another object.  Always performs a deep copy. */
485                         inline SeekTable &operator=(const SeekTable &object) { Prototype::operator=(object); return *this; }
486                         inline SeekTable &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
487                         inline SeekTable &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
488                         //@}
489
490                         /** Assigns an object with copy control.  See
491                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
492                          */
493                         inline SeekTable &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
494
495                         //@{
496                         /** Check for equality, performing a deep compare by following pointers. */
497                         inline bool operator==(const SeekTable &object) const { return Prototype::operator==(object); }
498                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
499                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
500                         //@}
501
502                         //@{
503                         /** Check for inequality, performing a deep compare by following pointers. */
504                         inline bool operator!=(const SeekTable &object) const { return Prototype::operator!=(object); }
505                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
506                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
507                         //@}
508
509                         unsigned get_num_points() const;
510                         ::FLAC__StreamMetadata_SeekPoint get_point(unsigned index) const;
511
512                         //! See FLAC__metadata_object_seektable_resize_points()
513                         bool resize_points(unsigned new_num_points);
514
515                         //! See FLAC__metadata_object_seektable_set_point()
516                         void set_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
517
518                         //! See FLAC__metadata_object_seektable_insert_point()
519                         bool insert_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
520
521                         //! See FLAC__metadata_object_seektable_delete_point()
522                         bool delete_point(unsigned index);
523
524                         //! See FLAC__metadata_object_seektable_is_legal()
525                         bool is_legal() const;
526
527                         //! See FLAC__metadata_object_seektable_template_append_placeholders()
528                         bool template_append_placeholders(unsigned num);
529
530                         //! See FLAC__metadata_object_seektable_template_append_point()
531                         bool template_append_point(FLAC__uint64 sample_number);
532
533                         //! See FLAC__metadata_object_seektable_template_append_points()
534                         bool template_append_points(FLAC__uint64 sample_numbers[], unsigned num);
535
536                         //! See FLAC__metadata_object_seektable_template_append_spaced_points()
537                         bool template_append_spaced_points(unsigned num, FLAC__uint64 total_samples);
538
539                         //! See FLAC__metadata_object_seektable_template_append_spaced_points_by_samples()
540                         bool template_append_spaced_points_by_samples(unsigned samples, FLAC__uint64 total_samples);
541
542                         //! See FLAC__metadata_object_seektable_template_sort()
543                         bool template_sort(bool compact);
544                 };
545
546                 /** VORBIS_COMMENT metadata block.
547                  *  See the \link flacpp_metadata_object overview \endlink for more,
548                  *  and the <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>.
549                  */
550                 class FLACPP_API VorbisComment : public Prototype {
551                 public:
552                         /** Convenience class for encapsulating Vorbis comment
553                          *  entries.  An entry is a vendor string or a comment
554                          *  field.  In the case of a vendor string, the field
555                          *  name is undefined; only the field value is relevant.
556                          *
557                          *  A \a field as used in the methods refers to an
558                          *  entire 'NAME=VALUE' string; for convenience the
559                          *  string is NUL-terminated.  A length field is
560                          *  required in the unlikely event that the value
561                          *  contains contain embedded NULs.
562                          *
563                          *  A \a field_name is what is on the left side of the
564                          *  first '=' in the \a field.  By definition it is ASCII
565                          *  and so is NUL-terminated and does not require a
566                          *  length to describe it.  \a field_name is undefined
567                          *  for a vendor string entry.
568                          *
569                          *  A \a field_value is what is on the right side of the
570                          *  first '=' in the \a field.  By definition, this may
571                          *  contain embedded NULs and so a \a field_value_length
572                          *  is required to describe it.  However in practice,
573                          *  embedded NULs are not known to be used, so it is
574                          *  generally safe to treat field values as NUL-
575                          *  terminated UTF-8 strings.
576                          *
577                          *  Always check is_valid() after the constructor or operator=
578                          *  to make sure memory was properly allocated and that the
579                          *  Entry conforms to the Vorbis comment specification.
580                          */
581                         class FLACPP_API Entry {
582                         public:
583                                 Entry();
584
585                                 Entry(const char *field, unsigned field_length);
586                                 Entry(const char *field); // assumes \a field is NUL-terminated
587
588                                 Entry(const char *field_name, const char *field_value, unsigned field_value_length);
589                                 Entry(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
590
591                                 Entry(const Entry &entry);
592
593                                 Entry &operator=(const Entry &entry);
594
595                                 virtual ~Entry();
596
597                                 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
598
599                                 unsigned get_field_length() const;
600                                 unsigned get_field_name_length() const;
601                                 unsigned get_field_value_length() const;
602
603                                 ::FLAC__StreamMetadata_VorbisComment_Entry get_entry() const;
604                                 const char *get_field() const;
605                                 const char *get_field_name() const;
606                                 const char *get_field_value() const;
607
608                                 bool set_field(const char *field, unsigned field_length);
609                                 bool set_field(const char *field); // assumes \a field is NUL-terminated
610                                 bool set_field_name(const char *field_name);
611                                 bool set_field_value(const char *field_value, unsigned field_value_length);
612                                 bool set_field_value(const char *field_value); // assumes \a field_value is NUL-terminated
613                         protected:
614                                 bool is_valid_;
615                                 ::FLAC__StreamMetadata_VorbisComment_Entry entry_;
616                                 char *field_name_;
617                                 unsigned field_name_length_;
618                                 char *field_value_;
619                                 unsigned field_value_length_;
620                         private:
621                                 void zero();
622                                 void clear();
623                                 void clear_entry();
624                                 void clear_field_name();
625                                 void clear_field_value();
626                                 void construct(const char *field, unsigned field_length);
627                                 void construct(const char *field); // assumes \a field is NUL-terminated
628                                 void construct(const char *field_name, const char *field_value, unsigned field_value_length);
629                                 void construct(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
630                                 void compose_field();
631                                 void parse_field();
632                         };
633
634                         VorbisComment();
635
636                         //@{
637                         /** Constructs a copy of the given object.  This form
638                          *  always performs a deep copy.
639                          */
640                         inline VorbisComment(const VorbisComment &object): Prototype(object) { }
641                         inline VorbisComment(const ::FLAC__StreamMetadata &object): Prototype(object) { }
642                         inline VorbisComment(const ::FLAC__StreamMetadata *object): Prototype(object) { }
643                         //@}
644
645                         /** Constructs an object with copy control.  See
646                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
647                          */
648                         inline VorbisComment(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
649
650                         ~VorbisComment();
651
652                         //@{
653                         /** Assign from another object.  Always performs a deep copy. */
654                         inline VorbisComment &operator=(const VorbisComment &object) { Prototype::operator=(object); return *this; }
655                         inline VorbisComment &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
656                         inline VorbisComment &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
657                         //@}
658
659                         /** Assigns an object with copy control.  See
660                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
661                          */
662                         inline VorbisComment &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
663
664                         //@{
665                         /** Check for equality, performing a deep compare by following pointers. */
666                         inline bool operator==(const VorbisComment &object) const { return Prototype::operator==(object); }
667                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
668                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
669                         //@}
670
671                         //@{
672                         /** Check for inequality, performing a deep compare by following pointers. */
673                         inline bool operator!=(const VorbisComment &object) const { return Prototype::operator!=(object); }
674                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
675                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
676                         //@}
677
678                         unsigned get_num_comments() const;
679                         const FLAC__byte *get_vendor_string() const; // NUL-terminated UTF-8 string
680                         Entry get_comment(unsigned index) const;
681
682                         //! See FLAC__metadata_object_vorbiscomment_set_vendor_string()
683                         bool set_vendor_string(const FLAC__byte *string); // NUL-terminated UTF-8 string
684
685                         //! See FLAC__metadata_object_vorbiscomment_resize_comments()
686                         bool resize_comments(unsigned new_num_comments);
687
688                         //! See FLAC__metadata_object_vorbiscomment_set_comment()
689                         bool set_comment(unsigned index, const Entry &entry);
690
691                         //! See FLAC__metadata_object_vorbiscomment_insert_comment()
692                         bool insert_comment(unsigned index, const Entry &entry);
693
694                         //! See FLAC__metadata_object_vorbiscomment_append_comment()
695                         bool append_comment(const Entry &entry);
696
697                         //! See FLAC__metadata_object_vorbiscomment_replace_comment()
698                         bool replace_comment(const Entry &entry, bool all);
699
700                         //! See FLAC__metadata_object_vorbiscomment_delete_comment()
701                         bool delete_comment(unsigned index);
702
703                         //! See FLAC__metadata_object_vorbiscomment_find_entry_from()
704                         int find_entry_from(unsigned offset, const char *field_name);
705
706                         //! See FLAC__metadata_object_vorbiscomment_remove_entry_matching()
707                         int remove_entry_matching(const char *field_name);
708
709                         //! See FLAC__metadata_object_vorbiscomment_remove_entries_matching()
710                         int remove_entries_matching(const char *field_name);
711                 };
712
713                 /** CUESHEET metadata block.
714                  *  See the \link flacpp_metadata_object overview \endlink for more,
715                  *  and the <A HREF="../format.html#metadata_block_cuesheet">format specification</A>.
716                  */
717                 class FLACPP_API CueSheet : public Prototype {
718                 public:
719                         /** Convenience class for encapsulating a cue sheet
720                          *  track.
721                          *
722                          *  Always check is_valid() after the constructor or operator=
723                          *  to make sure memory was properly allocated.
724                          */
725                         class FLACPP_API Track {
726                         protected:
727                                 ::FLAC__StreamMetadata_CueSheet_Track *object_;
728                         public:
729                                 Track();
730                                 Track(const ::FLAC__StreamMetadata_CueSheet_Track *track);
731                                 Track(const Track &track);
732                                 Track &operator=(const Track &track);
733
734                                 virtual ~Track();
735
736                                 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
737
738
739                                 inline FLAC__uint64 get_offset() const { return object_->offset; }
740                                 inline FLAC__byte get_number() const { return object_->number; }
741                                 inline const char *get_isrc() const { return object_->isrc; }
742                                 inline unsigned get_type() const { return object_->type; }
743                                 inline bool get_pre_emphasis() const { return object_->pre_emphasis; }
744
745                                 inline FLAC__byte get_num_indices() const { return object_->num_indices; }
746                                 ::FLAC__StreamMetadata_CueSheet_Index get_index(unsigned i) const;
747
748                                 inline const ::FLAC__StreamMetadata_CueSheet_Track *get_track() const { return object_; }
749
750                                 inline void set_offset(FLAC__uint64 value) { object_->offset = value; }
751                                 inline void set_number(FLAC__byte value) { object_->number = value; }
752                                 void set_isrc(const char value[12]);
753                                 void set_type(unsigned value);
754                                 inline void set_pre_emphasis(bool value) { object_->pre_emphasis = value? 1 : 0; }
755
756                                 void set_index(unsigned i, const ::FLAC__StreamMetadata_CueSheet_Index &index);
757                                 //@@@ It's awkward but to insert/delete index points
758                                 //@@@ you must use the routines in the CueSheet class.
759                         };
760
761                         CueSheet();
762
763                         //@{
764                         /** Constructs a copy of the given object.  This form
765                          *  always performs a deep copy.
766                          */
767                         inline CueSheet(const CueSheet &object): Prototype(object) { }
768                         inline CueSheet(const ::FLAC__StreamMetadata &object): Prototype(object) { }
769                         inline CueSheet(const ::FLAC__StreamMetadata *object): Prototype(object) { }
770                         //@}
771
772                         /** Constructs an object with copy control.  See
773                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
774                          */
775                         inline CueSheet(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
776
777                         ~CueSheet();
778
779                         //@{
780                         /** Assign from another object.  Always performs a deep copy. */
781                         inline CueSheet &operator=(const CueSheet &object) { Prototype::operator=(object); return *this; }
782                         inline CueSheet &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
783                         inline CueSheet &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
784                         //@}
785
786                         /** Assigns an object with copy control.  See
787                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
788                          */
789                         inline CueSheet &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
790
791                         //@{
792                         /** Check for equality, performing a deep compare by following pointers. */
793                         inline bool operator==(const CueSheet &object) const { return Prototype::operator==(object); }
794                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
795                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
796                         //@}
797
798                         //@{
799                         /** Check for inequality, performing a deep compare by following pointers. */
800                         inline bool operator!=(const CueSheet &object) const { return Prototype::operator!=(object); }
801                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
802                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
803                         //@}
804
805                         const char *get_media_catalog_number() const;
806                         FLAC__uint64 get_lead_in() const;
807                         bool get_is_cd() const;
808
809                         unsigned get_num_tracks() const;
810                         Track get_track(unsigned i) const;
811
812                         void set_media_catalog_number(const char value[128]);
813                         void set_lead_in(FLAC__uint64 value);
814                         void set_is_cd(bool value);
815
816                         void set_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
817
818                         //! See FLAC__metadata_object_cuesheet_track_resize_indices()
819                         bool resize_indices(unsigned track_num, unsigned new_num_indices);
820
821                         //! See FLAC__metadata_object_cuesheet_track_insert_index()
822                         bool insert_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
823
824                         //! See FLAC__metadata_object_cuesheet_track_insert_blank_index()
825                         bool insert_blank_index(unsigned track_num, unsigned index_num);
826
827                         //! See FLAC__metadata_object_cuesheet_track_delete_index()
828                         bool delete_index(unsigned track_num, unsigned index_num);
829
830                         //! See FLAC__metadata_object_cuesheet_resize_tracks()
831                         bool resize_tracks(unsigned new_num_tracks);
832
833                         //! See FLAC__metadata_object_cuesheet_set_track()
834                         bool set_track(unsigned i, const Track &track);
835
836                         //! See FLAC__metadata_object_cuesheet_insert_track()
837                         bool insert_track(unsigned i, const Track &track);
838
839                         //! See FLAC__metadata_object_cuesheet_insert_blank_track()
840                         bool insert_blank_track(unsigned i);
841
842                         //! See FLAC__metadata_object_cuesheet_delete_track()
843                         bool delete_track(unsigned i);
844
845                         //! See FLAC__metadata_object_cuesheet_is_legal()
846                         bool is_legal(bool check_cd_da_subset = false, const char **violation = 0) const;
847
848                         //! See FLAC__metadata_object_cuesheet_calculate_cddb_id()
849                         FLAC__uint32 calculate_cddb_id() const;
850                 };
851
852                 /** PICTURE metadata block.
853                  *  See the \link flacpp_metadata_object overview \endlink for more,
854                  *  and the <A HREF="../format.html#metadata_block_picture">format specification</A>.
855                  */
856                 class FLACPP_API Picture : public Prototype {
857                 public:
858                         Picture();
859
860                         //@{
861                         /** Constructs a copy of the given object.  This form
862                          *  always performs a deep copy.
863                          */
864                         inline Picture(const Picture &object): Prototype(object) { }
865                         inline Picture(const ::FLAC__StreamMetadata &object): Prototype(object) { }
866                         inline Picture(const ::FLAC__StreamMetadata *object): Prototype(object) { }
867                         //@}
868
869                         /** Constructs an object with copy control.  See
870                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
871                          */
872                         inline Picture(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
873
874                         ~Picture();
875
876                         //@{
877                         /** Assign from another object.  Always performs a deep copy. */
878                         inline Picture &operator=(const Picture &object) { Prototype::operator=(object); return *this; }
879                         inline Picture &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
880                         inline Picture &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
881                         //@}
882
883                         /** Assigns an object with copy control.  See
884                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
885                          */
886                         inline Picture &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
887
888                         //@{
889                         /** Check for equality, performing a deep compare by following pointers. */
890                         inline bool operator==(const Picture &object) const { return Prototype::operator==(object); }
891                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
892                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
893                         //@}
894
895                         //@{
896                         /** Check for inequality, performing a deep compare by following pointers. */
897                         inline bool operator!=(const Picture &object) const { return Prototype::operator!=(object); }
898                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
899                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
900                         //@}
901
902                         ::FLAC__StreamMetadata_Picture_Type get_type() const;
903                         const char *get_mime_type() const; // NUL-terminated printable ASCII string
904                         const FLAC__byte *get_description() const; // NUL-terminated UTF-8 string
905                         FLAC__uint32 get_width() const;
906                         FLAC__uint32 get_height() const;
907                         FLAC__uint32 get_depth() const;
908                         FLAC__uint32 get_colors() const; ///< a return value of \c 0 means true-color, i.e. 2^depth colors
909                         FLAC__uint32 get_data_length() const;
910                         const FLAC__byte *get_data() const;
911
912                         void set_type(::FLAC__StreamMetadata_Picture_Type type);
913
914                         //! See FLAC__metadata_object_picture_set_mime_type()
915                         bool set_mime_type(const char *string); // NUL-terminated printable ASCII string
916
917                         //! See FLAC__metadata_object_picture_set_description()
918                         bool set_description(const FLAC__byte *string); // NUL-terminated UTF-8 string
919
920                         void set_width(FLAC__uint32 value) const;
921                         void set_height(FLAC__uint32 value) const;
922                         void set_depth(FLAC__uint32 value) const;
923                         void set_colors(FLAC__uint32 value) const; ///< a value of \c 0 means true-color, i.e. 2^depth colors
924
925                         //! See FLAC__metadata_object_picture_set_data()
926                         bool set_data(const FLAC__byte *data, FLAC__uint32 data_length);
927
928                         //! See FLAC__metadata_object_picture_is_legal()
929                         bool is_legal(const char **violation);
930                 };
931
932                 /** Opaque metadata block for storing unknown types.
933                  *  This should not be used unless you know what you are doing;
934                  *  it is currently used only internally to support forward
935                  *  compatibility of metadata blocks.
936                  *  See the \link flacpp_metadata_object overview \endlink for more,
937                  */
938                 class FLACPP_API Unknown : public Prototype {
939                 public:
940                         Unknown();
941                         //
942                         //@{
943                         /** Constructs a copy of the given object.  This form
944                          *  always performs a deep copy.
945                          */
946                         inline Unknown(const Unknown &object): Prototype(object) { }
947                         inline Unknown(const ::FLAC__StreamMetadata &object): Prototype(object) { }
948                         inline Unknown(const ::FLAC__StreamMetadata *object): Prototype(object) { }
949                         //@}
950
951                         /** Constructs an object with copy control.  See
952                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
953                          */
954                         inline Unknown(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
955
956                         ~Unknown();
957
958                         //@{
959                         /** Assign from another object.  Always performs a deep copy. */
960                         inline Unknown &operator=(const Unknown &object) { Prototype::operator=(object); return *this; }
961                         inline Unknown &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
962                         inline Unknown &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
963                         //@}
964
965                         /** Assigns an object with copy control.  See
966                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
967                          */
968                         inline Unknown &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
969
970                         //@{
971                         /** Check for equality, performing a deep compare by following pointers. */
972                         inline bool operator==(const Unknown &object) const { return Prototype::operator==(object); }
973                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
974                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
975                         //@}
976
977                         //@{
978                         /** Check for inequality, performing a deep compare by following pointers. */
979                         inline bool operator!=(const Unknown &object) const { return Prototype::operator!=(object); }
980                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
981                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
982                         //@}
983
984                         const FLAC__byte *get_data() const;
985
986                         //! This form always copies \a data
987                         bool set_data(const FLAC__byte *data, unsigned length);
988                         bool set_data(FLAC__byte *data, unsigned length, bool copy);
989                 };
990
991                 /* \} */
992
993
994                 /** \defgroup flacpp_metadata_level0 FLAC++/metadata.h: metadata level 0 interface
995                  *  \ingroup flacpp_metadata
996                  *
997                  *  \brief
998                  *  Level 0 metadata iterators.
999                  *
1000                  *  See the \link flac_metadata_level0 C layer equivalent \endlink
1001                  *  for more.
1002                  *
1003                  * \{
1004                  */
1005
1006                 FLACPP_API bool get_streaminfo(const char *filename, StreamInfo &streaminfo); ///< See FLAC__metadata_get_streaminfo().
1007
1008                 FLACPP_API bool get_tags(const char *filename, VorbisComment *&tags); ///< See FLAC__metadata_get_tags().
1009                 FLACPP_API bool get_tags(const char *filename, VorbisComment &tags); ///< See FLAC__metadata_get_tags().
1010
1011                 FLACPP_API bool get_cuesheet(const char *filename, CueSheet *&cuesheet); ///< See FLAC__metadata_get_cuesheet().
1012                 FLACPP_API bool get_cuesheet(const char *filename, CueSheet &cuesheet); ///< See FLAC__metadata_get_cuesheet().
1013
1014                 FLACPP_API bool get_picture(const char *filename, Picture *&picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors); ///< See FLAC__metadata_get_picture().
1015                 FLACPP_API bool get_picture(const char *filename, Picture &picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors); ///< See FLAC__metadata_get_picture().
1016
1017                 /* \} */
1018
1019
1020                 /** \defgroup flacpp_metadata_level1 FLAC++/metadata.h: metadata level 1 interface
1021                  *  \ingroup flacpp_metadata
1022                  *
1023                  *  \brief
1024                  *  Level 1 metadata iterator.
1025                  *
1026                  *  The flow through the iterator in the C++ layer is similar
1027                  *  to the C layer:
1028                  *    - Create a SimpleIterator instance
1029                  *    - Check SimpleIterator::is_valid()
1030                  *    - Call SimpleIterator::init() and check the return
1031                  *    - Traverse and/or edit.  Edits are written to file
1032                  *      immediately.
1033                  *    - Destroy the SimpleIterator instance
1034                  *
1035                  *  The ownership of pointers in the C++ layer follows that in
1036                  *  the C layer, i.e.
1037                  *    - The objects returned by get_block() are yours to
1038                  *      modify, but changes are not reflected in the FLAC file
1039                  *      until you call set_block().  The objects are also
1040                  *      yours to delete; they are not automatically deleted
1041                  *      when passed to set_block() or insert_block_after().
1042                  *
1043                  *  See the \link flac_metadata_level1 C layer equivalent \endlink
1044                  *  for more.
1045                  *
1046                  * \{
1047                  */
1048
1049                 /** This class is a wrapper around the FLAC__metadata_simple_iterator
1050                  *  structures and methods; see the
1051                  * \link flacpp_metadata_level1 usage guide \endlink and
1052                  * ::FLAC__Metadata_SimpleIterator.
1053                  */
1054                 class FLACPP_API SimpleIterator {
1055                 public:
1056                         /** This class is a wrapper around FLAC__Metadata_SimpleIteratorStatus.
1057                          */
1058                         class FLACPP_API Status {
1059                         public:
1060                                 inline Status(::FLAC__Metadata_SimpleIteratorStatus status): status_(status) { }
1061                                 inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_; }
1062                                 inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString[status_]; }
1063                         protected:
1064                                 ::FLAC__Metadata_SimpleIteratorStatus status_;
1065                         };
1066
1067                         SimpleIterator();
1068                         virtual ~SimpleIterator();
1069
1070                         bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1071
1072                         bool init(const char *filename, bool read_only, bool preserve_file_stats); ///< See FLAC__metadata_simple_iterator_init().
1073
1074                         Status status();                                                    ///< See FLAC__metadata_simple_iterator_status().
1075                         bool is_writable() const;                                           ///< See FLAC__metadata_simple_iterator_is_writable().
1076
1077                         bool next();                                                        ///< See FLAC__metadata_simple_iterator_next().
1078                         bool prev();                                                        ///< See FLAC__metadata_simple_iterator_prev().
1079                         bool is_last() const;                                               ///< See FLAC__metadata_simple_iterator_is_last().
1080
1081                         off_t get_block_offset() const;                                     ///< See FLAC__metadata_simple_iterator_get_block_offset().
1082                         ::FLAC__MetadataType get_block_type() const;                        ///< See FLAC__metadata_simple_iterator_get_block_type().
1083                         unsigned get_block_length() const;                                  ///< See FLAC__metadata_simple_iterator_get_block_length().
1084                         bool get_application_id(FLAC__byte *id);                            ///< See FLAC__metadata_simple_iterator_get_application_id().
1085                         Prototype *get_block();                                             ///< See FLAC__metadata_simple_iterator_get_block().
1086                         bool set_block(Prototype *block, bool use_padding = true);          ///< See FLAC__metadata_simple_iterator_set_block().
1087                         bool insert_block_after(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_insert_block_after().
1088                         bool delete_block(bool use_padding = true);                         ///< See FLAC__metadata_simple_iterator_delete_block().
1089
1090                 protected:
1091                         ::FLAC__Metadata_SimpleIterator *iterator_;
1092                         void clear();
1093                 };
1094
1095                 /* \} */
1096
1097
1098                 /** \defgroup flacpp_metadata_level2 FLAC++/metadata.h: metadata level 2 interface
1099                  *  \ingroup flacpp_metadata
1100                  *
1101                  *  \brief
1102                  *  Level 2 metadata iterator.
1103                  *
1104                  *  The flow through the iterator in the C++ layer is similar
1105                  *  to the C layer:
1106                  *    - Create a Chain instance
1107                  *    - Check Chain::is_valid()
1108                  *    - Call Chain::read() and check the return
1109                  *    - Traverse and/or edit with an Iterator or with
1110                  *      Chain::merge_padding() or Chain::sort_padding()
1111                  *    - Write changes back to FLAC file with Chain::write()
1112                  *    - Destroy the Chain instance
1113                  *
1114                  *  The ownership of pointers in the C++ layer is slightly
1115                  *  different than in the C layer, i.e.
1116                  *    - The objects returned by Iterator::get_block() are NOT
1117                  *      owned by the iterator and should be deleted by the
1118                  *      caller when finished, BUT, when you modify the block,
1119                  *      it will directly edit what's in the chain and you do
1120                  *      not need to call Iterator::set_block().  However the
1121                  *      changes will not be reflected in the FLAC file until
1122                  *      the chain is written with Chain::write().
1123                  *    - When you pass an object to Iterator::set_block(),
1124                  *      Iterator::insert_block_before(), or
1125                  *      Iterator::insert_block_after(), the iterator takes
1126                  *      ownership of the block and it will be deleted by the
1127                  *      chain.
1128                  *
1129                  *  See the \link flac_metadata_level2 C layer equivalent \endlink
1130                  *  for more.
1131                  *
1132                  * \{
1133                  */
1134
1135                 /** This class is a wrapper around the FLAC__metadata_chain
1136                  *  structures and methods; see the
1137                  * \link flacpp_metadata_level2 usage guide \endlink and
1138                  * ::FLAC__Metadata_Chain.
1139                  */
1140                 class FLACPP_API Chain {
1141                 public:
1142                         /** This class is a wrapper around FLAC__Metadata_ChainStatus.
1143                          */
1144                         class FLACPP_API Status {
1145                         public:
1146                                 inline Status(::FLAC__Metadata_ChainStatus status): status_(status) { }
1147                                 inline operator ::FLAC__Metadata_ChainStatus() const { return status_; }
1148                                 inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString[status_]; }
1149                         protected:
1150                                 ::FLAC__Metadata_ChainStatus status_;
1151                         };
1152
1153                         Chain();
1154                         virtual ~Chain();
1155
1156                         friend class Iterator;
1157
1158                         bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1159
1160                         Status status();                                                ///< See FLAC__metadata_chain_status().
1161
1162                         bool read(const char *filename, bool is_ogg = false);                                ///< See FLAC__metadata_chain_read(), FLAC__metadata_chain_read_ogg().
1163                         bool read(FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, bool is_ogg = false);  ///< See FLAC__metadata_chain_read_with_callbacks(), FLAC__metadata_chain_read_ogg_with_callbacks().
1164
1165                         bool check_if_tempfile_needed(bool use_padding);                ///< See FLAC__metadata_chain_check_if_tempfile_needed().
1166
1167                         bool write(bool use_padding = true, bool preserve_file_stats = false); ///< See FLAC__metadata_chain_write().
1168                         bool write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks); ///< See FLAC__metadata_chain_write_with_callbacks().
1169                         bool write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks, ::FLAC__IOHandle temp_handle, ::FLAC__IOCallbacks temp_callbacks); ///< See FLAC__metadata_chain_write_with_callbacks_and_tempfile().
1170
1171                         void merge_padding();                                           ///< See FLAC__metadata_chain_merge_padding().
1172                         void sort_padding();                                            ///< See FLAC__metadata_chain_sort_padding().
1173
1174                 protected:
1175                         ::FLAC__Metadata_Chain *chain_;
1176                         virtual void clear();
1177                 };
1178
1179                 /** This class is a wrapper around the FLAC__metadata_iterator
1180                  *  structures and methods; see the
1181                  * \link flacpp_metadata_level2 usage guide \endlink and
1182                  * ::FLAC__Metadata_Iterator.
1183                  */
1184                 class FLACPP_API Iterator {
1185                 public:
1186                         Iterator();
1187                         virtual ~Iterator();
1188
1189                         bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1190
1191
1192                         void init(Chain &chain);                       ///< See FLAC__metadata_iterator_init().
1193
1194                         bool next();                                   ///< See FLAC__metadata_iterator_next().
1195                         bool prev();                                   ///< See FLAC__metadata_iterator_prev().
1196
1197                         ::FLAC__MetadataType get_block_type() const;   ///< See FLAC__metadata_iterator_get_block_type().
1198                         Prototype *get_block();                        ///< See FLAC__metadata_iterator_get_block().
1199                         bool set_block(Prototype *block);              ///< See FLAC__metadata_iterator_set_block().
1200                         bool delete_block(bool replace_with_padding);  ///< See FLAC__metadata_iterator_delete_block().
1201                         bool insert_block_before(Prototype *block);    ///< See FLAC__metadata_iterator_insert_block_before().
1202                         bool insert_block_after(Prototype *block);     ///< See FLAC__metadata_iterator_insert_block_after().
1203
1204                 protected:
1205                         ::FLAC__Metadata_Iterator *iterator_;
1206                         virtual void clear();
1207                 };
1208
1209                 /* \} */
1210
1211         }
1212 }
1213
1214 #endif