jorgen / json_struct

json_struct is a single header only C++ library for parsing JSON directly to C++ structs and vice versa
Other
422 stars 57 forks source link

Added user data member to ParseContext #22

Closed noodlecollie closed 2 years ago

noodlecollie commented 2 years ago

For my particular use case, I have to use const char* members in my structs instead of std::string. To accomplish this, I have to keep the parsed strings somewhere in memory and use a custom type handler to provide the const char* pointer to the output struct.

I realised this process would be made at least a little safer if the ParseContext class had support for some user data, since then my string memory pools could be provided on a per-parse basis rather than needing to be static global pools. I've created this PR simply to add a void* member to the ParseContext for this purpose. This should allow anyone else to provide context-specific data for when they do their own parsing.

jorgen commented 2 years ago

We don't need the setter and getter. The other members are just public members, and I think this should be as well.

jorgen commented 2 years ago

Thank you for youre contribution btw! Will you be able to remove the getter and setter or should I do it?

noodlecollie commented 2 years ago

That's a good point, I'll quickly remove them.