Skip to content

Commit 2bec8b2

Browse files
committed
Allow creation of a Swift IndexStoreDB instance from an existing C++ IndexSystem type
1 parent 4a3c714 commit 2bec8b2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Sources/IndexStoreDB_CIndexStoreDB/CIndexStoreDB.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ indexstoredb_index_create(const char *storePath, const char *databasePath,
176176
return nullptr;
177177
}
178178

179+
indexstoredb_index_t
180+
indexstoredb_index_create_from_existing(void *opaqueIndexSystem) {
181+
std::shared_ptr<IndexSystem> *indexSystem = static_cast<std::shared_ptr<IndexSystem> *>(opaqueIndexSystem);
182+
return make_object(*indexSystem);
183+
}
184+
179185
void indexstoredb_index_add_delegate(indexstoredb_index_t index,
180186
indexstoredb_delegate_event_receiver_t delegateCallback) {
181187
auto delegate = std::make_shared<BlockIndexSystemDelegate>(delegateCallback);

Sources/IndexStoreDB_CIndexStoreDB/include/IndexStoreDB_CIndexStoreDB/CIndexStoreDB.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ indexstoredb_index_create(const char * _Nonnull storePath,
224224
indexstoredb_creation_options_t _Nonnull options,
225225
indexstoredb_error_t _Nullable * _Nullable);
226226

227+
/// Create an `indexstoredb_index_t` from an existing `std::shared_ptr<IndexSystem>`.
228+
///
229+
/// `opaqueIndexSystem` must be a `std::shared_ptr<IndexSystem> *`.
230+
INDEXSTOREDB_PUBLIC _Nonnull indexstoredb_index_t
231+
indexstoredb_index_create_from_existing(void *_Nonnull opaqueIndexSystem);
232+
227233
/// Add an additional delegate to the given index.
228234
INDEXSTOREDB_PUBLIC void
229235
indexstoredb_index_add_delegate(_Nonnull indexstoredb_index_t index,

0 commit comments

Comments
 (0)