Recent Posts

Site menu:

_____________

Site search

Categories

Generic pointer emulation in Urbi 1.x

There are no “pointers” available in Urbi 1.x, nor references like in C++ for example. This will change in Urbi 2, where everything is an object and references can be made with a simple assignment between objects. Meanwhile, it is possible to use the “map” type of Urbi 1.x to emulate pointers in various ways, and we give some simple examples here.

Maps in Urbi 1.x can use any simple type like numbers or strings as keys. The examples below are valid:


mymap[42] = "hello";

mymap["foo"] = "bar";

mymap["bar"] = 42;

More importantly, you can create objects stored in maps:


mymap["name1"] = new myobj("name1",42);

mymap["name2"] = new myobj("name2",13);

...

It is then possible to give a “reference” to the created objects by providing the relevant key used with ‘mymap’.

A good example of this can be a function taking a list of such “references” and executing the ‘foo’ method on each object:


function apply_foo(l)
{
for obj in l { mymap[obj].foo() }
} ;

This usage of the limited map feature in Urbi 1.x can then be used to implement arrays of objects, which will not be natively supported until Urbi 2.