sclass RegisteredReference implements IRef {
Meta owner; // all we require is a meta field
A value;
*() {
//if (!dynamicObjectIsLoading()) registerRef();
}
/*void registerRef {
vmBus_send registeringReference(this);
}*/
// Note that the single-argument constructor takes an owner, not a value
*(Meta owner) {
this(owner, null);
}
*(Meta *owner, A *value) {
index();
//registerRef();
}
// get owning object (source)
Meta owner() { ret owner; }
// get target
public A get() { ret value; }
public bool has() { ret value != null; }
public bool set_trueIfChanged(A a) {
if (eq(a, value)) false;
unindex();
value = a;
index();
true;
}
public void set(A a) {
set_trueIfChanged(a);
}
void setIfEmpty(A a) {
if (!has()) set(a);
}
public void set(IRef ref) { set(ref == null ?: ref.get()); }
public void clear() { set((A) null); }
// can override
bool validRef() { true; }
// TODO: sync all the indexing and unindexing!?
void index() {
if (!validRef()) ret;
var br = lookupInterface IHasBackRefs(get());
br?._registerBackRef(this);
}
void unindex() {
if (!validRef()) ret;
var br = lookupInterface IHasBackRefs(get());
br?._unregisterBackRef(this);
}
// not used yet
void change {}
toString {
ret
ifdef RegisteredReference_markInToString
"RegisteringReference " +
endifdef
str(value);
}
}