Difference between revisions of "IC Python API:RLPy RVariant"

From Reallusion Wiki!
Jump to: navigation, search
(Created page with "{{TOC}} {{Parent|IC_Python_API:RL_Python_Modules|Modules}} == Detailed Description == The class acts like a union for the most common data types. A RVariant object holds a sin...")
 
m
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
== Detailed Description ==
+
{{last_modified}}
The class acts like a union for the most common data types.
+
A RVariant
+
object holds a single value of a single type() at a time. You can find
+
out what type the variant holds, get its value using one of the toT()
+
functions (e.g., ToInt32()). <syntaxhighlight lang="Python">
+
x = RLPy.RVariant(-10)
+
print(x.GetType() == RLPy.RVariant.Int32) #true
+
  
f = x.ToFloat()
+
== Description ==
print(f) #-10.0
+
  
y = RLPy.RVariant(10.0)
+
This class acts like an union for common data types. A RVariant object holds a single value of a specified type T at a time. You can use GetType() to find out what type the variant holds, and get its value by one of the ToT() functions (e.g., ToInt32()). Currently, there are two types supported: float and int.
print(y.GetType() == RLPy.RVariant.Float) #true
+
  
 +
<syntaxhighlight lang="Python">
 +
x = RLPy.RVariant(-10)
 +
print(x.GetType() == RLPy.RVariant.Int32)          #true
 +
 +
f = x.ToFloat()
 +
print(f)                                            #-10.0
 +
 +
y = RLPy.RVariant(10.0)
 +
print(y.GetType() == RLPy.RVariant.Float)          #true
 +
 
n = x.ToInt32()
 
n = x.ToInt32()
print(n) #10
+
print(n)  
 
</syntaxhighlight>
 
</syntaxhighlight>
==Constructor & Destructors==
 
===__init__===
 
<syntaxhighlight lang="Python">
 
RLPy.RVariant.__init__ ( self, args )
 
</syntaxhighlight>
 
Constructor, Initialize a new RVariant object with a RVariant data.
 
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''fValue''' [IN] a float data - float
+
== Member Functions ==
</div>
+
 
==Member Functions==
+
=== GetType ( self ) ===
===GetType===
+
 
 +
Get type of a RVariant object.
 +
 
 +
==== Returns ====
 +
:Type of a RVariant object - int
 +
:RLPy.RVariant.Float, RLPy.RVariant.Int32, or RLPy.RVariantUInt32
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RVariant.GetType ( self )
+
x = RLPy.RVariant(-10)
</syntaxhighlight>
+
print(x.GetType() == RLPy.RVariant.Int32)           #true
Get the type of this RVariant object.
+
====Returns====
+
<div style="margin-left: 2em;">The type of a RVariant object - RLPy.Type
+
</div>
+
-----
+
===ToFloat===
+
<syntaxhighlight lang="Python">
+
RLPy.RVariant.ToFloat ( self, pSucess = None )
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== ToFloat ( self, pSucess = None ) ===
 +
 
Convert to float.
 
Convert to float.
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''pSucess''' [IN] success or not - bool
+
See Also: [[#ToInt32 ( self, pSucess = None )|ToInt32 ( self, pSucess = None )]], [[#ToUInt32( self, pSucess = None )|ToUInt32( self, pSucess = None )]]
</div>
+
 
====Returns====
+
==== Parameters ====
<div style="margin-left: 2em;">The float value after conversion - float
+
:pSucess [IN] success or not - bool
</div>
+
 
-----
+
==== Returns ====
===ToInt32===
+
:Value after conversion - float
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RVariant.ToInt32 ( self, pSucess = None )
+
x = RLPy.RVariant(-10)
 +
f = x.ToFloat()
 +
print(f)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== ToInt32 ( self, pSucess = None ) ===
 +
 
Convert to int32_t.
 
Convert to int32_t.
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''pSucess''' [IN] success or not - bool
+
See Also: [[#ToFloat ( self, pSucess = None )|ToFloat ( self, pSucess = None )]], [[#ToUInt32( self, pSucess = None )|ToUInt32( self, pSucess = None )]]
</div>
+
 
====Returns====
+
==== Parameters ====
<div style="margin-left: 2em;">The int32_t value after conversion - int
+
:pSucess [IN] success or not - bool
</div>
+
 
-----
+
==== Returns ====
===ToUInt32===
+
:Signed integer value after conversion - int32
 +
 
 
<syntaxhighlight lang="Python">
 
<syntaxhighlight lang="Python">
RLPy.RVariant.ToUInt32 ( self, pSucess = None )
+
f = RLPy.RVariant(-10.0)
 +
x = f.ToInt32()
 +
print(x)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== ToUInt32( self, pSucess = None ) ===
 +
 
Convert to uint32_t.
 
Convert to uint32_t.
====Parameters====
 
<div style="margin-left: 2em;">
 
  
'''pSucess''' [IN] success or not - bool
+
See Also: [[#ToFloat ( self, pSucess = None )|ToFloat ( self, pSucess = None )]], [[#ToInt32 ( self, pSucess = None )|ToInt32 ( self, pSucess = None )]]
</div>
+
 
====Returns====
+
==== Parameters ====
<div style="margin-left: 2em;">The uint32_t value after conversion - int
+
:pSucess [IN] success or not - bool
</div>
+
 
 +
==== Returns ====
 +
:Unsigned integer value after conversion - uint32
 +
 
 +
<syntaxhighlight lang="Python">
 +
f = RLPy.RVariant(10.0)
 +
x = f.ToUInt32()
 +
print(x)
 +
</syntaxhighlight>

Revision as of 23:34, 22 March 2020

Main article: Modules.
Last modified: 03/22/2020

Description

This class acts like an union for common data types. A RVariant object holds a single value of a specified type T at a time. You can use GetType() to find out what type the variant holds, and get its value by one of the ToT() functions (e.g., ToInt32()). Currently, there are two types supported: float and int.

x = RLPy.RVariant(-10)
print(x.GetType() == RLPy.RVariant.Int32)           #true
 
f = x.ToFloat()
print(f)                                            #-10.0
 
y = RLPy.RVariant(10.0)
print(y.GetType() == RLPy.RVariant.Float)           #true
 
n = x.ToInt32()
print(n)

Member Functions

GetType ( self )

Get type of a RVariant object.

Returns

Type of a RVariant object - int
RLPy.RVariant.Float, RLPy.RVariant.Int32, or RLPy.RVariantUInt32
x = RLPy.RVariant(-10)
print(x.GetType() == RLPy.RVariant.Int32)           #true

ToFloat ( self, pSucess = None )

Convert to float.

See Also: ToInt32 ( self, pSucess = None ), ToUInt32( self, pSucess = None )

Parameters

pSucess [IN] success or not - bool

Returns

Value after conversion - float
x = RLPy.RVariant(-10) 
f = x.ToFloat()
print(f)

ToInt32 ( self, pSucess = None )

Convert to int32_t.

See Also: ToFloat ( self, pSucess = None ), ToUInt32( self, pSucess = None )

Parameters

pSucess [IN] success or not - bool

Returns

Signed integer value after conversion - int32
f = RLPy.RVariant(-10.0) 
x = f.ToInt32()
print(x)

ToUInt32( self, pSucess = None )

Convert to uint32_t.

See Also: ToFloat ( self, pSucess = None ), ToInt32 ( self, pSucess = None )

Parameters

pSucess [IN] success or not - bool

Returns

Unsigned integer value after conversion - uint32
f = RLPy.RVariant(10.0) 
x = f.ToUInt32()
print(x)