BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

LVOOP

Does a 'class' in LVOOP mean the same thing as defining a 'class' in other text based languages, such as Python?
Can you define functions and operators for the class as well?

I have never seen LVOOP code (that I am aware of) and was just curious.

Any recommendations on somewhere to learn the basics?

Cory K
0 Kudos
Message 1 of 20
(11,114 Views)

Just using their example, an array that is always sorted:

You define a certain type of array, such that every time an element is added, it is placed in its correct index in the array.

This seems relatively straight forward, but how about classes where you must define operators?

For example, look at the operator '+'

 

LabVIEW knows that

1 + 1 = 2

 or

an array of values + another array = sum of respective indexes

 

 

But say you wanted to make a class called 'Words' (essestially strings, but use this as an example)

How would you define the operator + to be used as a concatenator.

word1 + word2 = word1word2

 

Or define new operators, for example $ (which for this case would alternate letters)

word1 $ text2 = wtoerxdt12

 

Is this possible?

Message Edited by Cory K on 06-19-2009 01:02 PM
Cory K
0 Kudos
Message 3 of 20
(11,105 Views)

I think this really belongs in the LabVIEW forum...

 

... but, as far as your question is concerned: you can't overload operators in LabVIEW. You would need to make a method (or methods, depending on how many variations of datatypes between the left and right side of the operation you wanted to handle) for the class that performs that operation. It would be no different than if you were to do it in Java, which I believe does not allow overloading of operators. 

0 Kudos
Message 4 of 20
(11,077 Views)

Yeh, I wasnt really sure if I should post an LVOOP question in the LabVIEW forums.

I am not actually using OOP in my LabVIEW code, I was just curious how it is implemented.

I like to learn new stuff, even if I dont necessarily need it.... which is the rationale all my math professors above calc 4 used Smiley Very Happy

Cory K
0 Kudos
Message 5 of 20
(11,064 Views)

Cory K wrote:

Just using their example, an array that is always sorted:

You define a certain type of array, such that every time an element is added, it is placed in its correct index in the array.

This seems relatively straight forward, but how about classes where you must define operators?

For example, look at the operator '+'

 

LabVIEW knows that

1 + 1 = 2

 or

an array of values + another array = sum of respective indexes

 

 

But say you wanted to make a class called 'Words' (essestially strings, but use this as an example)

How would you define the operator + to be used as a concatenator.

word1 + word2 = word1word2

 

Or define new operators, for example $ (which for this case would alternate letters)

word1 $ text2 = wtoerxdt12

 

Is this possible?

Message Edited by Cory K on 06-19-2009 01:02 PM

I believe yes.

 

LVOOP is built around LV clusters. They are special clusters that have some unique features.

 

1) They don't have to have any data in them.

2) They are all children of a generic LV cluster.

 

LVOOP will generate VI to put things into the clusters and get them out. They are called accessors.

 

LVOOP has dynamic dispatching. This sorta works like polymorphic VIs but instead of the version of polymorhpic VI being determined at compile time it is performed at run time (stop and ponder that trick for a minute).

 

Dynamic dispatching decides which Class is being used and uses the VI from that class when it is time to execute the VI.

 

You establish which VI gets called by how you define you class inheritance.

 

The VI that get called implement the methods as appropriate for tht class. This is called an over-ride VI.

 

Methods in a class can call other methods of that class or it paraents. It can even call itself if you think re-cursiveness is the right approach.

 

SO to implement you Q above I would set up the class hiarchy such that after you have set the values "A" and "B" then invoke the method "Add" adn when using the numbers they would add and if string then they would concantenate.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 20
(11,023 Views)
Thanks Ben.
I'm gonna read through your post a couple hundred times and see if I can digest all that Smiley Very Happy
Cory K
0 Kudos
Message 7 of 20
(11,013 Views)

Ben wrote:

 

You establish which VI gets called by how you define you class inheritance.

 

The VI that get called implement the methods as appropriate for tht class. This is called an over-ride VI.

 

Methods in a class can call other methods of that class or it paraents. It can even call itself if you think re-cursiveness is the right approach.

 

SO to implement you Q above I would set up the class hiarchy such that after you have set the values "A" and "B" then invoke the method "Add" adn when using the numbers they would add and if string then they would concantenate.

 

Ben


This is the part I cant wrap my head around. So any user defined class's parent, at the highest level, is clusters?
So need to define both the class, and methods to operate on any object in that class?

Cory K
0 Kudos
Message 8 of 20
(10,991 Views)

Hi Cory,

 

I threw this together fro you this AM. THe index control determins if it si add or concantentate.

 

I don't have time to do screen shots but try single stepping into the add using the two versions and you will see dynamic dispatch in action.

 

If this helps please post some sreen shots to help out others.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 9 of 20
(10,978 Views)

Notes:

 

If i had editied the icons to name the values the code would read cleaner.

 

The index control of teh index array will select either Numeric class or sting class. once selected teh class selected will invoke the method that is appropriate for that class.

 

Play with the properties of the class to adjut the mask ued for the class icons and wire appearence.

 

Ask whatever Qs come up. WE can turn this thread into a intro to LVOOP for LV types, ... well maybe.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 10 of 20
(10,967 Views)