Skip to content

Commit f611331

Browse files
committed
Update implementation of OAGUnownedGraphContextRef
# Conflicts: # Sources/OpenGraphCxx/Graph/OGGraph.cpp # Sources/OpenGraphCxx/Graph/OGGraphContext.cpp # Sources/OpenGraphCxx/Graph/OGSubgraph.cpp # Sources/OpenGraphCxx/Graph/Subgraph.cpp # Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h # Sources/OpenGraphCxx/include/OpenGraph/OGGraphContext.h # Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h # Sources/OpenGraphCxx/include/OpenGraphCxx/Graph/Graph.hpp # Sources/OpenGraphCxx/include/OpenGraphCxx/Graph/Subgraph.hpp
1 parent 2a615c6 commit f611331

File tree

10 files changed

+32
-25
lines changed

10 files changed

+32
-25
lines changed

Sources/OpenAttributeGraph/Graph/Graph.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public import OpenAttributeGraphCxx
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/OpenAttributeGraphCxx/Graph/OAGGraph.cpp

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

113-
OAGGraphContextRef OAGGraphGetGraphContext(OAGGraphRef graph) {
113+
OAGUnownedGraphContextRef OAGGraphGetGraphContext(OAGGraphRef graph) {
114114
if (graph->context.isInvalid()) {
115115
OAG::precondition_failure("invalidated graph");
116116
}
117-
return reinterpret_cast<OAGGraphContextRef>(reinterpret_cast<uintptr_t>(graph) + sizeof(CFRuntimeBase));
117+
return reinterpret_cast<OAGUnownedGraphContextRef>(&graph->context.get_graph());
118118
}
119119

120120
void OAGGraphInvalidate(OAGGraphRef graph) {

Sources/OpenAttributeGraphCxx/Graph/OAGGraphContext.cpp

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

8-
OAGGraphRef OAGGraphContextGetGraph(OAGGraphContextRef context) {
8+
OAGGraphRef OAGGraphContextGetGraph(void *context) {
99
return reinterpret_cast<OAGGraphRef>(reinterpret_cast<uintptr_t>(context) - sizeof(CFRuntimeBase));
1010
}

Sources/OpenAttributeGraphCxx/Graph/OAGSubgraph.cpp

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

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

106107
void OAGSubgraphInvalidate(OAGSubgraphRef cf_subgraph) {
@@ -121,7 +122,8 @@ OAGGraphRef OAGSubgraphGetGraph(OAGSubgraphRef cf_subgraph) {
121122
if (cf_subgraph->subgraph == nullptr) {
122123
OAG::precondition_failure("accessing invalidated subgraph");
123124
}
124-
return OAGGraphContextGetGraph(cf_subgraph->subgraph->get_context());
125+
// TODO
126+
return nullptr;
125127
}
126128

127129
void OAGSubgraphAddChild(OAGSubgraphRef parent, OAGSubgraphRef child) {

Sources/OpenAttributeGraphCxx/Graph/Subgraph.cpp

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

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

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGGraph.h

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

1414
typedef struct OAG_BRIDGED_TYPE(id) OAGGraphStorage * OAGGraphRef OAG_SWIFT_NAME(Graph);
1515
typedef struct OAG_BRIDGED_TYPE(id) OAGSubgraphStorage * OAGSubgraphRef OAG_SWIFT_NAME(Subgraph);
16-
typedef struct OAG_BRIDGED_TYPE(id) OAGGraphContextStorage * OAGGraphContextRef OAG_SWIFT_NAME(GraphContext);
16+
typedef struct OAGGraphContextStorage * OAGUnownedGraphContextRef OAG_SWIFT_STRUCT OAG_SWIFT_NAME(UnownedGraphContext);
1717

1818
struct OAGGraphStorage;
19-
struct OAGGraphContextStorage;
2019
struct OAGSubgraphStorage;
20+
struct OAGGraphContextStorage;
2121

2222
typedef uint32_t OAGAttribute OAG_SWIFT_STRUCT OAG_SWIFT_NAME(AnyAttribute);
2323

@@ -63,7 +63,7 @@ void OAGGraphSetContext(OAGGraphRef graph, const void * _Nullable context) OAG_S
6363

6464
OAG_EXPORT
6565
OAG_REFINED_FOR_SWIFT
66-
OAGGraphContextRef OAGGraphGetGraphContext(OAGGraphRef graph) OAG_SWIFT_NAME(getter:OAGGraphRef.graphContext(self:));
66+
OAGUnownedGraphContextRef OAGGraphGetGraphContext(OAGGraphRef graph) OAG_SWIFT_NAME(getter:OAGGraphRef.graphContext(self:));
6767

6868
OAG_EXPORT
6969
OAG_REFINED_FOR_SWIFT

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGGraphContext.h

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

1919
OAG_EXPORT
2020
OAG_REFINED_FOR_SWIFT
21-
OAGGraphRef OAGGraphContextGetGraph(OAGGraphContextRef context) OAG_SWIFT_NAME(getter:OAGGraphContextRef.graph(self:));
21+
OAGGraphRef OAGGraphContextGetGraph(void *context);
2222

2323
OAG_EXTERN_C_END
2424

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void OAGSubgraphSetCurrent(_Nullable OAGSubgraphRef cf_subgraph) OAG_SWIFT_NAME(
4242

4343
OAG_EXPORT
4444
OAG_REFINED_FOR_SWIFT
45-
_Nullable OAGGraphContextRef OAGSubgraphGetCurrentGraphContext(void) OAG_SWIFT_NAME(getter:OAGSubgraphRef.currentGraphContext());
45+
_Nullable OAGUnownedGraphContextRef OAGSubgraphGetCurrentGraphContext(void) OAG_SWIFT_NAME(getter:OAGSubgraphRef.currentGraphContext());
4646

4747
OAG_EXPORT
4848
OAG_REFINED_FOR_SWIFT

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraphCxx/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+
OAG_INLINE OAG_CONSTEXPR
68+
OAGUniqueID get_id() OAG_NOEXCEPT {
69+
return _id;
70+
}
71+
6772
OAG_INLINE
6873
void set_invalidation_callback(ClosureFunction<void, OAGAttribute> invalidation_callback) OAG_NOEXCEPT {
6974
_invalidation_callback = invalidation_callback;
@@ -181,7 +186,7 @@ struct OAGGraphStorage {
181186
};
182187

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

187192
OAG_ASSUME_NONNULL_END

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraphCxx/Graph/Subgraph.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ class SubgraphObject;
1919

2020
class Subgraph final {
2121
private:
22-
OAGSubgraphRef _cf_subgraph;
23-
OAGGraphContextStorage& _context;
22+
SubgraphObject *_Nullable _object;
23+
Graph& _graph;
24+
OAGUniqueID _graph_context_id;
2425
// TODO
2526
bool _isInvalid;
2627
static pthread_key_t _current_subgraph_key;
@@ -30,7 +31,7 @@ class Subgraph final {
3031
static Subgraph *from_cf(OAGSubgraphRef cf_subgraph) OAG_NOEXCEPT;
3132

3233
OAGSubgraphRef to_cf() const OAG_NOEXCEPT {
33-
return _cf_subgraph;
34+
return reinterpret_cast<OAGSubgraphRef>(_object);
3435
}
3536

3637
// MARK: - pthread related
@@ -75,13 +76,13 @@ class Subgraph final {
7576
// MARK: - Getter and setter
7677

7778
OAG_INLINE OAG_CONSTEXPR
78-
const OAGGraphContextRef get_context() const OAG_NOEXCEPT {
79-
return &_context;
79+
const OAG::Graph &get_graph() const OAG_NOEXCEPT {
80+
return _graph;
8081
}
81-
82+
8283
OAG_INLINE OAG_CONSTEXPR
83-
OAGGraphContextRef get_context() OAG_NOEXCEPT {
84-
return &_context;
84+
OAG::Graph &get_graph() OAG_NOEXCEPT {
85+
return _graph;
8586
}
8687

8788
OAG_INLINE OAG_CONSTEXPR
@@ -98,7 +99,7 @@ class Subgraph final {
9899

99100
struct OAGSubgraphStorage {
100101
CFRuntimeBase base;
101-
OAG::Subgraph *subgraph;
102+
OAG::Subgraph *_Nullable subgraph;
102103
};
103104

104105
namespace OAG {

0 commit comments

Comments
 (0)