work around MSVC bug in set_metadata()

This commit is contained in:
Josh Coalson 2004-07-23 05:16:11 +00:00
parent 527bdda738
commit 990f741f54
3 changed files with 42 additions and 0 deletions

View 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)

View 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

View 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