void Option::writeIntegers(JSON::Sink &sink, const string &value, const string &delims) { integers_t l = parseIntegers(value, delims); sink.beginList(); for (unsigned i = 0; i < l.size(); i++) { sink.beginAppend(); if (JSON_MIN_INT < l[i] && l[i] < JSON_MAX_INT) sink.write(l[i]); else sink.write(SSTR("0x" << hex << l[i])); } sink.endList(); }
void Option::write(JSON::Sink &sink, bool config, const string &delims) const { if (config) { string value = toString(); if (isObscured() && !(flags & OBSCURED_FLAG)) sink.write(string(value.size(), '*')); else writeValue(sink, value, delims); return; } sink.beginDict(); if (!getHelp().empty()) sink.insert("help", getHelp()); if (hasValue()) { sink.beginInsert("value"); string value = toString(); if (isObscured() && !(flags & OBSCURED_FLAG)) sink.write(string(value.size(), '*')); else writeValue(sink, value, delims); } if (hasDefault()) { sink.beginInsert("default"); writeValue(sink, getDefault(), delims); } sink.insert("type", getTypeString()); if (isOptional()) sink.insertBoolean("optional", true); if (shortName) sink.insert("short", string(1, shortName)); if (isSet()) sink.insertBoolean("set", true); if (isCommandLine()) sink.insertBoolean("command_line", true); if (isDepreciated()) sink.insertBoolean("depreciated", true); if (!constraint.isNull()) sink.insert("constraint", constraint->getHelp()); sink.endDict(); }
void Option::writeValue(JSON::Sink &sink, const string &value, const string &delims) const { switch (type) { case BOOLEAN_TYPE: writeBoolean(sink, value); break; case STRING_TYPE: sink.write(value); break; case INTEGER_TYPE: writeInteger(sink, value); break; case DOUBLE_TYPE: writeDouble(sink, value); break; case STRINGS_TYPE: writeStrings(sink, value, delims); break; case INTEGERS_TYPE: writeIntegers(sink, value, delims); break; case DOUBLES_TYPE: writeDoubles(sink, value, delims); break; default: THROWS("Invalid type " << type); } }
void Option::writeDouble(JSON::Sink &sink, const string &value) { sink.write(parseDouble(value)); }
void Option::writeInteger(JSON::Sink &sink, const string &value) { int64_t x = parseInteger(value); if (JSON_MIN_INT < x && x < JSON_MAX_INT) sink.write(x); else sink.write(SSTR("0x" << hex << x)); }