11-04-2021 08:18 AM
I have a wire of type "Class P". I have defined "Class C" to be a child of "Class P".
I want to take the "Class P" data from the wire and push it into an instance of "Class C".
Is that possible?
11-04-2021 01:26 PM - edited 11-04-2021 01:28 PM
You could always define a parent protected method to retrieve the parent private fields, since by definition that can only be called by child classes. Then a child class method can call that internally to retrieve the parent data (ie from its own cluster). Protected scope rather than public ensures that you cant unintentionally leak the parent data outside the hierarchy.
But your question makes me wonder what you are trying to achieve. Child classes by definition carry around parent data that can be operated on using parent public or protected methods.
11-04-2021 06:03 PM
@tyk007 wrote:
You could always define a parent protected method to ..
Well, no, not always. In fact, in this case, I can't make any changes to the parent class.
11-04-2021 06:54 PM
So you're looking for a way to bypass encapsulation?
There is a crude way to extract the class data from the object cluster, using VI Server if I recall. I wouldn't call it maintainable though.
11-05-2021 03:01 AM
Can your instance be of "Class C" instead of "Class P" to begin with? That would be the simplest solution that i can think of. The other thought that comes to mind is, is "Class C" really a child of "Class P", or should there be some other relationship?
11-05-2021 11:22 AM - edited 11-05-2021 11:23 AM
If you flatten a class to XML using the LabVIEW node, the way it packs data from the different inheritance levels of the classes is not too difficult to parse. It wouldn't be that hard to use the "Flatten to XML" node on a parent class and reformat it into a child class while maintaining the parent class's data, then unflatten it into an instance of the child class containing all of the data from the parent.
Note that if you try flattening the class data to look at it for an example, you will want to first set at least one variable to not be the class default value. If the value on the wire is the class default for everything, it just leaves out most of the XML to save space.