Jump to content


Photo
- - - - -

Comparing objects


  • Please log in to reply
12 replies to this topic

#1 drjdpowell

drjdpowell

    The 500 club

  • Premium Member
  • 723 posts
  • Location:Oxford, UK
  • Version:LabVIEW 2011
  • Since:1999

Posted 10 August 2011 - 07:33 PM

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

#2 Tim_S

Tim_S

    The 500 club

  • Members
  • PipPipPipPipPip
  • 577 posts
  • Location:Michigan
  • Version:LabVIEW 2012
  • Since:1994

Posted 10 August 2011 - 07:43 PM

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
Tim

"If this was easy our kids would be doing it." - Coworker

#3 drjdpowell

drjdpowell

    The 500 club

  • Premium Member
  • 723 posts
  • Location:Oxford, UK
  • Version:LabVIEW 2011
  • Since:1999

Posted 10 August 2011 - 07:50 PM

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

#4 Tim_S

Tim_S

    The 500 club

  • Members
  • PipPipPipPipPip
  • 577 posts
  • Location:Michigan
  • Version:LabVIEW 2012
  • Since:1994

Posted 10 August 2011 - 08:30 PM

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
Tim

"If this was easy our kids would be doing it." - Coworker

#5 drjdpowell

drjdpowell

    The 500 club

  • Premium Member
  • 723 posts
  • Location:Oxford, UK
  • Version:LabVIEW 2011
  • Since:1999

Posted 10 August 2011 - 09:14 PM

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:

Child Comparison.png

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

#6 drjdpowell

drjdpowell

    The 500 club

  • Premium Member
  • 723 posts
  • Location:Oxford, UK
  • Version:LabVIEW 2011
  • Since:1999

Posted 10 August 2011 - 10:02 PM

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




#7 kugr

kugr

    Very Active

  • Members
  • PipPipPip
  • 90 posts
  • Location:NJ
  • Version:LabVIEW 2012
  • Since:2009

Posted 10 August 2011 - 10:13 PM

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/top...me-at-run-time/

-Kurt

#8 drjdpowell

drjdpowell

    The 500 club

  • Premium Member
  • 723 posts
  • Location:Oxford, UK
  • Version:LabVIEW 2011
  • Since:1999

Posted 11 August 2011 - 08:40 AM

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 Posted Image

#9 Aristos Queue

Aristos Queue

    LV R&D: I write C++/# so you don't have to.

  • Members
  • PipPipPipPipPipPip
  • 2,758 posts
  • Location:Austin, TX
  • Version:LabVIEW 2011
  • Since:2000

Posted 28 August 2011 - 04:39 AM

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.

#10 drjdpowell

drjdpowell

    The 500 club

  • Premium Member
  • 723 posts
  • Location:Oxford, UK
  • Version:LabVIEW 2011
  • Since:1999

Posted 28 August 2011 - 03:32 PM

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

#11 Aristos Queue

Aristos Queue

    LV R&D: I write C++/# so you don't have to.

  • Members
  • PipPipPipPipPipPip
  • 2,758 posts
  • Location:Austin, TX
  • Version:LabVIEW 2011
  • Since:2000

Posted 28 August 2011 - 08:50 PM

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.

#12 drjdpowell

drjdpowell

    The 500 club

  • Premium Member
  • 723 posts
  • Location:Oxford, UK
  • Version:LabVIEW 2011
  • Since:1999

Posted 30 August 2011 - 09:04 AM

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 by drjdpowell, 30 August 2011 - 09:10 AM.


#13 drjdpowell

drjdpowell

    The 500 club

  • Premium Member
  • 723 posts
  • Location:Oxford, UK
  • Version:LabVIEW 2011
  • Since:1999

Posted 31 August 2011 - 09:41 PM

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