Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement general getter for C-API #167

Open
awvwgk opened this issue Jun 17, 2022 · 0 comments
Open

Implement general getter for C-API #167

awvwgk opened this issue Jun 17, 2022 · 0 comments
Labels
API Affects the C-binding layer. enhancement New feature or request

Comments

@awvwgk
Copy link
Member

awvwgk commented Jun 17, 2022

Having a general getter in the C-API would allow to retrieve values from opaque types. Since the actual type is unknown, the storage location the value should be written to must be passed as void*, as safety measure a positive integer of the available number of bytes can be passed (in case NULL is passed we assume void* has enough memory to hold any result). An error is created if the key does not correspond to any entry or if the required memory is larger than the available.

A possible API could be given provided with

DFTD4_EXTERN void DFTD4_API_CALL
dftd4_structure_get(dftd4_error, dftd4_structure, char key[], void* value, int64_t size);

DFTD4_EXTERN void DFTD4_API_CALL
dftd4_param_get(dftd4_error, dftd4_param, char key[], void* value, int64_t size);

DFTD4_EXTERN void DFTD4_API_CALL
dftd4_model_get(dftd4_error, dftd4_model, char key[], void* value, int64_t size);

#define dftd4_get(error, ptr, ...) \
  _Generic((ptr),                  \
    dftd4_structure                \
    : dftd4_structure_get,         \
    dftd4_model                    \
    : dftd4_model_get,             \
    dftd4_param                    \
    : dftd4_param_get              \
    )((error), (ptr), __VAR_ARGS__)

Could be a solution to peek into the damping parameters if created by method name, cc Lori @loriab. Not sure whether a generic setter is in-scope for dftd4 at the moment. Thanks to Miguel @steinmig for the suggestion.

@awvwgk awvwgk added enhancement New feature or request API Affects the C-binding layer. labels Jun 17, 2022
@awvwgk awvwgk changed the title Implement general getter to C-API Implement general getter for C-API Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Affects the C-binding layer. enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant