File tree Expand file tree Collapse file tree
Tests/ComputeTests/Shared/Graph Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,6 +79,18 @@ AGGraphRef AGGraphContextGetGraph(AGUnownedGraphContextRef storage) {
7979 return graph_context->to_cf ();
8080}
8181
82+ #pragma mark - User context
83+
84+ const void *AGGraphGetContext (AGGraphRef graph) {
85+ auto graph_context = AG::Graph::Context::from_cf (graph);
86+ return graph_context->context ();
87+ }
88+
89+ void AGGraphSetContext (AGGraphRef graph, const void *context) {
90+ auto graph_context = AG::Graph::Context::from_cf (graph);
91+ graph_context->set_context (context);
92+ }
93+
8294#pragma mark - Attribute types
8395
8496uint32_t AGGraphInternAttributeType (AGUnownedGraphRef unowned_graph, AGTypeID type,
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ typedef struct AGGraphContextStorage *AGUnownedGraphContextRef AG_SWIFT_STRUCT;
1818
1919CF_EXPORT
2020CF_REFINED_FOR_SWIFT
21- CFTypeID AGGraphGetTypeID () AG_SWIFT_NAME (getter : AGGraphRef .typeID ());
21+ CFTypeID AGGraphGetTypeID () CF_SWIFT_NAME (getter : AGGraphRef .typeID ());
2222
2323// MARK: Graph Context
2424
@@ -39,6 +39,17 @@ CF_REFINED_FOR_SWIFT
3939AGGraphRef AGGraphContextGetGraph (AGUnownedGraphContextRef context )
4040 CF_SWIFT_NAME (getter :AGUnownedGraphContextRef .graph (self :));
4141
42+ // MARK: User context
43+
44+ CF_EXPORT
45+ CF_REFINED_FOR_SWIFT
46+ const void * _Nullable AGGraphGetContext (AGGraphRef graph ) CF_SWIFT_NAME (getter :AGGraphRef .context (self :));
47+
48+ CF_EXPORT
49+ CF_REFINED_FOR_SWIFT
50+ void AGGraphSetContext (AGGraphRef graph , const void * _Nullable context )
51+ CF_SWIFT_NAME (setter :AGGraphRef .context (self :_ :));
52+
4253// MARK: Attribute types
4354
4455CF_EXPORT
Original file line number Diff line number Diff line change 77
88namespace AG {
99
10- Graph::Context::Context (Graph *graph) {
11- _graph = graph;
12- _context_info = nullptr ;
13- _unique_id = AGMakeUniqueID ();
14-
10+ Graph::Context::Context (Graph *graph) : _graph(graph), _unique_id(AGMakeUniqueID()) {
1511 Graph::retain (graph);
1612 graph->_contexts_by_id .insert (_unique_id, this );
1713}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ namespace AG {
1414class Graph ::Context {
1515 private:
1616 Graph *_graph;
17- const void *_context_info ;
17+ const void *_context = nullptr ;
1818 uint64_t _unique_id;
1919
2020 bool _invalidated;
@@ -28,6 +28,9 @@ class Graph::Context {
2828
2929 Graph &graph () const { return *_graph; };
3030
31+ const void *_Nullable context () const { return _context; };
32+ void set_context (const void *_Nullable context) { _context = context; };
33+
3134 bool invalidated () const { return _invalidated; };
3235 void set_invalidated (bool invalidated) { _invalidated = invalidated; };
3336};
Original file line number Diff line number Diff line change @@ -20,6 +20,22 @@ struct GraphTests {
2020 }
2121
2222 }
23+
24+ @Suite
25+ struct ContextTests {
26+
27+ @Test
28+ func storesContextPointer( ) {
29+ let graph = Graph ( )
30+ #expect( graph. context == nil )
31+
32+ withUnsafePointer ( to: " Value " ) { pointer in
33+ graph. context = UnsafeRawPointer ( pointer)
34+ #expect( graph. context == UnsafeRawPointer ( pointer) )
35+ }
36+ }
37+
38+ }
2339
2440 @Suite
2541 struct InternAttributeTypeTests {
You can’t perform that action at this time.
0 commit comments