.. _ogn_tutorial_extended_types:

Tutorial 19 - Extended Attribute Types
======================================

Extended attribute types are so-named because they extend the types of data an attribute can accept from one type
to several types. Extended attributes come in two flavours. The _any_ type is the most flexible. It allows a connection
with any other attribute type:

.. code-block:: json
    :emphasize-lines: 4

    "inputs": {
        "myAnyAttribute": {
            "description": "Accepts an incoming connection from any type of attribute",
            "type": "any",
        }
    }

The union type, represented as an array of type names, allows a connection from a limited subset of attribute types.
Here's one that can connect to attributes of type _float[3]_ and _double[3]_:

.. code-block:: json
    :emphasize-lines: 4

    "inputs": {
        "myUnionAttribute": {
            "description": "Accepts an incoming connection from attributes with a vector of a 3-tuple of numbers",
            "type": ["float[3]", "double[3]"],
        }
    }

.. note::

    "union" is not an actual type name, as the type names are specified by a list. It is just the nomenclature used
    for the set of all attributes that can be specified in this way. More details about union types can be
    found in :ref:`ogn_attribute_types`.


As you will see in the code examples, the value extracted from the database for such attributes has to be checked for
the actual resolved data type. Until an extended attribute is connected its data type will be unresolved and it will
not have a value. For this reason _"default"_ values are not allowed on extended attributes.

OgnTutorialExtendedTypes.ogn
----------------------------
The *ogn* file shows the implementation of a node named "omni.graph.tutorials.ExtendedTypes", which has inputs and outputs
with the extended attribute types.

.. literalinclude:: ../../../../../source/extensions/omni.graph.tutorials/tutorials/tutorial19/OgnTutorialExtendedTypes.ogn
    :linenos:
    :language: json

OgnTutorialExtendedTypes.cpp
----------------------------
The *cpp* file contains the implementation of the compute method. It illustrates how to determine and set the data
types on extended attribute types.

.. literalinclude:: ../../../../../source/extensions/omni.graph.tutorials/tutorials/tutorial19/OgnTutorialExtendedTypes.cpp
    :linenos:
    :language: c++

Information on the raw types extracted from the extended type values can be seen in :ref:`ogn_tutorial_bundle_data`.

OgnTutorialExtendedTypesPy.py
-----------------------------
This is a Python version of the above C++ node with exactly the same set of attributes and the same algorithm. It
shows the parallels between manipulating extended attribute types in both languages. (The .ogn file is omitted for
brevity, being identical to the previous one save for the addition of a ``"language": "python"`` property.

.. literalinclude:: ../../../../../source/extensions/omni.graph.tutorials/tutorials/tutorial19/OgnTutorialExtendedTypesPy.py
    :linenos:
    :language: python
