Merge pull request #695 from quicktype/cpp-header-guard

Emit C++ header guard. Fixes #694
This commit is contained in:
Mark Probst 2018-03-21 13:35:57 -07:00 коммит произвёл GitHub
Родитель 2b9f385dac b54d13e2b1
Коммит 3d5464e5f5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 25 добавлений и 13 удалений

Просмотреть файл

@ -771,6 +771,15 @@ inline ${optionalType}<T> get_optional(const json &j, const char *property) {
}
this.ensureBlankLine();
const guardName: Sourcelike = [
"__QUICKTYPE_",
intercalate("_", this.topLevels.keySeq().map(n => legalizeName(allUpperWordStyle(n)))).toArray(),
"_HPP__"
];
this.emitLine("#ifndef ", guardName);
this.emitLine("#define ", guardName);
this.ensureBlankLine();
const include = (name: string): void => {
this.emitLine(`#include ${name}`);
};
@ -783,20 +792,23 @@ inline ${optionalType}<T> get_optional(const json &j, const char *property) {
} else {
this.emitNamespaces(this._namespaceNames, this.emitTypes);
}
if (this._justTypes) return;
if (!this.haveNamedTypes) return;
if (!this._justTypes && this.haveNamedTypes) {
this.ensureBlankLine();
this.emitNamespaces(List(["nlohmann"]), () => {
if (this.haveUnions) {
this.emitOptionalHelpers();
}
this.forEachClass("leading-and-interposing", this.emitClassFunctions);
this.forEachEnum("leading-and-interposing", this.emitEnumFunctions);
if (this.haveUnions) {
this.ensureBlankLine();
this.emitAllUnionFunctions();
}
});
}
this.ensureBlankLine();
this.emitNamespaces(List(["nlohmann"]), () => {
if (this.haveUnions) {
this.emitOptionalHelpers();
}
this.forEachClass("leading-and-interposing", this.emitClassFunctions);
this.forEachEnum("leading-and-interposing", this.emitEnumFunctions);
if (this.haveUnions) {
this.ensureBlankLine();
this.emitAllUnionFunctions();
}
});
this.emitLine("#endif");
}
}