Chlumsky/json-cpp-gen

Implement settings with ifdefs

Chlumsky opened this issue · 0 comments

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.