02-28-2023 09:04 PM
I'm trying to write a "System Configuration"-type class, which ideally has an API something like:
If I use a string for the names, then this is fairly straightforward - the Config class has an array of PSU classes (which can dynamic-dispatch) and manages them as by-value objects (considered DVRs but prefer to just write "after adding to config, don't use the object anymore" in the info... hopefully I'll remember not to do that!), and then a map of PSU Array index, Ch index (from the map passed to Add PSU, which is String -> Int).
However, if I want to use a typedef'd enum, then my class needs to know the enum first. I don't have that information at build-time for the PPL (in practice, I probably could, but then I might as well not have the Config class, since I can't have a different config for a new experiment/setup/whatever).
Format Into String in a malleable VI would solve this (with some checking that the name isn't reused, by being passed two different enums at different call-sites, etc). But I can't see how to package that nicely with a PPL - I can put the VIM alongside, but now it needs to always be used next to the VI I actually want to call (I can't put it inside, because then I don't know what control type I need for the actual VI I care about (Set Voltage, for example)). In this case, the VIM only makes it a tiny bit smaller than using Format Into String, and I could just write a VI with a tiny icon to do that (in the calling application, specific to the/each enum, or VIM if multiple...) but I still end up placing twice as many VIs as I want in the calling application.
I thought perhaps I could replace the String label for channels with the numeric value of the enum, and then have it coerce, but Maps don't allow that. I can use an array of clusters of numerics - maybe this is an option, but then I can't use two different enums in any situation (I could use Rings with non-sequential values, but then coordinating their values for different "providers" becomes a potential bear-trap...). At this point, I've lost most of the safety too, but it is more condensed (and full of red dots 😞 )
What are the better solutions I didn't consider? (leaving aside "don't use a PPL"...)
Or, which would you choose? (Allowing "don't do anything like this at all, do this instead" 😛 )
Solved! Go to Solution.
03-01-2023 11:16 AM
If you make that input into a Variant, then pass in an enum you've never seen before, you can get the string value of the enum out of the Variant using the Variant Data Type Parsing Palette. I've done it like this:
Plus an alternate if a "String" or equivalent is passed in:
03-01-2023 07:52 PM