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

new macros for enum value parsing #51

Closed gerwaric closed 1 year ago

gerwaric commented 1 year ago

Added two new macros for enums: JS_ENUM_DECLARE_VALUE_PARSER and JS_ENUM_NAMESPACE_DECLARE_VALUE_PARSER. These work like the existing enum parser macros. They define type handlers for an enum, but instead of using the name of the enumeration, the underlying value is read and written as an integer.

This was developed as an alternative to generalizing JS_ENUM to handle enumeration declarations with initializers.

jorgen commented 1 year ago

No just use git commit —amend and force push to your branch.

On Tue, 17 Oct 2023 at 16:57, Tom Holz @.***> wrote:

@.**** commented on this pull request.

In include/json_struct/json_struct.h https://github.com/jorgen/json_struct/pull/51#discussion_r1362275806:

@@ -4524,6 +4524,88 @@ void populateEnumNames(std::vector &names, const char (&data)[N]) }; \ }

+#define JS_ENUM_DECLARE_VALUE_PARSER(name) \

  • namespace JS \
  • { \
  • template <> \
  • struct TypeHandler \
  • { \
  • static inline Error to(name &to_type, ParseContext &context) \
  • { \
  • if (std::is_unsigned::value) \

Yes, std::underlying_type even better. Modern c++ keeps surprising me.

Should I submit another pull request and let you cancel this one? (I'm still learning how to use github)

— Reply to this email directly, view it on GitHub https://github.com/jorgen/json_struct/pull/51#discussion_r1362275806, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAHQVRIX2Q5GVIAXNZO2RTX72MFDAVCNFSM6AAAAAA6DI3V7CVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTMOBSGYYDIMBTGE . You are receiving this because you commented.Message ID: @.***>

gerwaric commented 1 year ago

Should be done now, thanks.

jorgen commented 1 year ago

Thank you for your contribution!

gerwaric commented 1 year ago

You're welcome, and thank you for maintaining such a useful and easy-to-use json library.