04-21-2015 10:02 AM
Does LabVIEW natively support finding out (programmatically) about a child class if it overrides a certain member VI of the parent class?
One workaround for dynamic dispatched VIs would be to print some information about the class (VI needs to be instrumented) and "dry-run" the VI to find out who the callee is. Other ideas?
Thanks,
Peter
04-21-2015 12:45 PM
I'm not sure exactly what you mean.
Are you asking if you can find the most specific class that is on a wire?
Are you asking if you can query programmatically whether or not an override VI exists at a given child level for a dynamic dispatch VI?
I'm also not sure what your end goal is.
04-22-2015 12:16 AM
04-22-2015 01:50 AM
@Bokor wrote:
Does LabVIEW natively support finding out (programmatically) about a child class if it overrides a certain member VI of the parent class?
One workaround for dynamic dispatched VIs would be to print some information about the class (VI needs to be instrumented) and "dry-run" the VI to find out who the callee is. Other ideas?
Thanks,
Peter
Edit-time or run-time?
04-22-2015 06:27 AM
I attach an example (LV '14):
Classes Child1 and Child2 both inherit from Parent but only Child1 overrides Parent's foo().
Requirement: given a Parent instance (which can be Parent, Child1, or Child2) , find out runtime if foo() is overriden by the instance.
The attached project includes my workaround (see demonstration in main()).
Is there another, more elegant way to solve it?
Note: it's not about finding out the exact class of the instance, which can be done by checking if downcast throws an error.
Thanks,
Peter
04-28-2015 03:09 AM
LV support pointed me to another solution via the invoke node "LabVIEW Class:Get Implementing VI Path Method".
I implemented this solution along my workaround into the project below.
Pro of my workaround: independent of where VI is stored in the file system.
Con of my workaround: the VI needs to be executed.
Pro of solution with invoke node: VI needs not be executed.
Con of solution with invoke node: depends on where VI is stored in the file system.
Peter
04-28-2015 03:33 AM
I have a feeling there's something very wrong with your implementation if you need to be finding out this kind of thing at run-time. At edit-time there are VI Server calls which can do this (although I've never atually tried this exact thing).
Why do you need this information?
04-28-2015 09:34 AM
I need it because LabVIEW doesn't support multiple inheritance nor interfaces.
Say class ChildA inherits from A; another class ChildAB inherits from A and B. In LabVIEW you have to add, as a workaround, an AdapterB class that inherits from B and that calls the member methods of ChildAB.
Now, given a class Child, how do you know if Class is an "A" or an "A and B"? Note that "instance of" doesn't work because Child cannot inherit from both A and B.
My workaround was that A abstractly implements B's methods and if Child overrides one of these methods then it must inherit from B.
Peter
04-28-2015 10:20 AM
I have trouble following your description of the problem.
A and B have different hierarchies (are unrelated to another except for the base class LVObject)? Why do you want to inherit from two base classes? What functionality are you trying to achieve exactly? Can't composition do the work for you? The object itself should already have all the information it requires to implement what you need, you should never to go around snooping like this to implement what you want.
04-29-2015 05:24 AM
Well, one can argue pro and contra multiple inheritance. In my opinion, if one accepts the legitimacy of inheritance, then multiple inheritance is just a generalization of the same idea.
Finding out the exact class of an object is reflection (or meta programming). Again, one can argue pro and contra against reflection. I use reflection as a form of static analysis to find out certain details about the implementation of a class.