Jon Kokott Posted April 14, 2010 Report Share Posted April 14, 2010 Is there any way to read the class hierarchy at runtime in LVOOP? Given a class, I want to be able to know who its parent is and what decendents are valid for that class. Specifically I will be needing the paths of the .lvclass eventually so that I can dynamically instantiate the decendent/parent classes. ~Jon Quote Link to comment
Francois Normandin Posted April 14, 2010 Report Share Posted April 14, 2010 Hi Jon, You'll have to separate this in two approaches: ancestors and descendants. For ancestors, there is a private method for getting the ancestor class. Running it recursively will get you all the ancestors. You can cut the chase by installing this API. There are methods found in the installed palette for doing what you want. For descendants, the parent doesn't have any record if a class is its descendant. So you've got to typecast the potential child to its alleged parent class and see if it throws you an error. Quote Link to comment
Jon Kokott Posted April 14, 2010 Author Report Share Posted April 14, 2010 Hi Jon, You'll have to separate this in two approaches: ancestors and descendants. For ancestors, there is a private method for getting the ancestor class. Running it recursively will get you all the ancestors. You can cut the chase by installing this API. There are methods found in the installed palette for doing what you want. For descendants, the parent doesn't have any record if a class is its descendant. So you've got to typecast the potential child to its alleged parent class and see if it throws you an error. I've run the toolkit, but it does not appear to retrieve descendent or child classes. The List_Ancestor_class.vi only lists the ancestors of my target class, and the original class I gave as a target. Here is the code: Quote Link to comment
Francois Normandin Posted April 14, 2010 Report Share Posted April 14, 2010 The List_Ancestor_class.vi only lists the ancestors of my target class, and the original class I gave as a target. Yes, this is expected behavior. Ancestors cannot be children of your intial class. If C is child of B, and B is child of A, then: 1- Wiring A.lvclass as input will give {A.lvclass} (self -> no ancestor class except LabVIEW Object) 2- Wiring B.lvclass as input will give {B.lvclass ; A.lvclass} (self + parent "A") 3- Wiring C.lvclass as input will give {C.lvclass; B.lvclass ; A.lvclass} (self + parent "B" + parent of B ) etc. To find Child classes, you can't ask the parent class "Who are your children?". You need to list the directory where your classes reside at runtime and typecast to see if they match the class type of the parent. Quote Link to comment
Aristos Queue Posted April 14, 2010 Report Share Posted April 14, 2010 There is no way to accomplish what you are requesting. A parent class is saved without any knowledge of its children. There may be infinite children on your disk, out on the network, anywhere. Some subset of those children may currently be in memory. Those are the only children that a parent knows about, and since those are already loaded, they're of no help to you. A class does know who its parent is. When the class loads into memory, it automatically loads its parent class, so you don't have to dynamically load that. Once in memory, a class can be asked for a list of all its children *in the editor environment*. You cannot do this in the runtime engine. Quote Link to comment
Jon Kokott Posted April 14, 2010 Author Report Share Posted April 14, 2010 There is no way to accomplish what you are requesting. A parent class is saved without any knowledge of its children. There may be infinite children on your disk, out on the network, anywhere. Some subset of those children may currently be in memory. Those are the only children that a parent knows about, and since those are already loaded, they're of no help to you. A class does know who its parent is. When the class loads into memory, it automatically loads its parent class, so you don't have to dynamically load that. Once in memory, a class can be asked for a list of all its children *in the editor environment*. You cannot do this in the runtime engine. Ok, perhaps a work around of registering all the classes and their hierarchy in an initialization step (from .ini file?) will do the trick then. At any rate, it sounds like I MUST load the parent of a particular target class before loading that target or labview will spit out errors. ~Jon Quote Link to comment
crelf Posted April 14, 2010 Report Share Posted April 14, 2010 A parent class is saved without any knowledge of its children. As it should - parents should never be child aware, children should always be parent aware. Hey Jon: can you give us an idea of your application? Maybe we can help with a work around if we know a little more about what you're trying to do. Quote Link to comment
Jon Kokott Posted April 16, 2010 Author Report Share Posted April 16, 2010 As it should - parents should never be child aware, children should always be parent aware. Hey Jon: can you give us an idea of your application? Maybe we can help with a work around if we know a little more about what you're trying to do. Basically what I'm trying to do is add classes later but allow them to be user selectable without actually adding any new code. Something like a tree control where the decendents can be viewed dynamically depending on hardware/software configurations on a given system. This is in the context of a factory pattern and plugin architexture. I'll try to work this out by registering new classes in a .ini file so that the main can scan who is actually out there and what is available for runtime purposes. we'll see how this goes, I'm getting a little experimental now... ~Jon Quote Link to comment
Aristos Queue Posted April 16, 2010 Report Share Posted April 16, 2010 At any rate, it sounds like I MUST load the parent of a particular target class before loading that target or labview will spit out errors. No. A child will load its parent automatically as part of its own load into memory.This is in the context of a factory pattern and plugin architexture. OH. In that case... you want these:http://decibel.ni.com/content/docs/DOC-2875 <<< search for "Factory Pattern" for an implementation of exactly what you're trying to do. This is a very CS oriented write up of the pattern and its implementation in LabVIEW. http://zone.ni.com/wv/app/doc/p/id/wv-1295 <<< Even more detailed online presentation about the Factory pattern, how it works and why it works and variations that may be of interest to you. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.