about Ref<> object passed to a function

Hi,

I have a function that accept two Ref<> object.
Something like this:

function doSomething(io Ref<A> a, in Ref<B> b);

When I pass this function to kl2dfg I got this kind of code for the node:

Ref<A> a_ref = a;
Ref<B> b_ref = b;
doSomething(a_ref, b_ref);

My question is: Is that mandatory, I mean create first the references locally then pass them to the function or is just the kl2dfg being super clean, explicit and safe?

A little more about Ref.
Is it something like this gonna give me problems?

object B;

struct BContainer {
    Ref<B> bRef;
};

object A {
    BContainer entries[];
};

function A.addB(in Ref<B> b) {
    BContainer cont;
    cont.bRef = b;
    this.entries.push(cont);
    b.manager = this;
}

fucntion A.remove(in Ref<B> b) {
    // the code here could be a little long,
    // lets just imagine it properly remove the BContainer that hold a reference to b
}

object B {
    Ref<A> manager;
}

inline ~B() {
    this.manager.remove(this);
}

Basically I want that B, when going out of scope, ask A to remove it for the entries list.
I have created the BContainer because when I tried a simple Ref<B> bRef[] it didn't work as reference (did I made a mistake, is ti supposed to work?)
Now my code seems to work but I don't know if I should trust it.
Any clarification, opinion, suggestion are very welcome.

Cheers,
Daniele

Tagged:

Comments

Sign In or Register to comment.