uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
Introduction
Product:
Class:
An overview of the DataType class, which provides metadata and functionality for specific data types within the uCalc engine.
Remarks
⚙️ The DataType Class: Runtime Type Introspection
The DataType class is a first-class object that represents the metadata and behavior of a specific data type within the uCalc engine. It's more than just a simple type identifier; it's an interactive object that holds information about a type's name, size in memory, and associated conversion and formatting logic.
This class is the foundation of uCalc's dynamic type system, providing the tools for runtime introspection, type safety, and the creation of custom data types.
Core Concepts
Runtime Introspection: Unlike compile-time type systems (like C#'s
typeofor C++'stypeid), uCalc'sDataTypeobjects can be retrieved and inspected at runtime using string names or enums via the uCalc.DataTypeOf method. This allows your application to make dynamic decisions based on the types of variables or expression results.Instance-Specific Behavior: Every uCalc instance maintains its own registry of
DataTypeobjects. This powerful feature allows you to customize the behavior of a type (e.g., its string representation) in one parser instance without affecting any others.Custom Types: While uCalc comes with a rich set of built-in types, you can define new data types or create aliases for existing ones at runtime using the DataType Constructor. This is essential for building expressive Domain-Specific Languages (DSLs).
Boolean properties
The numeric value for a Boolean when True, and the string to return for True and False can be changed using Define("Boolean:").
For instance, if you want the numeric representation of a Boolean to to be -1, and for it to return Yes and No for true and false when converted to a string, you can do:
uc.Define("Boolean: -1, Yes, No");If you want the numeric representation of a Boolean to to be 1, and for it to return Correct and Incorrect for true and false when converted to a string, you can do:
uc.Define("Boolean: 1, Correct, Incorrect");The numeric value for a Boolean when false is always 0.
📖 Class Members
The following properties and methods are available on a DataType object.
| Member | Description |
|---|---|
| Constructor | Creates a new data type definition within a uCalc instance or an empty placeholder. |
| BuiltInTypeEnum | Retrieves the BuiltInType enumeration member that uniquely identifies a built-in data type. |
| ByteSize | Gets the size, in bytes, that a single value of this data type occupies in memory. |
| Description | Gets or sets a user-defined text description for a DataType object. |
| Handle | Returns the internal, low-level handle of the DataType object. |
| IsCompound | Determines if the data type represents a compound value, such as a String or Complex number. |
| IsDefault | Gets or sets whether this data type is the engine's default for implicit typing. |
| Item | Retrieves the underlying Item object that represents this data type. |
| MemoryIndex | Returns the unique, stable index value that identifies the data type object. |
| Name | Retrieves the canonical string name of the data type. |
| Release | Unregisters a custom data type and releases its associated resources. |
| Reset | Resets a scalar variable to the default value for its data type. |
| SetScalar | Performs a low-level copy of a scalar value from a source memory address to a destination address. |
| SwapScalarValues | Efficiently swaps the values of two uCalc variables of the same underlying data type. |
| ToString | Converts a value to its string representation, either from a memory address or by parsing a string. |
| uCalc | Retrieves the parent uCalc instance that owns and manages this data type definition. |
Examples
Getting data type object with DataTypeOf
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1"));
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name);
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize);
255
65535
true
-1
int8u
4 using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1")); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name); Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.DataTypeOf(BuiltInType::Integer_8u).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_16u).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::Boolean).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::String).ToString("-1") << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_8u).Name() << endl;
cout << uc.DataTypeOf(BuiltInType::Integer_32).ByteSize() << endl;
}
255
65535
true
-1
int8u
4 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.DataTypeOf(BuiltInType::Integer_8u).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::Integer_16u).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::Boolean).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::String).ToString("-1") << endl; cout << uc.DataTypeOf(BuiltInType::Integer_8u).Name() << endl; cout << uc.DataTypeOf(BuiltInType::Integer_32).ByteSize() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1"))
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name)
Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize)
End Sub
End Module
255
65535
true
-1
int8u
4 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_16u).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.Boolean).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.String).ToString("-1")) Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_8u).Name) Console.WriteLine(uc.DataTypeOf(BuiltInType.Integer_32).ByteSize) End Sub End Module
Returning the data type of an expression
using uCalcSoftware;
var uc = new uCalc();
Console.WriteLine(uc.DataTypeOf("10 + 20 - 3").Name);
Console.WriteLine(uc.DataTypeOf(" 'What type ' + 'is this?' ").Name);
Console.WriteLine(uc.DataTypeOf("3 < 10").Name);
Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name);
Console.WriteLine("---");
uc.DefineFunction("func(x) as string = 'Hello' * 3");
Console.WriteLine(uc.DataTypeOf("func").Name);
Console.WriteLine(uc.DataTypeOf("Int").Name);
Console.WriteLine(uc.DataTypeOf("NonExistantType").Name); // Empty string
Console.WriteLine(uc.DataTypeOf("&&").Name);
double
string
bool
complex
---
string
int
bool using uCalcSoftware; var uc = new uCalc(); Console.WriteLine(uc.DataTypeOf("10 + 20 - 3").Name); Console.WriteLine(uc.DataTypeOf(" 'What type ' + 'is this?' ").Name); Console.WriteLine(uc.DataTypeOf("3 < 10").Name); Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name); Console.WriteLine("---"); uc.DefineFunction("func(x) as string = 'Hello' * 3"); Console.WriteLine(uc.DataTypeOf("func").Name); Console.WriteLine(uc.DataTypeOf("Int").Name); Console.WriteLine(uc.DataTypeOf("NonExistantType").Name); // Empty string Console.WriteLine(uc.DataTypeOf("&&").Name);
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
cout << uc.DataTypeOf("10 + 20 - 3").Name() << endl;
cout << uc.DataTypeOf(" 'What type ' + 'is this?' ").Name() << endl;
cout << uc.DataTypeOf("3 < 10").Name() << endl;
cout << uc.DataTypeOf("5 + 7 * #i").Name() << endl;
cout << "---" << endl;
uc.DefineFunction("func(x) as string = 'Hello' * 3");
cout << uc.DataTypeOf("func").Name() << endl;
cout << uc.DataTypeOf("Int").Name() << endl;
cout << uc.DataTypeOf("NonExistantType").Name() << endl; // Empty string
cout << uc.DataTypeOf("&&").Name() << endl;
}
double
string
bool
complex
---
string
int
bool #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; cout << uc.DataTypeOf("10 + 20 - 3").Name() << endl; cout << uc.DataTypeOf(" 'What type ' + 'is this?' ").Name() << endl; cout << uc.DataTypeOf("3 < 10").Name() << endl; cout << uc.DataTypeOf("5 + 7 * #i").Name() << endl; cout << "---" << endl; uc.DefineFunction("func(x) as string = 'Hello' * 3"); cout << uc.DataTypeOf("func").Name() << endl; cout << uc.DataTypeOf("Int").Name() << endl; cout << uc.DataTypeOf("NonExistantType").Name() << endl; // Empty string cout << uc.DataTypeOf("&&").Name() << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Console.WriteLine(uc.DataTypeOf("10 + 20 - 3").Name)
Console.WriteLine(uc.DataTypeOf(" 'What type ' + 'is this?' ").Name)
Console.WriteLine(uc.DataTypeOf("3 < 10").Name)
Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name)
Console.WriteLine("---")
uc.DefineFunction("func(x) as string = 'Hello' * 3")
Console.WriteLine(uc.DataTypeOf("func").Name)
Console.WriteLine(uc.DataTypeOf("Int").Name)
Console.WriteLine(uc.DataTypeOf("NonExistantType").Name) '// Empty string
Console.WriteLine(uc.DataTypeOf("&&").Name)
End Sub
End Module
double
string
bool
complex
---
string
int
bool Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Console.WriteLine(uc.DataTypeOf("10 + 20 - 3").Name) Console.WriteLine(uc.DataTypeOf(" 'What type ' + 'is this?' ").Name) Console.WriteLine(uc.DataTypeOf("3 < 10").Name) Console.WriteLine(uc.DataTypeOf("5 + 7 * #i").Name) Console.WriteLine("---") uc.DefineFunction("func(x) as string = 'Hello' * 3") Console.WriteLine(uc.DataTypeOf("func").Name) Console.WriteLine(uc.DataTypeOf("Int").Name) Console.WriteLine(uc.DataTypeOf("NonExistantType").Name) '// Empty string Console.WriteLine(uc.DataTypeOf("&&").Name) End Sub End Module