LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
drjdpowell

Convert an Array of Variants into a Cluster

Status: New

It is common, in writing reusable code, to handle arbitrary clusters in variants.  To access the elements of the cluster, one wants to convert the cluster into an array of variants containing the individual items.  After access, one needs to convert the array of variants back into the original cluster.

 

There are several examples of packages that use this on NI.com and in the LAVAg.org Code Repository.  They mostly use functions for working with Variant Clusters from OpenG; however, these can be quite slow.   Recent LabVIEW versions have had the ability to do much of the functions quicker, however, there is a very imortant missing native ability: to convert an Array of Variants into a Variant Cluster.

 

The other direction, Cluster to Array of Variants, works like this:

Array of Variants to Cluster.png

But trying to reverse the process breaks:

Array of Variants to Cluster.png

 

So my idea is make the second image work; make an Array of Variants interchangable with a Variant Cluster in the "Variant to Data" LabVIEW primative. The interchangability should apply to contained subclusters/arrays also.  The matching of array to cluster elements can be by cluster order rather than element name.

 

This would greatly aid the performance of reuasable packages that operate on arbitrary clusters.

22 Comments
AristosQueue (NI)
NI Employee (retired)

"This is especially hard for classes, as the flattened data is empty for default values."

 

Say what? No it isn't empty. Not ever.

LabVIEW Object flattens as a list of 4 NULL characters.

For all other classes, the flattened data of an object, even its default value, always includes at least the name of the class. Without that, how could we ever know whether the unflatten is legal? An empty string would change types!

 

AristosQueue_0-1593093069339.png

 

AristosQueue_1-1593093198297.png

 

 

wiebe@CARYA
Knight of NI

The string is not empty, but the list of values in the string is empty. Sorry, I though that was clear from the context.