From 8be36df298b43100c18bc9879471dc8f84c23207 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Fri, 9 Feb 2018 14:35:31 -0800 Subject: [PATCH] Don't emit empty "nlohmann" namespace in C++. Fixes #504 --- src/ConvenienceRenderer.ts | 4 ++++ src/Language/CPlusPlus.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/src/ConvenienceRenderer.ts b/src/ConvenienceRenderer.ts index e44a92f3..0507b1c4 100644 --- a/src/ConvenienceRenderer.ts +++ b/src/ConvenienceRenderer.ts @@ -331,6 +331,10 @@ export abstract class ConvenienceRenderer extends Renderer { return !this._namedUnions.isEmpty(); } + protected get haveNamedTypes(): boolean { + return !this._namedTypes.isEmpty(); + } + protected get haveUnions(): boolean { return this._haveUnions; } diff --git a/src/Language/CPlusPlus.ts b/src/Language/CPlusPlus.ts index 21904113..36db2026 100644 --- a/src/Language/CPlusPlus.ts +++ b/src/Language/CPlusPlus.ts @@ -754,6 +754,7 @@ inline ${optionalType} get_optional(const json &j, const char *property) { this.emitNamespace(this._namespaceName, this.emitTypes); } if (this._justTypes) return; + if (!this.haveNamedTypes) return; this.ensureBlankLine(); this.emitNamespace("nlohmann", () => {