Skip to content

Commit 4d0a921

Browse files
committed
Update implementation of OGUnownedGraphContextRef
1 parent 65a976c commit 4d0a921

File tree

11 files changed

+32
-134
lines changed

11 files changed

+32
-134
lines changed

Sources/OpenGraph/Graph/Graph.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public import OpenGraphCxx
99

1010
extension Graph {
1111
public static func typeIndex(
12-
ctx: GraphContext,
12+
ctx: UnownedGraphContext,
1313
body: _AttributeBody.Type,
1414
valueType: Metadata,
1515
flags: _AttributeType.Flags,

Sources/OpenGraphCxx/Graph/OGGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ void OGGraphSetContext(OGGraphRef graph, const void * _Nullable context) {
110110
graph->context.set_context(context);
111111
}
112112

113-
OGGraphContextRef OGGraphGetGraphContext(OGGraphRef graph) {
113+
OGUnownedGraphContextRef OGGraphGetGraphContext(OGGraphRef graph) {
114114
if (graph->context.isInvalid()) {
115115
OG::precondition_failure("invalidated graph");
116116
}
117-
return reinterpret_cast<OGGraphContextRef>(reinterpret_cast<uintptr_t>(graph) + sizeof(CFRuntimeBase));
117+
return reinterpret_cast<OGUnownedGraphContextRef>(&graph->context.get_graph());
118118
}
119119

120120
void OGGraphInvalidate(OGGraphRef graph) {

Sources/OpenGraphCxx/Graph/OGGraphContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
#include <OpenGraph/OGGraphContext.h>
66
#include <OpenGraph/Private/CFRuntime.h>
77

8-
OGGraphRef OGGraphContextGetGraph(OGGraphContextRef context) {
8+
OGGraphRef OGGraphContextGetGraph(void *context) {
99
return reinterpret_cast<OGGraphRef>(reinterpret_cast<uintptr_t>(context) - sizeof(CFRuntimeBase));
1010
}

Sources/OpenGraphCxx/Graph/OGSubgraph.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ void OGSubgraphSetCurrent(_Nullable OGSubgraphRef cf_subgraph) {
9595
}
9696
}
9797

98-
OGGraphContextRef OGSubgraphGetCurrentGraphContext() {
98+
OGUnownedGraphContextRef OGSubgraphGetCurrentGraphContext() {
9999
OG::Subgraph *subgraph = OG::Subgraph::get_current();
100100
if (subgraph == nullptr) {
101101
return nullptr;
102102
}
103-
return subgraph->get_context();
103+
OG::Graph &graph = subgraph->get_graph();
104+
return reinterpret_cast<OGUnownedGraphContextRef>(&graph);
104105
}
105106

106107
void OGSubgraphInvalidate(OGSubgraphRef cf_subgraph) {
@@ -121,7 +122,8 @@ OGGraphRef OGSubgraphGetGraph(OGSubgraphRef cf_subgraph) {
121122
if (cf_subgraph->subgraph == nullptr) {
122123
OG::precondition_failure("accessing invalidated subgraph");
123124
}
124-
return OGGraphContextGetGraph(cf_subgraph->subgraph->get_context());
125+
// TODO
126+
return nullptr;
125127
}
126128

127129
void OGSubgraphAddChild(OGSubgraphRef parent, OGSubgraphRef child) {

Sources/OpenGraphCxx/Graph/Subgraph.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ void OG::Subgraph::apply(OGAttributeFlags flags, OG::ClosureFunction<void, OGAtt
2323
// TODO
2424
}
2525

26-
OG::Subgraph::Subgraph(OG::SubgraphObject* cf_subgraph, OG::Graph::Context& context, OG::AttributeID):
27-
_cf_subgraph((OGSubgraphRef)cf_subgraph), // FIXME
28-
_context((OGGraphContextStorage &)context){
26+
OG::Subgraph::Subgraph(OG::SubgraphObject* object, OG::Graph::Context& context, OG::AttributeID):
27+
_object(object), _graph(context.get_graph()), _graph_context_id(context.get_id()) {
2928
// TODO
3029
}
3130

Sources/OpenGraphCxx/Graph/Subgraph.hpp

Lines changed: 0 additions & 109 deletions
This file was deleted.

Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
typedef struct OG_BRIDGED_TYPE(id) OGGraphStorage * OGGraphRef OG_SWIFT_NAME(Graph);
1515
typedef struct OG_BRIDGED_TYPE(id) OGSubgraphStorage * OGSubgraphRef OG_SWIFT_NAME(Subgraph);
16-
typedef struct OG_BRIDGED_TYPE(id) OGGraphContextStorage * OGGraphContextRef OG_SWIFT_NAME(GraphContext);
16+
typedef struct OGGraphContextStorage * OGUnownedGraphContextRef OG_SWIFT_STRUCT OG_SWIFT_NAME(UnownedGraphContext);
1717

1818
struct OGGraphStorage;
19-
struct OGGraphContextStorage;
2019
struct OGSubgraphStorage;
20+
struct OGGraphContextStorage;
2121

2222
typedef uint32_t OGAttribute OG_SWIFT_STRUCT OG_SWIFT_NAME(AnyAttribute);
2323

@@ -63,7 +63,7 @@ void OGGraphSetContext(OGGraphRef graph, const void * _Nullable context) OG_SWIF
6363

6464
OG_EXPORT
6565
OG_REFINED_FOR_SWIFT
66-
OGGraphContextRef OGGraphGetGraphContext(OGGraphRef graph) OG_SWIFT_NAME(getter:OGGraphRef.graphContext(self:));
66+
OGUnownedGraphContextRef OGGraphGetGraphContext(OGGraphRef graph) OG_SWIFT_NAME(getter:OGGraphRef.graphContext(self:));
6767

6868
OG_EXPORT
6969
OG_REFINED_FOR_SWIFT

Sources/OpenGraphCxx/include/OpenGraph/OGGraphContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ OG_EXTERN_C_BEGIN
1818

1919
OG_EXPORT
2020
OG_REFINED_FOR_SWIFT
21-
OGGraphRef OGGraphContextGetGraph(OGGraphContextRef context) OG_SWIFT_NAME(getter:OGGraphContextRef.graph(self:));
21+
OGGraphRef OGGraphContextGetGraph(void *context);
2222

2323
OG_EXTERN_C_END
2424

Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void OGSubgraphSetCurrent(_Nullable OGSubgraphRef cf_subgraph) OG_SWIFT_NAME(set
4242

4343
OG_EXPORT
4444
OG_REFINED_FOR_SWIFT
45-
_Nullable OGGraphContextRef OGSubgraphGetCurrentGraphContext(void) OG_SWIFT_NAME(getter:OGSubgraphRef.currentGraphContext());
45+
_Nullable OGUnownedGraphContextRef OGSubgraphGetCurrentGraphContext(void) OG_SWIFT_NAME(getter:OGSubgraphRef.currentGraphContext());
4646

4747
OG_EXPORT
4848
OG_REFINED_FOR_SWIFT

Sources/OpenGraphCxx/include/OpenGraphCxx/Graph/Graph.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ class Graph final {
6464
_context = context;
6565
}
6666

67+
OG_INLINE OG_CONSTEXPR
68+
OGUniqueID get_id() OG_NOEXCEPT {
69+
return _id;
70+
}
71+
6772
OG_INLINE
6873
void set_invalidation_callback(ClosureFunction<void, OGAttribute> invalidation_callback) OG_NOEXCEPT {
6974
_invalidation_callback = invalidation_callback;
@@ -181,7 +186,7 @@ struct OGGraphStorage {
181186
};
182187

183188
struct OGGraphContextStorage {
184-
OG::Graph::Context context;
189+
OG::Graph graph;
185190
};
186191

187192
OG_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)