Skip to content

csiro-hydroinformatics/c-interop

Repository files navigation

Reusable functions for marshalling data between C, C++ and other programming languages

license status Python package doc

Python package: license status Documentation Status codecov master: Python package testing: Python package

Purpose and context

This repository contains reusable material for interoperability between C/C++ and other languages such as python, R, etc. It is using template-only C++, avoiding code duplications across several projects. The code design also stems from learning over the years to prevent some "gotchas" one can get into when diving deep in native interop accross compilation modules.

Content

The C++ header files cover interop for:

  • common base types (characters, numeric, and vectors thereof)
  • boost date-time
  • time series (inherited from its usage in time step modelling systems)

The repo also includes interop packages for several higher level languages, that helps handling consistently (including memory management...) some of the data stemming from the C/C++ glue code:

Related work, use cases

One use case arising from hydrologic forecasting is uchronia-time-series.

Some features in the present repository depend on related material:

  • moirai, a C++ library designed to help handling C++ objects from so-called opaque pointers, via a C API.
  • The python package refcount for reference counting external resources.

Another resource is a blog post on generating programming language bindings to a C API.

Example

For instance this library defines a template function to_custom_character_vector to convert C char** types to something useful for the higher level language at hand.

namespace cinterop
{
    namespace utils
	{
        template<typename T>
		T to_custom_character_vector(char** names, int size, bool cleanup);

One specialization of this is a conversion to Rcpp's CharacterVector type for interop with R, which would be used like this:

int size;
char** values = GetEnsembleDatasetDataIdentifiers(dataLibrary->get(),  &size);
CharacterVector cv = to_custom_character_vector<CharacterVector>(values, size, true);

Related work

About

Reusable functions for marshalling data between C, C++ and other programming languages

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •