Libraryless. Click here for Pure Java version (4294L/25K).
sclass RegisteredReference<A> implements IRef<A> { 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<A> 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); } }
download show line numbers debug dex old transpilations
Travelled to 5 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1031954 |
Snippet name: | RegisteredReference - Refs (like Concept.Ref) for (almost) any object as owner/value [dev.] |
Eternal ID of this version: | #1031954/17 |
Text MD5: | ba1be4d57202e63055fe8fb423a85d52 |
Transpilation MD5: | c23e7fcdd0a287c028ae9594b468ab03 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-06 07:11:56 |
Source code size: | 1575 bytes / 75 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 198 / 640 |
Version history: | 16 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |