work around MSVC bug in set_metadata()
authorJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 23 Jul 2004 05:16:11 +0000 (05:16 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Fri, 23 Jul 2004 05:16:11 +0000 (05:16 +0000)
src/libFLAC++/file_encoder.cpp
src/libFLAC++/seekable_stream_encoder.cpp
src/libFLAC++/stream_encoder.cpp

index 875fc6c..1c20b35 100644 (file)
@@ -168,12 +168,26 @@ namespace FLAC {
                bool File::set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks)
                {
                        FLAC__ASSERT(is_valid());
+#ifdef _MSC_VER
+                       // MSVC++ can't handle:
+                       // ::FLAC__StreamMetadata *m[num_blocks];
+                       // so we do this ugly workaround
+                       ::FLAC__StreamMetadata **m = new ::FLAC__StreamMetadata*[num_blocks];
+#else
                        ::FLAC__StreamMetadata *m[num_blocks];
+#endif
                        for(unsigned i = 0; i < num_blocks; i++) {
                                // we can get away with this since we know the encoder will only correct the is_last flags
                                m[i] = const_cast< ::FLAC__StreamMetadata*>((::FLAC__StreamMetadata*)metadata[i]);
                        }
+#ifdef _MSC_VER
+                       // complete the hack
+                       const bool ok = (bool)::FLAC__file_encoder_set_metadata(encoder_, m, num_blocks);
+                       delete [] m;
+                       return ok;
+#else
                        return (bool)::FLAC__file_encoder_set_metadata(encoder_, m, num_blocks);
+#endif
                }
 
                bool File::set_filename(const char *value)
index 9e8f58e..c51da4f 100644 (file)
@@ -168,12 +168,26 @@ namespace FLAC {
                bool SeekableStream::set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks)
                {
                        FLAC__ASSERT(is_valid());
+#ifdef _MSC_VER
+                       // MSVC++ can't handle:
+                       // ::FLAC__StreamMetadata *m[num_blocks];
+                       // so we do this ugly workaround
+                       ::FLAC__StreamMetadata **m = new ::FLAC__StreamMetadata*[num_blocks];
+#else
                        ::FLAC__StreamMetadata *m[num_blocks];
+#endif
                        for(unsigned i = 0; i < num_blocks; i++) {
                                // we can get away with this since we know the encoder will only correct the is_last flags
                                m[i] = const_cast< ::FLAC__StreamMetadata*>((::FLAC__StreamMetadata*)metadata[i]);
                        }
+#ifdef _MSC_VER
+                       // complete the hack
+                       const bool ok = (bool)::FLAC__seekable_stream_encoder_set_metadata(encoder_, m, num_blocks);
+                       delete [] m;
+                       return ok;
+#else
                        return (bool)::FLAC__seekable_stream_encoder_set_metadata(encoder_, m, num_blocks);
+#endif
                }
 
                SeekableStream::State SeekableStream::get_state() const
index 5aaa43e..5f59da7 100644 (file)
@@ -169,12 +169,26 @@ namespace FLAC {
                bool Stream::set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks)
                {
                        FLAC__ASSERT(is_valid());
+#ifdef _MSC_VER
+                       // MSVC++ can't handle:
+                       // ::FLAC__StreamMetadata *m[num_blocks];
+                       // so we do this ugly workaround
+                       ::FLAC__StreamMetadata **m = new ::FLAC__StreamMetadata*[num_blocks];
+#else
                        ::FLAC__StreamMetadata *m[num_blocks];
+#endif
                        for(unsigned i = 0; i < num_blocks; i++) {
                                // we can get away with this since we know the encoder will only correct the is_last flags
                                m[i] = const_cast< ::FLAC__StreamMetadata*>((::FLAC__StreamMetadata*)metadata[i]);
                        }
+#ifdef _MSC_VER
+                       // complete the hack
+                       const bool ok = (bool)::FLAC__stream_encoder_set_metadata(encoder_, m, num_blocks);
+                       delete [] m;
+                       return ok;
+#else
                        return (bool)::FLAC__stream_encoder_set_metadata(encoder_, m, num_blocks);
+#endif
                }
 
                Stream::State Stream::get_state() const