Struct

HC Data Structure Primitives Constructors Struct
Table toList

Struct typelist


outputs a new Struct, the members are filled with typelist. typelist is a list of lists, which contain a field name, a field type and optionally a field item. The field type may be any of Int, Int16, Int8, UInt8, Word, IntArray, Int16Array, FloatArray. The types Word, IntArray, Int16Array and FloatArray require a third list item, the size. Having Word, size is the number of characters of the Word. You can change members by using setItem or the "t's=x" operator.

Structs are, like Tables, very fast for word lookup, much faster than searching in a big list or plist (constant time).

Example:

wavHeaderType=(list
	[ChunkID Word RIFF]
	[wavfilesize Int]
	[RIFFtype Word 4]	;the last item is the string length
	
	[formatChunkID Word fmt\ ]
	[formatChunkSize Int 16]
	[compressionCode Int16 1]
	[NumberOfChannels Int16 1]
	(list "SampleRate "Int rate)
	(list "BytesPerSecond "Int rate*2)
	[BlockAlign Int16 2]
	[BitsPerSample Int16 16]
	
	[DataChunkID word data]
	(list "DataChunkSize "Int size*2)
)
wavHeader=struct wavHeaderType
wavsize=(SizeOf wavHeader)+size*2
wavHeader'RIFFtype=[WAVE]	;example for setting a string
wavHeader'wavfilesize=wavsize
pr wavHeader

Examples:

References:

Table toList