Jamoma API  0.6.0.a19
Data Types in Jamoma
Author
Jamoma, Timothy Place

We will begin our introduction of the Jamoma environment by looking at the basic data types. All other aspects of the environment, creating objects, writing extensions, etc., all require some knowledge about how data is represented.

Primitive Data Types

Numbers

To begin, Jamoma Foundation defines a variety of basic types for representing integers and a floating-point numbers with various degrees of resolution, and in signed or unsigned variants. The following table lists the basic numeric types according to their properties.

| | Unsigned Integer | Signed Integer | Floating-Point |
| 8-bit | #TTUInt8 | #TTInt8 | |
| 16-bit | #TTUInt16 | #TTInt16 | |
| 32-bit | #TTUInt32 | #TTInt32 | #TTFloat32 |
| 64-bit | #TTUInt64 | #TTInt64 | #TTFloat64 |

Booleans

In addition to these types for representing numbers, there are basic types for representing booleans (true/false values), TTBoolean.

Strings and Symbols

Strings can be represented in several different ways in Jamoma. Of course, arrays of the standard char type is a well understood way to work with text in C. The TTString type is similar to the C++ std::string and follows most of the conventions of the string provided by the C++ standard library. Unlike std::string, however, the characters of a TTString are guaranteed to be contiguous in memory and not subject to problems of ambiguous byte alignment.

In addition to TTString, there is also a TTSymbol type. A symbol is simply a wrapper around a string that is cached in a fast lookup table. While comparing TTString values is relatively slow, comparing TTSymbol values is extremely fast.

TTSymbol bearSymbol("bear");

The use of symbols is so ubiquitous in Jamoma that we have defined a macro, TT, to create a symbol from a C-string.

TTSymbol bearSymbol;
// ...
bearSymbol = TT("bear");

In fact, often the use of the TT macro is not even needed, as C-strings and TTStrings both can be promoted to symbols implicitly in many cases.

TTSymbol bearSymbol;
// ...
bearSymbol = "bear";
if (bearSymbol == "frog")
; // you have issues.

Composite Data Types

TTValue

While is important to have defined the basic data types for numbers, strings, and booleans, this is not the way that values are typically passed in Jamoma. Instead, values are passed using a special container type called TTValue. TTValue is a generic type that can hold any of the number, string, boolean, or a few other types that we use in Jamoma. In fact, it can even hold a mixed array of values made up of these various types. The following example shows several assignments using TTValue.

// Assigning numbers and symbols to TTValues
TTValue v = 3.1415;
TTValue s = TTSymbol("hog");
// Assigning TTValues to numbers
TTUInt16 i = v;
// Assigning an array to a TTValue
TTPtr aPointer = new int[10];
a.resize(4); // now has 4 elements
a[0] = 1;
a[1] = 22.0 / 7.0;
a[2] = TT("cow");
a[3] = aPointer;

TTObject

Another type that can be represented with a TTValue is the TTObject type. We’ll discuss more about that in coming sections.