Skip to content

Implement settings with ifdefs #38

@Chlumsky

Description

@Chlumsky

The way parsers and serializers are generated could be changed so that they are configurable with macro definitions rather than settings for the generator, with a notable exception of noThrow as that would result in a mess with function return types. This would also make it easier to check different versions of the generated functions as all would be visible simultaneously. The settings can be kept for default macro values, e.g.

#ifndef JSON_CPP_STRICT_SYNTAX_CHECK
#define JSON_CPP_STRICT_SYNTAX_CHECK 0
#endif
// In actual function:
#if JSON_CPP_STRICT_SYNTAX_CHECK
// ...

For checkMissingKeys and checkRepeatingKeys, this would work as

if (buffer == "firstKey") {
    JSON_CPP_KEY_ENCOUNTERED(0, 0x00000001)
    parseXYZ(value.firstKey);
    continue;
}

with JSON_CPP_KEY_ENCOUNTERED being defined at the beginning of the file to either nothing, just flagging doneKeys, or also checking to throw a REPEATED_KEY based on the configuration macros.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-generationInvolves generation of parser / serializer code

    Projects

    Status

    Medium Priority

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions