cmake/configure.ac: Enable -fstack-protector-strong by default
[flac.git] / include / FLAC++ / metadata.h
1 /* libFLAC++ - Free Lossless Audio Codec library
2  * Copyright (C) 2002-2009  Josh Coalson
3  * Copyright (C) 2011-2016  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                         uint32_t 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                 // local utility routines
230
231                 namespace local {
232
233                         /** Construct a new object of the type provided in object->type and return it. */
234                         Prototype *construct_block(::FLAC__StreamMetadata *object);
235
236                 }
237
238 #ifdef _MSC_VER
239 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
240 #pragma warning ( disable : 4800 )
241 #endif
242
243                 inline bool Prototype::operator==(const Prototype &object) const
244                 { return (bool)::FLAC__metadata_object_is_equal(object_, object.object_); }
245
246                 inline bool Prototype::operator==(const ::FLAC__StreamMetadata &object) const
247                 { return (bool)::FLAC__metadata_object_is_equal(object_, &object); }
248
249                 inline bool Prototype::operator==(const ::FLAC__StreamMetadata *object) const
250                 { return (bool)::FLAC__metadata_object_is_equal(object_, object); }
251
252 #ifdef _MSC_VER
253 #pragma warning ( default : 4800 )
254 #endif
255
256                 inline bool Prototype::operator!=(const Prototype &object) const
257                 { return !operator==(object); }
258
259                 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata &object) const
260                 { return !operator==(object); }
261
262                 inline bool Prototype::operator!=(const ::FLAC__StreamMetadata *object) const
263                 { return !operator==(object); }
264
265                 inline bool Prototype::is_valid() const
266                 { return 0 != object_; }
267
268                 inline Prototype::operator const ::FLAC__StreamMetadata *() const
269                 { return object_; }
270
271                 /** Create a deep copy of an object and return it. */
272                 FLACPP_API Prototype *clone(const Prototype *);
273
274
275                 /** STREAMINFO metadata block.
276                  *  See the \link flacpp_metadata_object overview \endlink for more,
277                  *  and the <A HREF="../format.html#metadata_block_streaminfo">format specification</A>.
278                  */
279                 class FLACPP_API StreamInfo : public Prototype {
280                 public:
281                         StreamInfo();
282
283                         //@{
284                         /** Constructs a copy of the given object.  This form
285                          *  always performs a deep copy.
286                          */
287                         inline StreamInfo(const StreamInfo &object): Prototype(object) { }
288                         inline StreamInfo(const ::FLAC__StreamMetadata &object): Prototype(object) { }
289                         inline StreamInfo(const ::FLAC__StreamMetadata *object): Prototype(object) { }
290                         //@}
291
292                         /** Constructs an object with copy control.  See
293                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
294                          */
295                         inline StreamInfo(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
296
297                         ~StreamInfo();
298
299                         //@{
300                         /** Assign from another object.  Always performs a deep copy. */
301                         inline StreamInfo &operator=(const StreamInfo &object) { Prototype::operator=(object); return *this; }
302                         inline StreamInfo &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
303                         inline StreamInfo &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
304                         //@}
305
306                         /** Assigns an object with copy control.  See
307                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
308                          */
309                         inline StreamInfo &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
310
311                         //@{
312                         /** Check for equality, performing a deep compare by following pointers. */
313                         inline bool operator==(const StreamInfo &object) const { return Prototype::operator==(object); }
314                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
315                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
316                         //@}
317
318                         //@{
319                         /** Check for inequality, performing a deep compare by following pointers. */
320                         inline bool operator!=(const StreamInfo &object) const { return Prototype::operator!=(object); }
321                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
322                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
323                         //@}
324
325                         //@{
326                         /** See <A HREF="../format.html#metadata_block_streaminfo">format specification</A>. */
327                         uint32_t get_min_blocksize() const;
328                         uint32_t get_max_blocksize() const;
329                         uint32_t get_min_framesize() const;
330                         uint32_t get_max_framesize() const;
331                         uint32_t get_sample_rate() const;
332                         uint32_t get_channels() const;
333                         uint32_t get_bits_per_sample() const;
334                         FLAC__uint64 get_total_samples() const;
335                         const FLAC__byte *get_md5sum() const;
336
337                         void set_min_blocksize(uint32_t value);
338                         void set_max_blocksize(uint32_t value);
339                         void set_min_framesize(uint32_t value);
340                         void set_max_framesize(uint32_t value);
341                         void set_sample_rate(uint32_t value);
342                         void set_channels(uint32_t value);
343                         void set_bits_per_sample(uint32_t value);
344                         void set_total_samples(FLAC__uint64 value);
345                         void set_md5sum(const FLAC__byte value[16]);
346                         //@}
347                 };
348
349                 /** PADDING metadata block.
350                  *  See the \link flacpp_metadata_object overview \endlink for more,
351                  *  and the <A HREF="../format.html#metadata_block_padding">format specification</A>.
352                  */
353                 class FLACPP_API Padding : public Prototype {
354                 public:
355                         Padding();
356
357                         //@{
358                         /** Constructs a copy of the given object.  This form
359                          *  always performs a deep copy.
360                          */
361                         inline Padding(const Padding &object): Prototype(object) { }
362                         inline Padding(const ::FLAC__StreamMetadata &object): Prototype(object) { }
363                         inline Padding(const ::FLAC__StreamMetadata *object): Prototype(object) { }
364                         //@}
365
366                         /** Constructs an object with copy control.  See
367                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
368                          */
369                         inline Padding(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
370
371                         /** Constructs an object with the given length.
372                          */
373                         Padding(uint32_t length);
374
375                         ~Padding();
376
377                         //@{
378                         /** Assign from another object.  Always performs a deep copy. */
379                         inline Padding &operator=(const Padding &object) { Prototype::operator=(object); return *this; }
380                         inline Padding &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
381                         inline Padding &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
382                         //@}
383
384                         /** Assigns an object with copy control.  See
385                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
386                          */
387                         inline Padding &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
388
389                         //@{
390                         /** Check for equality, performing a deep compare by following pointers. */
391                         inline bool operator==(const Padding &object) const { return Prototype::operator==(object); }
392                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
393                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
394                         //@}
395
396                         //@{
397                         /** Check for inequality, performing a deep compare by following pointers. */
398                         inline bool operator!=(const Padding &object) const { return Prototype::operator!=(object); }
399                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
400                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
401                         //@}
402
403                         /** Sets the length in bytes of the padding block.
404                          */
405                         void set_length(uint32_t length);
406                 };
407
408                 /** APPLICATION metadata block.
409                  *  See the \link flacpp_metadata_object overview \endlink for more,
410                  *  and the <A HREF="../format.html#metadata_block_application">format specification</A>.
411                  */
412                 class FLACPP_API Application : public Prototype {
413                 public:
414                         Application();
415                         //
416                         //@{
417                         /** Constructs a copy of the given object.  This form
418                          *  always performs a deep copy.
419                          */
420                         inline Application(const Application &object): Prototype(object) { }
421                         inline Application(const ::FLAC__StreamMetadata &object): Prototype(object) { }
422                         inline Application(const ::FLAC__StreamMetadata *object): Prototype(object) { }
423                         //@}
424
425                         /** Constructs an object with copy control.  See
426                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
427                          */
428                         inline Application(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
429
430                         ~Application();
431
432                         //@{
433                         /** Assign from another object.  Always performs a deep copy. */
434                         inline Application &operator=(const Application &object) { Prototype::operator=(object); return *this; }
435                         inline Application &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
436                         inline Application &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
437                         //@}
438
439                         /** Assigns an object with copy control.  See
440                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
441                          */
442                         inline Application &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
443
444                         //@{
445                         /** Check for equality, performing a deep compare by following pointers. */
446                         inline bool operator==(const Application &object) const { return Prototype::operator==(object); }
447                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
448                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
449                         //@}
450
451                         //@{
452                         /** Check for inequality, performing a deep compare by following pointers. */
453                         inline bool operator!=(const Application &object) const { return Prototype::operator!=(object); }
454                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
455                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
456                         //@}
457
458                         const FLAC__byte *get_id() const;
459                         const FLAC__byte *get_data() const;
460
461                         void set_id(const FLAC__byte value[4]);
462                         //! This form always copies \a data
463                         bool set_data(const FLAC__byte *data, uint32_t length);
464                         bool set_data(FLAC__byte *data, uint32_t length, bool copy);
465                 };
466
467                 /** SEEKTABLE metadata block.
468                  *  See the \link flacpp_metadata_object overview \endlink for more,
469                  *  and the <A HREF="../format.html#metadata_block_seektable">format specification</A>.
470                  */
471                 class FLACPP_API SeekTable : public Prototype {
472                 public:
473                         SeekTable();
474
475                         //@{
476                         /** Constructs a copy of the given object.  This form
477                          *  always performs a deep copy.
478                          */
479                         inline SeekTable(const SeekTable &object): Prototype(object) { }
480                         inline SeekTable(const ::FLAC__StreamMetadata &object): Prototype(object) { }
481                         inline SeekTable(const ::FLAC__StreamMetadata *object): Prototype(object) { }
482                         //@}
483
484                         /** Constructs an object with copy control.  See
485                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
486                          */
487                         inline SeekTable(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
488
489                         ~SeekTable();
490
491                         //@{
492                         /** Assign from another object.  Always performs a deep copy. */
493                         inline SeekTable &operator=(const SeekTable &object) { Prototype::operator=(object); return *this; }
494                         inline SeekTable &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
495                         inline SeekTable &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
496                         //@}
497
498                         /** Assigns an object with copy control.  See
499                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
500                          */
501                         inline SeekTable &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
502
503                         //@{
504                         /** Check for equality, performing a deep compare by following pointers. */
505                         inline bool operator==(const SeekTable &object) const { return Prototype::operator==(object); }
506                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
507                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
508                         //@}
509
510                         //@{
511                         /** Check for inequality, performing a deep compare by following pointers. */
512                         inline bool operator!=(const SeekTable &object) const { return Prototype::operator!=(object); }
513                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
514                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
515                         //@}
516
517                         uint32_t get_num_points() const;
518                         ::FLAC__StreamMetadata_SeekPoint get_point(uint32_t index) const;
519
520                         //! See FLAC__metadata_object_seektable_resize_points()
521                         bool resize_points(uint32_t new_num_points);
522
523                         //! See FLAC__metadata_object_seektable_set_point()
524                         void set_point(uint32_t index, const ::FLAC__StreamMetadata_SeekPoint &point);
525
526                         //! See FLAC__metadata_object_seektable_insert_point()
527                         bool insert_point(uint32_t index, const ::FLAC__StreamMetadata_SeekPoint &point);
528
529                         //! See FLAC__metadata_object_seektable_delete_point()
530                         bool delete_point(uint32_t index);
531
532                         //! See FLAC__metadata_object_seektable_is_legal()
533                         bool is_legal() const;
534
535                         //! See FLAC__metadata_object_seektable_template_append_placeholders()
536                         bool template_append_placeholders(uint32_t num);
537
538                         //! See FLAC__metadata_object_seektable_template_append_point()
539                         bool template_append_point(FLAC__uint64 sample_number);
540
541                         //! See FLAC__metadata_object_seektable_template_append_points()
542                         bool template_append_points(FLAC__uint64 sample_numbers[], uint32_t num);
543
544                         //! See FLAC__metadata_object_seektable_template_append_spaced_points()
545                         bool template_append_spaced_points(uint32_t num, FLAC__uint64 total_samples);
546
547                         //! See FLAC__metadata_object_seektable_template_append_spaced_points_by_samples()
548                         bool template_append_spaced_points_by_samples(uint32_t samples, FLAC__uint64 total_samples);
549
550                         //! See FLAC__metadata_object_seektable_template_sort()
551                         bool template_sort(bool compact);
552                 };
553
554                 /** VORBIS_COMMENT metadata block.
555                  *  See the \link flacpp_metadata_object overview \endlink for more,
556                  *  and the <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>.
557                  */
558                 class FLACPP_API VorbisComment : public Prototype {
559                 public:
560                         /** Convenience class for encapsulating Vorbis comment
561                          *  entries.  An entry is a vendor string or a comment
562                          *  field.  In the case of a vendor string, the field
563                          *  name is undefined; only the field value is relevant.
564                          *
565                          *  A \a field as used in the methods refers to an
566                          *  entire 'NAME=VALUE' string; for convenience the
567                          *  string is NUL-terminated.  A length field is
568                          *  required in the unlikely event that the value
569                          *  contains contain embedded NULs.
570                          *
571                          *  A \a field_name is what is on the left side of the
572                          *  first '=' in the \a field.  By definition it is ASCII
573                          *  and so is NUL-terminated and does not require a
574                          *  length to describe it.  \a field_name is undefined
575                          *  for a vendor string entry.
576                          *
577                          *  A \a field_value is what is on the right side of the
578                          *  first '=' in the \a field.  By definition, this may
579                          *  contain embedded NULs and so a \a field_value_length
580                          *  is required to describe it.  However in practice,
581                          *  embedded NULs are not known to be used, so it is
582                          *  generally safe to treat field values as NUL-
583                          *  terminated UTF-8 strings.
584                          *
585                          *  Always check is_valid() after the constructor or operator=
586                          *  to make sure memory was properly allocated and that the
587                          *  Entry conforms to the Vorbis comment specification.
588                          */
589                         class FLACPP_API Entry {
590                         public:
591                                 Entry();
592
593                                 Entry(const char *field, uint32_t field_length);
594                                 Entry(const char *field); // assumes \a field is NUL-terminated
595
596                                 Entry(const char *field_name, const char *field_value, uint32_t field_value_length);
597                                 Entry(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
598
599                                 Entry(const Entry &entry);
600
601                                 Entry &operator=(const Entry &entry);
602
603                                 virtual ~Entry();
604
605                                 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
606
607                                 uint32_t get_field_length() const;
608                                 uint32_t get_field_name_length() const;
609                                 uint32_t get_field_value_length() const;
610
611                                 ::FLAC__StreamMetadata_VorbisComment_Entry get_entry() const;
612                                 const char *get_field() const;
613                                 const char *get_field_name() const;
614                                 const char *get_field_value() const;
615
616                                 bool set_field(const char *field, uint32_t field_length);
617                                 bool set_field(const char *field); // assumes \a field is NUL-terminated
618                                 bool set_field_name(const char *field_name);
619                                 bool set_field_value(const char *field_value, uint32_t field_value_length);
620                                 bool set_field_value(const char *field_value); // assumes \a field_value is NUL-terminated
621                         protected:
622                                 bool is_valid_;
623                                 ::FLAC__StreamMetadata_VorbisComment_Entry entry_;
624                                 char *field_name_;
625                                 uint32_t field_name_length_;
626                                 char *field_value_;
627                                 uint32_t field_value_length_;
628                         private:
629                                 void zero();
630                                 void clear();
631                                 void clear_entry();
632                                 void clear_field_name();
633                                 void clear_field_value();
634                                 void construct(const char *field, uint32_t field_length);
635                                 void construct(const char *field); // assumes \a field is NUL-terminated
636                                 void construct(const char *field_name, const char *field_value, uint32_t field_value_length);
637                                 void construct(const char *field_name, const char *field_value); // assumes \a field_value is NUL-terminated
638                                 void compose_field();
639                                 void parse_field();
640                         };
641
642                         VorbisComment();
643
644                         //@{
645                         /** Constructs a copy of the given object.  This form
646                          *  always performs a deep copy.
647                          */
648                         inline VorbisComment(const VorbisComment &object): Prototype(object) { }
649                         inline VorbisComment(const ::FLAC__StreamMetadata &object): Prototype(object) { }
650                         inline VorbisComment(const ::FLAC__StreamMetadata *object): Prototype(object) { }
651                         //@}
652
653                         /** Constructs an object with copy control.  See
654                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
655                          */
656                         inline VorbisComment(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
657
658                         ~VorbisComment();
659
660                         //@{
661                         /** Assign from another object.  Always performs a deep copy. */
662                         inline VorbisComment &operator=(const VorbisComment &object) { Prototype::operator=(object); return *this; }
663                         inline VorbisComment &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
664                         inline VorbisComment &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
665                         //@}
666
667                         /** Assigns an object with copy control.  See
668                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
669                          */
670                         inline VorbisComment &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
671
672                         //@{
673                         /** Check for equality, performing a deep compare by following pointers. */
674                         inline bool operator==(const VorbisComment &object) const { return Prototype::operator==(object); }
675                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
676                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
677                         //@}
678
679                         //@{
680                         /** Check for inequality, performing a deep compare by following pointers. */
681                         inline bool operator!=(const VorbisComment &object) const { return Prototype::operator!=(object); }
682                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
683                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
684                         //@}
685
686                         uint32_t get_num_comments() const;
687                         const FLAC__byte *get_vendor_string() const; // NUL-terminated UTF-8 string
688                         Entry get_comment(uint32_t index) const;
689
690                         //! See FLAC__metadata_object_vorbiscomment_set_vendor_string()
691                         bool set_vendor_string(const FLAC__byte *string); // NUL-terminated UTF-8 string
692
693                         //! See FLAC__metadata_object_vorbiscomment_resize_comments()
694                         bool resize_comments(uint32_t new_num_comments);
695
696                         //! See FLAC__metadata_object_vorbiscomment_set_comment()
697                         bool set_comment(uint32_t index, const Entry &entry);
698
699                         //! See FLAC__metadata_object_vorbiscomment_insert_comment()
700                         bool insert_comment(uint32_t index, const Entry &entry);
701
702                         //! See FLAC__metadata_object_vorbiscomment_append_comment()
703                         bool append_comment(const Entry &entry);
704
705                         //! See FLAC__metadata_object_vorbiscomment_replace_comment()
706                         bool replace_comment(const Entry &entry, bool all);
707
708                         //! See FLAC__metadata_object_vorbiscomment_delete_comment()
709                         bool delete_comment(uint32_t index);
710
711                         //! See FLAC__metadata_object_vorbiscomment_find_entry_from()
712                         int find_entry_from(uint32_t offset, const char *field_name);
713
714                         //! See FLAC__metadata_object_vorbiscomment_remove_entry_matching()
715                         int remove_entry_matching(const char *field_name);
716
717                         //! See FLAC__metadata_object_vorbiscomment_remove_entries_matching()
718                         int remove_entries_matching(const char *field_name);
719                 };
720
721                 /** CUESHEET metadata block.
722                  *  See the \link flacpp_metadata_object overview \endlink for more,
723                  *  and the <A HREF="../format.html#metadata_block_cuesheet">format specification</A>.
724                  */
725                 class FLACPP_API CueSheet : public Prototype {
726                 public:
727                         /** Convenience class for encapsulating a cue sheet
728                          *  track.
729                          *
730                          *  Always check is_valid() after the constructor or operator=
731                          *  to make sure memory was properly allocated.
732                          */
733                         class FLACPP_API Track {
734                         protected:
735                                 ::FLAC__StreamMetadata_CueSheet_Track *object_;
736                         public:
737                                 Track();
738                                 Track(const ::FLAC__StreamMetadata_CueSheet_Track *track);
739                                 Track(const Track &track);
740                                 Track &operator=(const Track &track);
741
742                                 virtual ~Track();
743
744                                 virtual bool is_valid() const; ///< Returns \c true iff object was properly constructed.
745
746
747                                 inline FLAC__uint64 get_offset() const { return object_->offset; }
748                                 inline FLAC__byte get_number() const { return object_->number; }
749                                 inline const char *get_isrc() const { return object_->isrc; }
750                                 inline uint32_t get_type() const { return object_->type; }
751                                 inline bool get_pre_emphasis() const { return object_->pre_emphasis; }
752
753                                 inline FLAC__byte get_num_indices() const { return object_->num_indices; }
754                                 ::FLAC__StreamMetadata_CueSheet_Index get_index(uint32_t i) const;
755
756                                 inline const ::FLAC__StreamMetadata_CueSheet_Track *get_track() const { return object_; }
757
758                                 inline void set_offset(FLAC__uint64 value) { object_->offset = value; }
759                                 inline void set_number(FLAC__byte value) { object_->number = value; }
760                                 void set_isrc(const char value[12]);
761                                 void set_type(uint32_t value);
762                                 inline void set_pre_emphasis(bool value) { object_->pre_emphasis = value? 1 : 0; }
763
764                                 void set_index(uint32_t i, const ::FLAC__StreamMetadata_CueSheet_Index &index);
765                                 //@@@ It's awkward but to insert/delete index points
766                                 //@@@ you must use the routines in the CueSheet class.
767                         };
768
769                         CueSheet();
770
771                         //@{
772                         /** Constructs a copy of the given object.  This form
773                          *  always performs a deep copy.
774                          */
775                         inline CueSheet(const CueSheet &object): Prototype(object) { }
776                         inline CueSheet(const ::FLAC__StreamMetadata &object): Prototype(object) { }
777                         inline CueSheet(const ::FLAC__StreamMetadata *object): Prototype(object) { }
778                         //@}
779
780                         /** Constructs an object with copy control.  See
781                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
782                          */
783                         inline CueSheet(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
784
785                         ~CueSheet();
786
787                         //@{
788                         /** Assign from another object.  Always performs a deep copy. */
789                         inline CueSheet &operator=(const CueSheet &object) { Prototype::operator=(object); return *this; }
790                         inline CueSheet &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
791                         inline CueSheet &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
792                         //@}
793
794                         /** Assigns an object with copy control.  See
795                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
796                          */
797                         inline CueSheet &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
798
799                         //@{
800                         /** Check for equality, performing a deep compare by following pointers. */
801                         inline bool operator==(const CueSheet &object) const { return Prototype::operator==(object); }
802                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
803                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
804                         //@}
805
806                         //@{
807                         /** Check for inequality, performing a deep compare by following pointers. */
808                         inline bool operator!=(const CueSheet &object) const { return Prototype::operator!=(object); }
809                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
810                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
811                         //@}
812
813                         const char *get_media_catalog_number() const;
814                         FLAC__uint64 get_lead_in() const;
815                         bool get_is_cd() const;
816
817                         uint32_t get_num_tracks() const;
818                         Track get_track(uint32_t i) const;
819
820                         void set_media_catalog_number(const char value[128]);
821                         void set_lead_in(FLAC__uint64 value);
822                         void set_is_cd(bool value);
823
824                         void set_index(uint32_t track_num, uint32_t index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
825
826                         //! See FLAC__metadata_object_cuesheet_track_resize_indices()
827                         bool resize_indices(uint32_t track_num, uint32_t new_num_indices);
828
829                         //! See FLAC__metadata_object_cuesheet_track_insert_index()
830                         bool insert_index(uint32_t track_num, uint32_t index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
831
832                         //! See FLAC__metadata_object_cuesheet_track_insert_blank_index()
833                         bool insert_blank_index(uint32_t track_num, uint32_t index_num);
834
835                         //! See FLAC__metadata_object_cuesheet_track_delete_index()
836                         bool delete_index(uint32_t track_num, uint32_t index_num);
837
838                         //! See FLAC__metadata_object_cuesheet_resize_tracks()
839                         bool resize_tracks(uint32_t new_num_tracks);
840
841                         //! See FLAC__metadata_object_cuesheet_set_track()
842                         bool set_track(uint32_t i, const Track &track);
843
844                         //! See FLAC__metadata_object_cuesheet_insert_track()
845                         bool insert_track(uint32_t i, const Track &track);
846
847                         //! See FLAC__metadata_object_cuesheet_insert_blank_track()
848                         bool insert_blank_track(uint32_t i);
849
850                         //! See FLAC__metadata_object_cuesheet_delete_track()
851                         bool delete_track(uint32_t i);
852
853                         //! See FLAC__metadata_object_cuesheet_is_legal()
854                         bool is_legal(bool check_cd_da_subset = false, const char **violation = 0) const;
855
856                         //! See FLAC__metadata_object_cuesheet_calculate_cddb_id()
857                         FLAC__uint32 calculate_cddb_id() const;
858                 };
859
860                 /** PICTURE metadata block.
861                  *  See the \link flacpp_metadata_object overview \endlink for more,
862                  *  and the <A HREF="../format.html#metadata_block_picture">format specification</A>.
863                  */
864                 class FLACPP_API Picture : public Prototype {
865                 public:
866                         Picture();
867
868                         //@{
869                         /** Constructs a copy of the given object.  This form
870                          *  always performs a deep copy.
871                          */
872                         inline Picture(const Picture &object): Prototype(object) { }
873                         inline Picture(const ::FLAC__StreamMetadata &object): Prototype(object) { }
874                         inline Picture(const ::FLAC__StreamMetadata *object): Prototype(object) { }
875                         //@}
876
877                         /** Constructs an object with copy control.  See
878                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
879                          */
880                         inline Picture(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
881
882                         ~Picture();
883
884                         //@{
885                         /** Assign from another object.  Always performs a deep copy. */
886                         inline Picture &operator=(const Picture &object) { Prototype::operator=(object); return *this; }
887                         inline Picture &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
888                         inline Picture &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
889                         //@}
890
891                         /** Assigns an object with copy control.  See
892                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
893                          */
894                         inline Picture &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
895
896                         //@{
897                         /** Check for equality, performing a deep compare by following pointers. */
898                         inline bool operator==(const Picture &object) const { return Prototype::operator==(object); }
899                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
900                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
901                         //@}
902
903                         //@{
904                         /** Check for inequality, performing a deep compare by following pointers. */
905                         inline bool operator!=(const Picture &object) const { return Prototype::operator!=(object); }
906                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
907                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
908                         //@}
909
910                         ::FLAC__StreamMetadata_Picture_Type get_type() const;
911                         const char *get_mime_type() const; // NUL-terminated printable ASCII string
912                         const FLAC__byte *get_description() const; // NUL-terminated UTF-8 string
913                         FLAC__uint32 get_width() const;
914                         FLAC__uint32 get_height() const;
915                         FLAC__uint32 get_depth() const;
916                         FLAC__uint32 get_colors() const; ///< a return value of \c 0 means true-color, i.e. 2^depth colors
917                         FLAC__uint32 get_data_length() const;
918                         const FLAC__byte *get_data() const;
919
920                         void set_type(::FLAC__StreamMetadata_Picture_Type type);
921
922                         //! See FLAC__metadata_object_picture_set_mime_type()
923                         bool set_mime_type(const char *string); // NUL-terminated printable ASCII string
924
925                         //! See FLAC__metadata_object_picture_set_description()
926                         bool set_description(const FLAC__byte *string); // NUL-terminated UTF-8 string
927
928                         void set_width(FLAC__uint32 value) const;
929                         void set_height(FLAC__uint32 value) const;
930                         void set_depth(FLAC__uint32 value) const;
931                         void set_colors(FLAC__uint32 value) const; ///< a value of \c 0 means true-color, i.e. 2^depth colors
932
933                         //! See FLAC__metadata_object_picture_set_data()
934                         bool set_data(const FLAC__byte *data, FLAC__uint32 data_length);
935
936                         //! See FLAC__metadata_object_picture_is_legal()
937                         bool is_legal(const char **violation);
938                 };
939
940                 /** Opaque metadata block for storing unknown types.
941                  *  This should not be used unless you know what you are doing;
942                  *  it is currently used only internally to support forward
943                  *  compatibility of metadata blocks.
944                  *  See the \link flacpp_metadata_object overview \endlink for more,
945                  */
946                 class FLACPP_API Unknown : public Prototype {
947                 public:
948                         Unknown();
949                         //
950                         //@{
951                         /** Constructs a copy of the given object.  This form
952                          *  always performs a deep copy.
953                          */
954                         inline Unknown(const Unknown &object): Prototype(object) { }
955                         inline Unknown(const ::FLAC__StreamMetadata &object): Prototype(object) { }
956                         inline Unknown(const ::FLAC__StreamMetadata *object): Prototype(object) { }
957                         //@}
958
959                         /** Constructs an object with copy control.  See
960                          *  Prototype(::FLAC__StreamMetadata *object, bool copy).
961                          */
962                         inline Unknown(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
963
964                         ~Unknown();
965
966                         //@{
967                         /** Assign from another object.  Always performs a deep copy. */
968                         inline Unknown &operator=(const Unknown &object) { Prototype::operator=(object); return *this; }
969                         inline Unknown &operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); return *this; }
970                         inline Unknown &operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); return *this; }
971                         //@}
972
973                         /** Assigns an object with copy control.  See
974                          *  Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy).
975                          */
976                         inline Unknown &assign(::FLAC__StreamMetadata *object, bool copy) { Prototype::assign_object(object, copy); return *this; }
977
978                         //@{
979                         /** Check for equality, performing a deep compare by following pointers. */
980                         inline bool operator==(const Unknown &object) const { return Prototype::operator==(object); }
981                         inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
982                         inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
983                         //@}
984
985                         //@{
986                         /** Check for inequality, performing a deep compare by following pointers. */
987                         inline bool operator!=(const Unknown &object) const { return Prototype::operator!=(object); }
988                         inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
989                         inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
990                         //@}
991
992                         const FLAC__byte *get_data() const;
993
994                         //! This form always copies \a data
995                         bool set_data(const FLAC__byte *data, uint32_t length);
996                         bool set_data(FLAC__byte *data, uint32_t length, bool copy);
997                 };
998
999                 /* \} */
1000
1001
1002                 /** \defgroup flacpp_metadata_level0 FLAC++/metadata.h: metadata level 0 interface
1003                  *  \ingroup flacpp_metadata
1004                  *
1005                  *  \brief
1006                  *  Level 0 metadata iterators.
1007                  *
1008                  *  See the \link flac_metadata_level0 C layer equivalent \endlink
1009                  *  for more.
1010                  *
1011                  * \{
1012                  */
1013
1014                 FLACPP_API bool get_streaminfo(const char *filename, StreamInfo &streaminfo); ///< See FLAC__metadata_get_streaminfo().
1015
1016                 FLACPP_API bool get_tags(const char *filename, VorbisComment *&tags); ///< See FLAC__metadata_get_tags().
1017                 FLACPP_API bool get_tags(const char *filename, VorbisComment &tags); ///< See FLAC__metadata_get_tags().
1018
1019                 FLACPP_API bool get_cuesheet(const char *filename, CueSheet *&cuesheet); ///< See FLAC__metadata_get_cuesheet().
1020                 FLACPP_API bool get_cuesheet(const char *filename, CueSheet &cuesheet); ///< See FLAC__metadata_get_cuesheet().
1021
1022                 FLACPP_API bool get_picture(const char *filename, Picture *&picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors); ///< See FLAC__metadata_get_picture().
1023                 FLACPP_API bool get_picture(const char *filename, Picture &picture, ::FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, uint32_t max_width, uint32_t max_height, uint32_t max_depth, uint32_t max_colors); ///< See FLAC__metadata_get_picture().
1024
1025                 /* \} */
1026
1027
1028                 /** \defgroup flacpp_metadata_level1 FLAC++/metadata.h: metadata level 1 interface
1029                  *  \ingroup flacpp_metadata
1030                  *
1031                  *  \brief
1032                  *  Level 1 metadata iterator.
1033                  *
1034                  *  The flow through the iterator in the C++ layer is similar
1035                  *  to the C layer:
1036                  *    - Create a SimpleIterator instance
1037                  *    - Check SimpleIterator::is_valid()
1038                  *    - Call SimpleIterator::init() and check the return
1039                  *    - Traverse and/or edit.  Edits are written to file
1040                  *      immediately.
1041                  *    - Destroy the SimpleIterator instance
1042                  *
1043                  *  The ownership of pointers in the C++ layer follows that in
1044                  *  the C layer, i.e.
1045                  *    - The objects returned by get_block() are yours to
1046                  *      modify, but changes are not reflected in the FLAC file
1047                  *      until you call set_block().  The objects are also
1048                  *      yours to delete; they are not automatically deleted
1049                  *      when passed to set_block() or insert_block_after().
1050                  *
1051                  *  See the \link flac_metadata_level1 C layer equivalent \endlink
1052                  *  for more.
1053                  *
1054                  * \{
1055                  */
1056
1057                 /** This class is a wrapper around the FLAC__metadata_simple_iterator
1058                  *  structures and methods; see the
1059                  * \link flacpp_metadata_level1 usage guide \endlink and
1060                  * ::FLAC__Metadata_SimpleIterator.
1061                  */
1062                 class FLACPP_API SimpleIterator {
1063                 public:
1064                         /** This class is a wrapper around FLAC__Metadata_SimpleIteratorStatus.
1065                          */
1066                         class FLACPP_API Status {
1067                         public:
1068                                 inline Status(::FLAC__Metadata_SimpleIteratorStatus status): status_(status) { }
1069                                 inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_; }
1070                                 inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString[status_]; }
1071                         protected:
1072                                 ::FLAC__Metadata_SimpleIteratorStatus status_;
1073                         };
1074
1075                         SimpleIterator();
1076                         virtual ~SimpleIterator();
1077
1078                         bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1079
1080                         bool init(const char *filename, bool read_only, bool preserve_file_stats); ///< See FLAC__metadata_simple_iterator_init().
1081
1082                         Status status();                                                    ///< See FLAC__metadata_simple_iterator_status().
1083                         bool is_writable() const;                                           ///< See FLAC__metadata_simple_iterator_is_writable().
1084
1085                         bool next();                                                        ///< See FLAC__metadata_simple_iterator_next().
1086                         bool prev();                                                        ///< See FLAC__metadata_simple_iterator_prev().
1087                         bool is_last() const;                                               ///< See FLAC__metadata_simple_iterator_is_last().
1088
1089                         off_t get_block_offset() const;                                     ///< See FLAC__metadata_simple_iterator_get_block_offset().
1090                         ::FLAC__MetadataType get_block_type() const;                        ///< See FLAC__metadata_simple_iterator_get_block_type().
1091                         uint32_t get_block_length() const;                                  ///< See FLAC__metadata_simple_iterator_get_block_length().
1092                         bool get_application_id(FLAC__byte *id);                            ///< See FLAC__metadata_simple_iterator_get_application_id().
1093                         Prototype *get_block();                                             ///< See FLAC__metadata_simple_iterator_get_block().
1094                         bool set_block(Prototype *block, bool use_padding = true);          ///< See FLAC__metadata_simple_iterator_set_block().
1095                         bool insert_block_after(Prototype *block, bool use_padding = true); ///< See FLAC__metadata_simple_iterator_insert_block_after().
1096                         bool delete_block(bool use_padding = true);                         ///< See FLAC__metadata_simple_iterator_delete_block().
1097
1098                 protected:
1099                         ::FLAC__Metadata_SimpleIterator *iterator_;
1100                         void clear();
1101
1102                 private: // Do not use.
1103                         SimpleIterator(const SimpleIterator&);
1104                         SimpleIterator&operator=(const SimpleIterator&);
1105                 };
1106
1107                 /* \} */
1108
1109
1110                 /** \defgroup flacpp_metadata_level2 FLAC++/metadata.h: metadata level 2 interface
1111                  *  \ingroup flacpp_metadata
1112                  *
1113                  *  \brief
1114                  *  Level 2 metadata iterator.
1115                  *
1116                  *  The flow through the iterator in the C++ layer is similar
1117                  *  to the C layer:
1118                  *    - Create a Chain instance
1119                  *    - Check Chain::is_valid()
1120                  *    - Call Chain::read() and check the return
1121                  *    - Traverse and/or edit with an Iterator or with
1122                  *      Chain::merge_padding() or Chain::sort_padding()
1123                  *    - Write changes back to FLAC file with Chain::write()
1124                  *    - Destroy the Chain instance
1125                  *
1126                  *  The ownership of pointers in the C++ layer is slightly
1127                  *  different than in the C layer, i.e.
1128                  *    - The objects returned by Iterator::get_block() are NOT
1129                  *      owned by the iterator and should be deleted by the
1130                  *      caller when finished, BUT, when you modify the block,
1131                  *      it will directly edit what's in the chain and you do
1132                  *      not need to call Iterator::set_block().  However the
1133                  *      changes will not be reflected in the FLAC file until
1134                  *      the chain is written with Chain::write().
1135                  *    - When you pass an object to Iterator::set_block(),
1136                  *      Iterator::insert_block_before(), or
1137                  *      Iterator::insert_block_after(), the iterator takes
1138                  *      ownership of the block and it will be deleted by the
1139                  *      chain.
1140                  *
1141                  *  See the \link flac_metadata_level2 C layer equivalent \endlink
1142                  *  for more.
1143                  *
1144                  * \{
1145                  */
1146
1147                 /** This class is a wrapper around the FLAC__metadata_chain
1148                  *  structures and methods; see the
1149                  * \link flacpp_metadata_level2 usage guide \endlink and
1150                  * ::FLAC__Metadata_Chain.
1151                  */
1152                 class FLACPP_API Chain {
1153                 public:
1154                         /** This class is a wrapper around FLAC__Metadata_ChainStatus.
1155                          */
1156                         class FLACPP_API Status {
1157                         public:
1158                                 inline Status(::FLAC__Metadata_ChainStatus status): status_(status) { }
1159                                 inline operator ::FLAC__Metadata_ChainStatus() const { return status_; }
1160                                 inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString[status_]; }
1161                         protected:
1162                                 ::FLAC__Metadata_ChainStatus status_;
1163                         };
1164
1165                         Chain();
1166                         virtual ~Chain();
1167
1168                         friend class Iterator;
1169
1170                         bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1171
1172                         Status status();                                                ///< See FLAC__metadata_chain_status().
1173
1174                         bool read(const char *filename, bool is_ogg = false);                                ///< See FLAC__metadata_chain_read(), FLAC__metadata_chain_read_ogg().
1175                         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().
1176
1177                         bool check_if_tempfile_needed(bool use_padding);                ///< See FLAC__metadata_chain_check_if_tempfile_needed().
1178
1179                         bool write(bool use_padding = true, bool preserve_file_stats = false); ///< See FLAC__metadata_chain_write().
1180                         bool write(bool use_padding, ::FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks); ///< See FLAC__metadata_chain_write_with_callbacks().
1181                         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().
1182
1183                         void merge_padding();                                           ///< See FLAC__metadata_chain_merge_padding().
1184                         void sort_padding();                                            ///< See FLAC__metadata_chain_sort_padding().
1185
1186                 protected:
1187                         ::FLAC__Metadata_Chain *chain_;
1188                         virtual void clear();
1189
1190                 private: // Do not use.
1191                         Chain(const Chain&);
1192                         Chain&operator=(const Chain&);
1193                 };
1194
1195                 /** This class is a wrapper around the FLAC__metadata_iterator
1196                  *  structures and methods; see the
1197                  * \link flacpp_metadata_level2 usage guide \endlink and
1198                  * ::FLAC__Metadata_Iterator.
1199                  */
1200                 class FLACPP_API Iterator {
1201                 public:
1202                         Iterator();
1203                         virtual ~Iterator();
1204
1205                         bool is_valid() const; ///< Returns \c true iff object was properly constructed.
1206
1207
1208                         void init(Chain &chain);                       ///< See FLAC__metadata_iterator_init().
1209
1210                         bool next();                                   ///< See FLAC__metadata_iterator_next().
1211                         bool prev();                                   ///< See FLAC__metadata_iterator_prev().
1212
1213                         ::FLAC__MetadataType get_block_type() const;   ///< See FLAC__metadata_iterator_get_block_type().
1214                         Prototype *get_block();                        ///< See FLAC__metadata_iterator_get_block().
1215                         bool set_block(Prototype *block);              ///< See FLAC__metadata_iterator_set_block().
1216                         bool delete_block(bool replace_with_padding);  ///< See FLAC__metadata_iterator_delete_block().
1217                         bool insert_block_before(Prototype *block);    ///< See FLAC__metadata_iterator_insert_block_before().
1218                         bool insert_block_after(Prototype *block);     ///< See FLAC__metadata_iterator_insert_block_after().
1219
1220                 protected:
1221                         ::FLAC__Metadata_Iterator *iterator_;
1222                         virtual void clear();
1223
1224                 private: // Do not use.
1225                         Iterator(const Iterator&);
1226                         Iterator&operator=(const Iterator&);
1227                 };
1228
1229                 /* \} */
1230
1231         }
1232 }
1233
1234 #endif