miva_struct_members()

 
This function retreives the member / field names of a data structure.
Syntax
miva_struct_members( struct var, members var )
Returns the number of member names found. Important: A member name will be returned even if its value is null.
  • struct = the structure or structured array that will be processed
  • members = The array populated with the members names found in structure
User Annotations: miva_struct_members
Chris Burdick : christopher d0t m d0t burdick at, gmail d0t com
11/18/2011 17:53 p.m.

Description of miva_struct_members()

miva_struct_members( aggregate var, members var ) will populate an array "members" with the members of structure "aggregate". It returns the number of members in the structure.
<MvCOMMENT>MivaScript</MvCOMMENT>

<MvCOMMENT>Set up test array with values</MvCOMMENT>
<MvASSIGN NAME = "l.testarray" INDEX = "1" MEMBER = "member_a" VALUE = "1">
<MvASSIGN NAME = "l.testarray" INDEX = "1" MEMBER = "member_b" VALUE = "2">
<MvASSIGN NAME = "l.testarray" INDEX = "1" MEMBER = "member_c" VALUE = "3">
<MvASSIGN NAME = "l.testarray" INDEX = "2" MEMBER = "member_a" VALUE = "1">
<MvASSIGN NAME = "l.testarray" INDEX = "2" MEMBER = "member_b" VALUE = "2">
<MvASSIGN NAME = "l.testarray" INDEX = "3" MEMBER = "member_a" VALUE = "1">
<MvASSIGN NAME = "l.testarray" INDEX = "3" MEMBER = "member_b" VALUE = "2">
<MvASSIGN NAME = "l.testarray" INDEX = "3" MEMBER = "member_c" VALUE = "3">
<MvASSIGN NAME = "l.testarray" INDEX = "3" MEMBER = "member_d" VALUE = "4">

<MvCOMMENT>Abuse of miva_struct_members()</MvCOMMENT>
<MvASSIGN NAME = "l.empty" VALUE = "{ miva_struct_members(l.testarray, l.empty_array) }">
<MvASSIGN NAME = "l.three" VALUE = "{ miva_struct_members(l.testarray[1], l.three_array) }">
<MvASSIGN NAME = "l.two" VALUE = "{ miva_struct_members(l.testarray[2], l.two_array) }">
<MvASSIGN NAME = "l.four" VALUE = "{ miva_struct_members(l.testarray[3], l.four_array) }">

<MvCOMMENT>Evals for output</MvCOMMENT>
<MvEVAL EXPR = "{ 'Array Member Count: ' $ l.empty $ ' | Serialized: ' $ miva_array_serialize(l.empty_array) $ '<br />
               Element 1 Member Count: ' $ l.three $ ' | Serialized: ' $ miva_array_serialize(l.three_array) $ '<br />
               Element 2 Member Count: ' $ l.two $ ' | Serialized: ' $ miva_array_serialize(l.two_array) $ '<br />
               Element 3 Member Count: ' $ l.four $ ' | Serialized: ' $ miva_array_serialize(l.four_array) }">

<!-- This will result in the following output -->
Array Member Count: 0 | Serialized: <br>
Element 1 Member Count: 3 | Serialized: [1]=MEMBER_A,[2]=MEMBER_B,[3]=MEMBER_C<br>
Element 2 Member Count: 2 | Serialized: [1]=MEMBER_A,[2]=MEMBER_B<br>
Element 3 Member Count: 4 | Serialized: [1]=MEMBER_A,[2]=MEMBER_B,[3]=MEMBER_C,[4]=MEMBER_D<br>