Skip to content

Commit

Permalink
add c api bindings for lgraph (#180)
Browse files Browse the repository at this point in the history
* add c bindings of lgraph api

* add license

* fix cpplint typo

* fix typo

* add lgraph-cbindings ut

* fix cpplint

* fix test_c

* default initialize

* fix cpplint

* always compile c bindings

* "pack" c bindings into lgraph target

* move src/c/c.cpp to src/lgraph_api/c.cpp

* Update Options.cmake

* Update src/BuildLGraphApi.cmake

---------

Co-authored-by: Tao Wang <wangtaofighting@163.com>
  • Loading branch information
antkiller996 and wangtao9 committed Jun 16, 2023
1 parent 1c716c0 commit b8dcaac
Show file tree
Hide file tree
Showing 7 changed files with 4,579 additions and 7 deletions.
907 changes: 907 additions & 0 deletions include/lgraph/c.h

Large diffs are not rendered by default.

26 changes: 21 additions & 5 deletions include/lgraph/lgraph_types.h
@@ -1,4 +1,4 @@
/**
/**
* Copyright 2022 AntGroup CO., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -726,9 +726,7 @@ struct FieldData {

FieldType type;

FieldType getType() const {
return type;
}
FieldType GetType() const { return type; }

union {
bool boolean;
Expand Down Expand Up @@ -759,9 +757,27 @@ struct FieldData {
/** @brief Query if this object is string */
bool IsString() const { return type == FieldType::STRING; }

/** @brief Query if this object is INT8 */
bool IsInt8() const { return type == FieldType::INT8; }

/** @brief Query if this object is INT16 */
bool IsInt16() const { return type == FieldType::INT16; }

/** @brief Query if this object is INT32 */
bool IsInt32() const { return type == FieldType::INT32; }

/** @brief Query if this object is INT64 */
bool IsInt64() const { return type == FieldType::INT64; }

/** @brief Is this a INT8, INT16, INT32 or INT64? */
bool IsInteger() const { return IsInteger(type); }

/** @brief Query if this object is float */
bool IsFloat() const { return type == FieldType::FLOAT; }

/** @brief Query if this object is double */
bool IsDouble() const { return type == FieldType::DOUBLE; }

/** @brief Is this a FLOAT or DOUBLE? */
bool IsReal() const { return IsReal(type); }

Expand Down Expand Up @@ -799,7 +815,7 @@ struct FieldSpec {
/** @brief is this field optional? */
bool optional;

FieldSpec() {}
FieldSpec(): name(), type(FieldType::NUL), optional(false) {}

/**
* @brief Constructor
Expand Down
1 change: 1 addition & 0 deletions src/BuildLGraphApi.cmake
Expand Up @@ -63,6 +63,7 @@ set(LGRAPH_DB_SRC
db/token_manager.cpp)

set(LGRAPH_API_SRC
lgraph_api/c.cpp
lgraph_api/lgraph_db.cpp
lgraph_api/lgraph_edge_iterator.cpp
lgraph_api/lgraph_galaxy.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/import/import_v3.cpp
Expand Up @@ -32,7 +32,7 @@ void Importer::OnErrorOffline(const std::string& msg) {
}

void Importer::AppendFieldData(std::string& ret, const FieldData& data) {
switch (data.getType()) {
switch (data.GetType()) {
case FieldType::NUL:
FMA_ASSERT(false);
break;
Expand Down

0 comments on commit b8dcaac

Please sign in to comment.