Skip to content

Commit 7e1664c

Browse files
authored
Add Subgraph functionality (#176)
1 parent bb3ff23 commit 7e1664c

File tree

14 files changed

+98
-124
lines changed

14 files changed

+98
-124
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/OpenAttributeGraph/Graph/Subgraph.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension Subgraph {
1515
}
1616

1717
extension Subgraph {
18-
public func addObserver(_ observer: () -> Void) -> Int {
18+
public func addObserver(_ observer: @escaping () -> Void) -> Int {
1919
Subgraph.addObserver(self, observer: observer)
2020
}
2121

@@ -65,5 +65,5 @@ extension Subgraph {
6565
private static func apply(_ graph: Subgraph, flags: Flags, callback: (AnyAttribute) -> Void)
6666

6767
@_silgen_name("OAGSubgraphAddObserver")
68-
private static func addObserver(_ graph: Subgraph, observer: () -> Void) -> Int
68+
private static func addObserver(_ graph: Subgraph, observer: @escaping () -> Void) -> Int
6969
}

Sources/OpenAttributeGraphCxx/Attribute/OAGAttribute.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ OAGGraphRef OAGGraphGetAttributeGraph(OAGAttribute attribute) {
159159
}
160160

161161
OAGSubgraphRef OAGGraphGetAttributeSubgraph(OAGAttribute attribute) {
162+
OAGSubgraphRef subgraph = OAGGraphGetAttributeSubgraph2(attribute);
163+
if (subgraph == nullptr) {
164+
OAG::precondition_failure("no subgraph");
165+
}
166+
return subgraph;
167+
}
168+
169+
_Nullable OAGSubgraphRef OAGGraphGetAttributeSubgraph2(OAGAttribute attribute) {
170+
auto attribute_id = OAG::AttributeID(attribute);
171+
// attribute_id.validate_data_offset();
172+
// auto subgraph = attribute_id.subgraph();
173+
// if (subgraph == nullptr) {
174+
// OAG::precondition_failure("internal error");
175+
// }
176+
// return subgraph->to_cf();
162177
// TODO
163178
return nullptr;
164179
}

Sources/OpenAttributeGraphCxx/Data/OAGUniqueID.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// OAGUniqueID.c
33
// OpenAttributeGraphCxx
44
//
5-
// Audited for iOS 18.0
5+
// Audited for 6.5.1
66
// Status: Complete
77

88
#include <OpenAttributeGraph/OAGUniqueID.h>
99
#include <stdatomic.h>
1010

1111
OAGUniqueID OAGMakeUniqueID(void) {
12-
// Initial value is 1
13-
static atomic_long counter = 1;
14-
return counter++;
12+
static atomic_ulong counter = 1;
13+
return atomic_fetch_add_explicit(&counter, 1, memory_order_relaxed);
1514
}

Sources/OpenAttributeGraphCxx/Graph/OAGSubgraph.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ bool OAGSubgraphIsDirty(OAGSubgraphRef cf_subgraph, OAGAttributeFlags flags) {
163163
return false;
164164
}
165165

166-
OAGUniqueID OAGSubgraphAddObserver(OAGSubgraphRef cf_subgraph,
166+
OAGObserverID OAGSubgraphAddObserver(OAGSubgraphRef cf_subgraph,
167167
const void (*function)(const void * _Nullable context OAG_SWIFT_CONTEXT) OAG_SWIFT_CC(swift),
168168
const void * _Nullable context) {
169169
OAG::Subgraph *subgraph = cf_subgraph->subgraph;
@@ -173,6 +173,14 @@ OAGUniqueID OAGSubgraphAddObserver(OAGSubgraphRef cf_subgraph,
173173
return subgraph->add_observer(OAG::ClosureFunction<void>(function, context));
174174
}
175175

176+
void OAGSubgraphRemoveObserver(OAGSubgraphRef cf_subgraph, OAGObserverID observerID) {
177+
OAG::Subgraph *subgraph = cf_subgraph->subgraph;
178+
if (subgraph == nullptr) {
179+
return;
180+
}
181+
subgraph->remove_observer(observerID);
182+
}
183+
176184
#if !OAG_TARGET_OS_WASI
177185
static bool should_record_tree;
178186
static dispatch_once_t should_record_tree_once;

Sources/OpenAttributeGraphCxx/Graph/Subgraph.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ OAGUniqueID OAG::Subgraph::add_observer(OAG::ClosureFunction<void> observer) con
3434
return OAGMakeUniqueID();
3535
}
3636

37+
void OAG::Subgraph::remove_observer(OAGUniqueID observerID) const OAG_NOEXCEPT {
38+
// TODO
39+
}
40+
3741
void OAG::Subgraph::begin_tree(OAG::AttributeID id, OAG::swift::metadata const* type, unsigned int flags) const OAG_NOEXCEPT {
3842
// TODO
3943
}

Sources/OpenAttributeGraphCxx/Graph/Subgraph.hpp

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

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGAttribute.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ OAG_EXPORT
139139
OAG_REFINED_FOR_SWIFT
140140
OAGSubgraphRef OAGGraphGetAttributeSubgraph(OAGAttribute attribute) OAG_SWIFT_NAME(getter:OAGAttribute.subgraph(self:));
141141

142+
OAG_EXPORT
143+
OAG_REFINED_FOR_SWIFT
144+
_Nullable OAGSubgraphRef OAGGraphGetAttributeSubgraph2(OAGAttribute attribute) OAG_SWIFT_NAME(getter:OAGAttribute.subgraph2(self:));
145+
142146
OAG_EXPORT
143147
OAG_REFINED_FOR_SWIFT
144148
const void * OAGGraphReadCachedAttribute(long hashValue, OAGTypeID bodyType, const void *bodyPointer, OAGTypeID valueType, OAGCachedValueOptions options, OAGAttribute attribute, bool unknown/*, ...*/);

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,18 @@ OAG_EXPORT
8787
OAG_REFINED_FOR_SWIFT
8888
bool OAGSubgraphIsDirty(OAGSubgraphRef cf_subgraph, OAGAttributeFlags flags) OAG_SWIFT_NAME(OAGSubgraphRef.isDirty(self:flags:));
8989

90+
typedef long OAGObserverID OAG_SWIFT_NAME(ObserverID);
91+
9092
OAG_EXPORT
9193
OAG_REFINED_FOR_SWIFT
92-
OAGUniqueID OAGSubgraphAddObserver(OAGSubgraphRef cf_subgraph,
94+
OAGObserverID OAGSubgraphAddObserver(OAGSubgraphRef cf_subgraph,
9395
const void (*function)(const void * _Nullable context OAG_SWIFT_CONTEXT) OAG_SWIFT_CC(swift),
9496
const void * _Nullable context);
9597

98+
OAG_EXPORT
99+
OAG_REFINED_FOR_SWIFT
100+
void OAGSubgraphRemoveObserver(OAGSubgraphRef cf_subgraph, OAGObserverID observerID) OAG_SWIFT_NAME(OAGSubgraphRef.removeObserver(self:_:));
101+
96102
OAG_EXPORT
97103
OAG_REFINED_FOR_SWIFT
98104
bool OAGSubgraphShouldRecordTree(void) OAG_SWIFT_NAME(getter:OAGSubgraphRef.shouldRecordTree());

Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGUniqueID.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// OAGUniqueID.h
33
// OpenAttributeGraphCxx
44
//
5-
// Audited for iOS 18.0
5+
// Audited for 6.5.1
66
// Status: Complete
77

88
#ifndef OAGUniqueID_h
99
#define OAGUniqueID_h
1010

1111
#include <OpenAttributeGraph/OAGBase.h>
12-
typedef long OAGUniqueID;
12+
typedef u_long OAGUniqueID OAG_SWIFT_NAME(UniqueID);
1313

1414
OAG_EXTERN_C_BEGIN
1515
OAG_EXPORT

0 commit comments

Comments
 (0)