Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

75
LINES

< > BotCompany Repo | #1031954 // RegisteredReference - Refs (like Concept.Ref) for (almost) any object as owner/value [dev.]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4294L/25K).

1  
sclass RegisteredReference<A> implements IRef<A> {
2  
  Meta owner; // all we require is a meta field
3  
  A value;
4  
  
5  
  *() {
6  
    //if (!dynamicObjectIsLoading()) registerRef();
7  
  }
8  
  
9  
  /*void registerRef {
10  
    vmBus_send registeringReference(this);
11  
  }*/
12  
  
13  
  // Note that the single-argument constructor takes an owner, not a value
14  
  *(Meta owner) {
15  
    this(owner, null);
16  
  }
17  
  
18  
  *(Meta *owner, A *value) {
19  
    index();
20  
    //registerRef();
21  
  }
22  
  
23  
  // get owning object (source)
24  
  Meta owner() { ret owner; }
25  
26  
  // get target
27  
  public A get() { ret value; }
28  
  public bool has() { ret value != null; }
29  
  
30  
  public bool set_trueIfChanged(A a) {
31  
    if (eq(a, value)) false;
32  
    unindex();
33  
    value = a;
34  
    index();
35  
    true;
36  
  }
37  
  
38  
  public void set(A a) {
39  
    set_trueIfChanged(a);
40  
  }
41  
  
42  
  void setIfEmpty(A a) {
43  
    if (!has()) set(a);
44  
  }
45  
  
46  
  public void set(IRef<A> ref) { set(ref == null ?: ref.get()); }
47  
  public void clear() { set((A) null); }
48  
  
49  
  // can override
50  
  bool validRef() { true; }
51  
  
52  
  // TODO: sync all the indexing and unindexing!?
53  
  void index() { 
54  
    if (!validRef()) ret;
55  
    var br = lookupInterface IHasBackRefs(get());
56  
    br?._registerBackRef(this);
57  
  }
58  
59  
  void unindex() {
60  
    if (!validRef()) ret;
61  
    var br = lookupInterface IHasBackRefs(get());
62  
    br?._unregisterBackRef(this);
63  
  }
64  
  
65  
  // not used yet
66  
  void change {}
67  
68  
  toString {
69  
    ret
70  
      ifdef RegisteredReference_markInToString
71  
        "RegisteringReference " +
72  
      endifdef
73  
        str(value);
74  
  }
75  
}

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: 199 / 642
Version history: 16 change(s)
Referenced in: [show references]