Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the feature to use #pragma once instead of #include guards #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions code-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
}

Expand Down
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
6 changes: 6 additions & 0 deletions preferences/preference.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down