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.

uCalc = [uCalc]

Property

Product: 

Fast Math Parser

Class: 

Item

Retrieves the parent uCalc instance to which this Item belongs, providing access to its execution context.

Remarks

Every Item in uCalc—be it a variable, function, or operator—is owned by a specific uCalc instance. This instance acts as its execution context or "sandbox," holding the complete set of definitions and settings that apply to it.

The uCalc() method provides a direct way to get a reference back to this parent instance from any Item object.

🎯 Primary Use Cases

  1. Contextual Operations: The most common use is to perform another operation within the same context as the item. If you have an Item object but not a direct reference to its parent uCalc instance, you can use this method to retrieve it and call methods like Eval() or DefineVariable().

  2. Instance Introspection: It allows you to determine if two different items belong to the same execution context, which is invaluable for debugging applications that manage multiple, isolated uCalc instances.

  3. Accessing Sibling Items: Once you retrieve the parent instance, you can use it to find other items within the same sandbox, for example: myVar.uCalc().ItemOf("SomeOtherVar").

⚖️ Comparative Analysis

  • vs. Native Objects (C#/C++): In standard object-oriented programming, an object typically does not maintain a public reference to the factory or container that created it. You would have to design this relationship manually. uCalc makes this parent-child link a first-class, built-in feature, simplifying the management of multiple, concurrent parsing environments.

  • vs. Document Object Model (DOM): The relationship is analogous to the DOM in web development. Just as an HTML element has an ownerDocument property that points back to the document it belongs to, a uCalc Item has its uCalc() method to get back to its owner instance. This provides a consistent and predictable way to navigate the object hierarchy.

Examples

A succinct example demonstrating the basic round-trip from an item back to its parent instance.
				
					using uCalcSoftware;

var uc = new uCalc();
var myInstance = new uCalc();
// Define a variable and get its Item object
var v = myInstance.DefineVariable("v = 10");

// Use the item to get back to its parent uCalc instance
var parentInstance = v.uCalc;

// Perform another evaluation in the same context
Console.WriteLine(parentInstance.EvalStr("v + 5"));
				
			
15
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc myInstance;
   // Define a variable and get its Item object
   auto v = myInstance.DefineVariable("v = 10");

   // Use the item to get back to its parent uCalc instance
   auto parentInstance = v.uCalc();

   // Perform another evaluation in the same context
   cout << parentInstance.EvalStr("v + 5") << endl;
}
				
			
15
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim myInstance As New uCalc()
      '// Define a variable and get its Item object
      Dim v = myInstance.DefineVariable("v = 10")
      
      '// Use the item to get back to its parent uCalc instance
      Dim parentInstance = v.uCalc
      
      '// Perform another evaluation in the same context
      Console.WriteLine(parentInstance.EvalStr("v + 5"))
   End Sub
End Module
				
			
15
A practical example showing how to manage two separate uCalc instances with conflicting variable names.
				
					using uCalcSoftware;

var uc = new uCalc();
// Create two independent uCalc instances
var uc1 = new uCalc();
var uc2 = new uCalc();

// Define a variable 'x' in each instance with a different value
var itemX1 = uc1.DefineVariable("x = 100");
var itemX2 = uc2.DefineVariable("x = 200");

// Use the item to get its parent context and evaluate 'x * 2'
// This correctly uses uc1's context where x is 100.
Console.WriteLine($"Context 1: {itemX1.uCalc.Eval("x * 2")}");

// This correctly uses uc2's context where x is 200.
Console.WriteLine($"Context 2: {itemX2.uCalc.Eval("x * 2")}");

// Clean up the instances
uc1.Release();
uc2.Release();
				
			
Context 1: 200
Context 2: 400
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // Create two independent uCalc instances
   uCalc uc1;
   uCalc uc2;

   // Define a variable 'x' in each instance with a different value
   auto itemX1 = uc1.DefineVariable("x = 100");
   auto itemX2 = uc2.DefineVariable("x = 200");

   // Use the item to get its parent context and evaluate 'x * 2'
   // This correctly uses uc1's context where x is 100.
   cout << "Context 1: " << itemX1.uCalc().Eval("x * 2") << endl;

   // This correctly uses uc2's context where x is 200.
   cout << "Context 2: " << itemX2.uCalc().Eval("x * 2") << endl;

   // Clean up the instances
   uc1.Release();
   uc2.Release();
}
				
			
Context 1: 200
Context 2: 400
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      '// Create two independent uCalc instances
      Dim uc1 As New uCalc()
      Dim uc2 As New uCalc()
      
      '// Define a variable 'x' in each instance with a different value
      Dim itemX1 = uc1.DefineVariable("x = 100")
      Dim itemX2 = uc2.DefineVariable("x = 200")
      
      '// Use the item to get its parent context and evaluate 'x * 2'
      '// This correctly uses uc1's context where x is 100.
      Console.WriteLine($"Context 1: {itemX1.uCalc.Eval("x * 2")}")
      
      '// This correctly uses uc2's context where x is 200.
      Console.WriteLine($"Context 2: {itemX2.uCalc.Eval("x * 2")}")
      
      '// Clean up the instances
      uc1.Release()
      uc2.Release()
   End Sub
End Module
				
			
Context 1: 200
Context 2: 400
Doing an Eval in the same uCalc instance a variable belongs to
				
					using uCalcSoftware;

var uc = new uCalc();
var uc1 = new uCalc();
var uc2 = new uCalc();

var x1 = uc1.DefineVariable("x = 5");
var x2 = uc2.DefineVariable("x = 6");

Console.WriteLine(x1.uCalc.Eval("x*10")); // Same as uc1.Eval("x*10")
Console.WriteLine(x2.uCalc.Eval("x*10")); // Same as uc2.Eval("x*10")

uc1.Release();  // Since x1 is part of uc1, x1 is automatically released as well
uc2.Release();  // Since x2 is part of uc2, x2 is automatically released as well

// You should no longer use x1 or x2 because they were part of uc1 & uc2
// Don not try x1.uCalc().Eval("x*10"); or x2.uCalc().Eval("x*10");
				
			
50
60
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   uCalc uc1;
   uCalc uc2;

   auto x1 = uc1.DefineVariable("x = 5");
   auto x2 = uc2.DefineVariable("x = 6");

   cout << x1.uCalc().Eval("x*10") << endl; // Same as uc1.Eval("x*10")
   cout << x2.uCalc().Eval("x*10") << endl; // Same as uc2.Eval("x*10")

   uc1.Release();  // Since x1 is part of uc1, x1 is automatically released as well
   uc2.Release();  // Since x2 is part of uc2, x2 is automatically released as well

   // You should no longer use x1 or x2 because they were part of uc1 & uc2
   // Don not try x1.uCalc().Eval("x*10"); or x2.uCalc().Eval("x*10");
}
				
			
50
60
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim uc1 As New uCalc()
      Dim uc2 As New uCalc()
      
      Dim x1 = uc1.DefineVariable("x = 5")
      Dim x2 = uc2.DefineVariable("x = 6")
      
      Console.WriteLine(x1.uCalc.Eval("x*10")) '// Same as uc1.Eval("x*10")
      Console.WriteLine(x2.uCalc.Eval("x*10")) '// Same as uc2.Eval("x*10")
      
      uc1.Release()  '// Since x1 is part of uc1, x1 is automatically released as well
      uc2.Release()  '// Since x2 is part of uc2, x2 is automatically released as well
      
      '// You should no longer use x1 or x2 because they were part of uc1 & uc2
      '// Don not try x1.uCalc().Eval("x*10"); or x2.uCalc().Eval("x*10");
   End Sub
End Module
				
			
50
60