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

Add support for default values for some of the CYAML types #185

Closed
wants to merge 4 commits into from

Conversation

dawoun
Copy link

@dawoun dawoun commented May 9, 2022

  • Support default values (with new macros) for integer, float, boolean, enum and bitfield fields
  • Can work with code compiled without those updates without rebuilding said code
  • Existing code can be updated to allow default values support simply by including "cyaml_ex.h" instead of "cyaml.h"
  • Some new tests for the new functionality

@dawoun dawoun mentioned this pull request May 9, 2022
Guy Hachlili added 2 commits May 12, 2022 11:15
Default value upport is available for integer (both signed and un),
floating-point, enumeration and bitfields.

The library will keep working correctly with any code compiled with
a prior version, or new code that includes only the cyaml.h header.
Code that includes the cyaml_ex.h will include the option to set up
a default value for loading said types; if the values are not found
in the yaml file the default value will be set inside the allocated
buffer.
@tlsa
Copy link
Owner

tlsa commented May 15, 2022

Hi @dawoun,

Thank you for your interest in LibCYAML.

I have a plan for default values where the default value will always be provided via a pointer. This will allow even structures and arrays to have default values.

The approach taken here is very different to what I want to do, however it is interesting to see.

@dawoun
Copy link
Author

dawoun commented May 15, 2022

Hi @dawoun,

Thank you for your interest in LibCYAML.

I have a plan for default values where the default value will always be provided via a pointer. This will allow even structures and arrays to have default values.

The approach taken here is very different to what I want to do, however it is interesting to see.

I think my approach can be fairly easily expanded to use pointers, except it's not possible then to provide a value as the default value in a macro (i.e, CYAML_FIELD_INT_DEFAULT(7, ...) will not work because you can't take a pointer to the number. I considered it - it would have made copying the data into the value much easier - but seeing that there aren't any registration for whole structures, and that for strings and structures you can use NULL pointer as indicating they aren't in the yaml hence should be filled with defaults, I think the PR handles all the cases.

Furthermore, it doesn't change the API for any existing app, and can be easily applied by including cyaml_ex.h wherever cyaml.h was previously included.

In C++ any structures must be fully initialized - or not initialized
at all; and when initialized it must be in member declaration order.

Hence changes must be made to the headers, in order to allow them to
compile under C++.

Signed-off-by: Guy Hachlili <guy.hachlili@nextsilicon.com>
@dawoun dawoun force-pushed the default_values branch from 6cd3406 to 14a1cd7 Compare May 2, 2023 12:12
@tlsa
Copy link
Owner

tlsa commented May 29, 2023

Hi @dawoun,

Thank you for this proposal. I have decided to use the alternative approach in #212 instead, so I am closing this.

This a very clever approach, but I did not want to maintain the complexity, that would only increase as other optional features are added, such as validation callback functions.

@tlsa tlsa closed this May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants