CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
ssdnode.cxh
1#include <cx/ssdtree/ssdtreeobj.cxh>
2#include <cx/stype/stvar.h>
3
4enum SSD_INDEX_MARKER {
5 SSD_ByName = -1 // Pass as index to address a child by name
6};
7
8#define ssditeratorObj(self, clsname) objDynCast(clsname, ssditeratorObjInst(self))
9#define ssdnodeIterLocked(self) ssdnode_iterLocked(self, _ssdCurrentLockState)
10
11interface SSDIteratorIf extends IteratorIf
12{
13 stvar *ptr();
14 strref name();
15 int32 idx();
16
17 bool iterOut([sal _When_(return == true, _Out_)] int32 *idx,
18 [sal _When_(return == true, _Out_)] strref *name,
19 [sal _When_(return == true, _Out_)] stvar **val);
20}
21
22abstract class SSDIterator implements SSDIteratorIf
23{
24 object:SSDNode node;
25
26 SSDLockState *lstate;
27 SSDLockState transient_lock_state;
28
29 bool isHashtable();
30 bool isArray();
31 [opt] [valid] unbound ObjInst *objInst();
32
33 init();
34 destroy();
35}
36
37interface SSDNodeIf
38{
39 // Gets a value. Caller owns the value and must destroy it with stDestroy!
40 bool get(int32 idx, strref name, [sal _When_(return == true, _Out_)] stvar *out, [inout] SSDLockState *_ssdCurrentLockState);
41
42 // Gets a pointer to a value. This points to the internal storage within the node
43 // so it is only guaranteed to be valid while the read lock is held.
44 [opt] [valid] stvar *ptr(int32 idx, strref name, [inout] SSDLockState *_ssdCurrentLockState);
45
46 // Sets the given value
47 bool set(int32 idx, strref name, stvar val, [inout] SSDLockState *_ssdCurrentLockState);
48
49 // Same as setValue but consumes the value
50 // (consumes even on failure)
51 bool setC(int32 idx, strref name, [inout] stvar *val, [inout] SSDLockState *_ssdCurrentLockState);
52
53 // Removes a value
54 bool remove(int32 idx, strref name, [inout] SSDLockState *_ssdCurrentLockState);
55
56 // How many values / objects does this node contain?
57 int32 count([inout] SSDLockState *_ssdCurrentLockState);
58
59 // IMPORTANT NOTE: The generic object iterator interface cannot take any parameters;
60 // thus it always acquires a transient read lock and holds it until the iterator is
61 // destroyed. The caller MUST NOT already have an SSDLock held.
62 // If you want to use iterators inside a larger locked transaction or modify the tree,
63 // use iterLocked() instead.
64 [valid] SSDIterator *iter();
65
66 SSDIterator *_iterLocked([inout] SSDLockState *_ssdCurrentLockState);
67}
68
69abstract class SSDNode implements SSDNodeIf implements Iterable
70{
71 object:SSDTree tree;
72
73 // The timestamp this node was last modified
74 int64 modified;
75
76 // This node is an object that contains values or objects by name
77 bool isHashtable();
78
79 // This node is an array that contains values or objects by array index
80 bool isArray();
81
82 unbound void updateModified();
83}