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