drjdpowell Posted August 10, 2011 Report Share Posted August 10, 2011 I'm probably missing something obvious but I can't seem to do the following: Imagine I have a class tree with parent, children, grandchildren, etc. How do I take two objects in on parent wires and tell if one object is a child of the other? So for example, if Parent P has Children A and B, with grandchildren A1 and A2 of A, and B1 and B2 of B, I want a subVI (with two "P" inputs) that if comparing A and A1 returns "true", but if passed a B and A1 returns false. -- James Quote Link to comment
Tim_S Posted August 10, 2011 Report Share Posted August 10, 2011 Imagine I have a class tree with parent, children, grandchildren, etc. How do I take two objects in on parent wires and tell if one object is a child of the other? Have you tried using "To More Generic Class"? You should get an error if it's not a child. Tim Quote Link to comment
drjdpowell Posted August 10, 2011 Author Report Share Posted August 10, 2011 Have you tried using "To More Generic Class"? You should get an error if it's not a child. Doesn't work, because those functions use one of the inputs just for the wire type (which has to be the Parent), ignoring the specific child on the wire. -- James Quote Link to comment
Tim_S Posted August 10, 2011 Report Share Posted August 10, 2011 Doesn't work, because those functions use one of the inputs just for the wire type (which has to be the Parent), ignoring the specific child on the wire. I'm confused; why wouldn't it? If you have two To More Specific Class primitives where class A goes into the reference of the first and into the target of the second, and class B goes into the other inputs, then you should get an error on both only if there is no relation between the classes. Tim Quote Link to comment
drjdpowell Posted August 10, 2011 Author Report Share Posted August 10, 2011 I'm confused; why wouldn't it? If you have two To More Specific Class primitives where class A goes into the reference of the first and into the target of the second, and class B goes into the other inputs, then you should get an error on both only if there is no relation between the classes. It's because I don't know either child at runtime; I only have parent-type wires. The "To More Specific Class" function only uses the type of the wire, not the actual object on the wire at runtime. See below: I could do what I want if I could programmatically get a list of an objects ancestors; does anyone know how to do that? -- James Quote Link to comment
drjdpowell Posted August 10, 2011 Author Report Share Posted August 10, 2011 Found what I need: the "Preserve Run-Time Class" function. Unfortunately this isn't in the LabVIEW 8.6 that I'm mainly using. -- James Quote Link to comment
K-node Posted August 10, 2011 Report Share Posted August 10, 2011 I could do what I want if I could programmatically get a list of an objects ancestors; does anyone know how to do that? Check mike5's posts at the end of this thread. I am not sure it will work for you as it is a specific implementation. http://lavag.org/topic/12874-really-get-the-class-name-at-run-time/ -Kurt Quote Link to comment
drjdpowell Posted August 11, 2011 Author Report Share Posted August 11, 2011 Check mike5's posts at the end of this thread. I am not sure it will work for you as it is a specific implementation. http://lavag.org/top...me-at-run-time/ I need to get around to upgrading; I can't seem to do this in 8.6 either Quote Link to comment
Aristos Queue Posted August 28, 2011 Report Share Posted August 28, 2011 Imagine I have a class tree with parent, children, grandchildren, etc. How do I take two objects in on parent wires and tell if one object is a child of the other? This is actually something that you should pretty much never have to do. Although the Preserve Run-Time Class function will do what you're asking, the PRTC was put in so you could reasonably make *assertions* that two objects are the exact same class, not for runtime testing. What code are you writing where you need this type of functionality? It's a highly unusual request. Quote Link to comment
drjdpowell Posted August 28, 2011 Author Report Share Posted August 28, 2011 It's a highly unusual request. It is? What I have is an "Observer Registry" (mentioned in my "Parallel Process" topic) that deals with "Message" objects published by one process, to which other processes can register for. I would like the other processes to be able to specify what specific types of messages they would like to be notified of. For example, Process A may be interested in all "CommandMessages", a child class of Message, and any children of CommandMessage. This could be done by Process A passing a default CommandMessage object to the Observer Register, and then having the Register check every Message published to see if it is a child of CommandMessage. The Register would then be dealing with two children of Message (on Message-type wires) and needs to see if one is the child of the other. -- James Quote Link to comment
Aristos Queue Posted August 28, 2011 Report Share Posted August 28, 2011 It is? What I have is an "Observer Registry" (mentioned in my "Parallel Process" topic) that deals with "Message" objects published by one process, to which other processes can register for. I would like the other processes to be able to specify what specific types of messages they would like to be notified of. For example, Process A may be interested in all "CommandMessages", a child class of Message, and any children of CommandMessage. This could be done by Process A passing a default CommandMessage object to the Observer Register, and then having the Register check every Message published to see if it is a child of CommandMessage. The Register would then be dealing with two children of Message (on Message-type wires) and needs to see if one is the child of the other. Ok, when you put it that way, it sounds perfectly reasonable, but I have never needed that functionality in any other programming language, despite having written several systems of similar nature. I haven't needed it in LabVIEW either, but I haven't tried in LabVIEW to write the kind of dynamic registration system that you are attempting. I couldn't come up with a quick reason why I haven't needed it. I thought, "Well, maybe *I* haven't needed it, but it'll turn up in code by others," but in a brief search this morning I can't find any examples of typical programs that do this in other languages.Curiouser and curiouser, thought Alice. In any case, the Preserve Run-Time Class would (if you had a later LV version) do what you're looking for, and the only disadvantage I can see is that the other process has to register for a subtree of message types (as opposed to some more arbitrary filter mechanism). It will be faster than anything you can do involving Library refnums (most things are faster if you can do them without Library refnums). I can't really come up with a way to do this in LV 8.6 short of you adding a new method to your class hierarchy for "Is X a child of me?" and a second method for "get class name", which each class overrides correctly. Quote Link to comment
drjdpowell Posted August 30, 2011 Author Report Share Posted August 30, 2011 (edited) I can't really come up with a way to do this in LV 8.6 short of you adding a new method to your class hierarchy for "Is X a child of me?" and a second method for "get class name", which each class overrides correctly. I ended up leaving this feature on the to-do-list awaiting an upgrade, and just hard-wired in the ability to register for all children of "ErrorMessage", that being the only use case I need at the moment. I'm also considering adding the ability for the publishing process to organize groups of messages into "topics", with subscribing processes registering for topics of interest. This would obviate the need for registering message classes. Edited August 30, 2011 by drjdpowell Quote Link to comment
drjdpowell Posted August 31, 2011 Author Report Share Posted August 31, 2011 I thought, "Well, maybe *I* haven't needed it, but it'll turn up in code by others," but in a brief search this morning I can't find any examples of typical programs that do this in other languages. Actually, I just came across an example of exactly this use, in an "LVOOP Event Handler" by Francois Normandin: http://lavag.org/top...dpost__p__79074 (you can see "Preserve Run-Time Class" being used in the image) He uses it slightly differently, to allow the publisher to specify who can subscribe to an event, while I intend to use it to allow the subscriber to specify what events they are interested, but it's basically the same. -- James 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.