Here is the details about how to wrap objects(C++) form OpenVINO to objects(C).
In OpenVINO C++ implementation, many objects are defined with class
, such as ov::Core
, ov::Model
, ov::InferRequest
..., but for C class
doesn't be supported. So, C need to create new object to represent those objects. Three kinds of methods had been adopted in our implementation:
- C
struct
contains a shared pointer to C++class
, Wrap by C++ Shared Pointer - C
struct
contains a instance of C++class
, Wrap by C++ Object - C
struct
rewrite the C++class
, Wrap by Rewrite
Tips:
- For the objects which needs to be hided for users, C
struct
contains a shared pointer will be adopted. - For the objects which needs to be created, operated and read by users, rewrite the C++
class
will be better. - For some simple objects, C
struct
contains a instance of C++class
will be enough.
C construct a new struct
represents the class, which contains a shared pointer to the class
as following:
struct ov_class_name {
std::shared_ptr<ov::ClassName> object;
};
Here is an example (core) for wrapping by shared pointer:
Represent by C struct
:
C provides the struct
by typedef struct ov_core ov_core_t;
C construct a new struct
represents the class, which contains an instance to C++ class
as following:
struct ov_ClassName {
ov::ClassName object;
};
Here is an example (layout) for wrapping by shared pointer:
Represent by C struct
:
C provides the struct
by typedef struct ov_layout ov_layout_t;
C construct a new struct
represents the class, which rewrites related info to the class
as following:
typedef struct {
ov::ClassName object;
} ov_class_name_t;
Here is an example (shape) for wrapping by shared pointer: https://github.com/openvinotoolkit/openvino/blob/d96c25844d6cfd5ad131539c8a0928266127b05a/src/core/include/openvino/core/shape.hpp#L21-L40
Represent by C struct
here
NOTE: this implementation needs developer create the C++
class
based on the Cstruct
info in using this rewrite type.