To answer my own question
for typ in instances(MetadataType) ... end
On Friday, July 31, 2015 at 9:41:13 AM UTC-5, Douglas Bates wrote:
>
> In a FLAC (as in Free Lossless Audio Codec) package for version 0.4 I used
> @enum to create a type to pass to calls to the C library libflac.
>
> """
> Metadata for a flac stream object.
>
> Used in both encoding and decoding of a stream.
> Each type of metadata object contains an indicator
> of its `typ`, an indicator of whether this is the
> last metadata block and its length, in bytes.
> """
> abstract StreamMetaData
>
> @enum(MetadataType,
> InfoType=UInt32(0),
> PaddingType,
> ApplicationType,
> SeektableType,
> VorbisCommentType,
> CueSheetType,
> PictureType)
>
> Some of the constructors are boilerplate, differing only in the
> MetadataType. Can I iterate over these values and create all the
> constructors in a macro call? Alternatively, if I iterate over the range
> 0:6, can I convert the integer to a MetadataType?
>
> The boilerplate looks like
>
> """
> A block containing information on the stream including
> `samplerate`, `channels`, `bitspersample`, `totalsamples`,
> and `mdsum`.
> """
> type StreamInfoMetaData <: StreamMetaData
> typ::MetadataType
> is_last::Cint
> len::Int64
> minblocksize::Int32
> maxblocksize::Int32
> minframesize::Int32
> maxframesize::Int32
> samplerate::Int32
> channels::Int32
> bitspersample::Int32
> totalsamples::Int64
> md5sum::NTuple{16,UInt8}
> end
>
> """
> The zero-argument constructor uses storage allocated by libflac.
> """
> function StreamInfoMetaData()
> md = unsafe_load(ccall((:FLAC__metadata_object_new,libflac),
>
> Ptr{StreamInfoMetaData},(MetadataType,),InfoType))
> finalizer(md,x->ccall((:FLAC__metadata_object_delete,libflac),
> Void,(Ptr{StreamInfoMetaData},),pointer(x)))
> md
> end
>
>
>