From 92ab35bdbabda2c982ebac31a028d27bd921bd54 Mon Sep 17 00:00:00 2001 From: Eugene Bronza Date: Thu, 1 Jul 2021 16:33:12 +0300 Subject: [PATCH] Added the feature to use #pragma once instead of #include guards + configuration option for this in Preference Resolves #31 --- code-generator.js | 15 ++++++++++++--- main.js | 1 + preferences/preference.json | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/code-generator.js b/code-generator.js index e0b1fd0..3bebb7b 100644 --- a/code-generator.js +++ b/code-generator.js @@ -301,8 +301,13 @@ class CppCodeGenerator { var includePart = this.getIncludePart(elem) codeWriter.writeLine(copyrightHeader) codeWriter.writeLine() - codeWriter.writeLine('#ifndef ' + headerString) - codeWriter.writeLine('#define ' + headerString) + + if (options.usePragmaOnce) { + codeWriter.writeLine('#pragma once') + } else { + codeWriter.writeLine('#ifndef ' + headerString) + codeWriter.writeLine('#define ' + headerString) + } codeWriter.writeLine() if (includePart.length > 0) { @@ -311,8 +316,12 @@ class CppCodeGenerator { } funct(codeWriter, elem, this) + if (!options.usePragmaOnce) { + codeWriter.writeLine() + codeWriter.writeLine('#endif //' + headerString) + } codeWriter.writeLine() - codeWriter.writeLine('#endif //' + headerString) + return codeWriter.getData() } diff --git a/main.js b/main.js index 0a2f77c..5775f01 100644 --- a/main.js +++ b/main.js @@ -29,6 +29,7 @@ function getGenOptions () { useTab: app.preferences.get('cpp.gen.useTab'), indentSpaces: app.preferences.get('cpp.gen.indentSpaces'), useVector: app.preferences.get('cpp.gen.useVector'), + usePragmaOnce: app.preferences.get('cpp.gen.usePragmaOnce'), includeHeader: app.preferences.get('cpp.gen.includeHeader'), genCpp: app.preferences.get('cpp.gen.genCpp') } diff --git a/preferences/preference.json b/preferences/preference.json index 1a2d8b7..9e6579e 100644 --- a/preferences/preference.json +++ b/preferences/preference.json @@ -30,6 +30,12 @@ "type": "check", "default": true }, + "cpp.gen.usePragmaOnce": { + "text": "Use #pragma once instead of #include guards", + "description": "Use #pragma once instead of #include guards in header files.", + "type": "check", + "default": false + }, "cpp.gen.genCpp": { "text": "Generate *.cpp file", "description": "Generate cpp file",