├── .vscodeignore ├── .gitignore ├── resources ├── logo.png ├── completeGenerator.gif └── defaultGenerator.gif ├── .vscode ├── extensions.json ├── settings.json ├── tasks.json └── launch.json ├── tsconfig.json ├── CHANGELOG.md ├── .eslintrc.json ├── license.txt ├── webpack.config.js ├── README.md ├── package.json └── src ├── HppGenerator.ts ├── extension.ts ├── CppGenerators.ts └── GuiGenerator.ts /.vscodeignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | *.vsix 4 | out -------------------------------------------------------------------------------- /resources/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onora-hbl/CPP_Class_Generator/HEAD/resources/logo.png -------------------------------------------------------------------------------- /resources/completeGenerator.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onora-hbl/CPP_Class_Generator/HEAD/resources/completeGenerator.gif -------------------------------------------------------------------------------- /resources/defaultGenerator.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onora-hbl/CPP_Class_Generator/HEAD/resources/defaultGenerator.gif -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher"] 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "ES2020", 5 | "lib": [ 6 | "ES2020" 7 | ], 8 | "sourceMap": true, 9 | "rootDir": "src", 10 | "strict": true /* enable all strict type-checking options */ 11 | /* Additional Checks */ 12 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 13 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 14 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.1.1 - 13/02/2022 4 | 5 | - Add settings for default value of checkbox 6 | - Update documentation with GIF examples 7 | - Sync README/CHANGELOG/manifest/... between VScodeStore, open-vsx and github 8 | 9 | ## 1.1.0 - 11/02/2022 10 | 11 | - Add the choice to create or not getters and setters 12 | - Add the posibility to choose a default value for the fields 13 | - Add exceptions' support 14 | - Add `<<` operator overload 15 | - Publish to VScodeStore and open-vsx 16 | 17 | ## 1.0.0 - 03/02/2022 18 | 19 | - First functional version 20 | - Never published on the store 21 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "ecmaVersion": 6, 6 | "sourceType": "module" 7 | }, 8 | "plugins": [ 9 | "@typescript-eslint" 10 | ], 11 | "rules": { 12 | "@typescript-eslint/naming-convention": "warn", 13 | "@typescript-eslint/semi": "warn", 14 | "curly": "warn", 15 | "eqeqeq": "warn", 16 | "no-throw-literal": "warn", 17 | "semi": "off" 18 | }, 19 | "ignorePatterns": [ 20 | "out", 21 | "dist", 22 | "**/*.d.ts" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false, // set this to true to hide the "out" folder with the compiled JS files 5 | "dist": false // set this to true to hide the "dist" folder with the compiled JS files 6 | }, 7 | "search.exclude": { 8 | "out": true, // set this to false to include "out" folder in search results 9 | "dist": true // set this to false to include "dist" folder in search results 10 | }, 11 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 12 | "typescript.tsc.autoDetect": "off" 13 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": [ 10 | "$ts-webpack-watch", 11 | "$tslint-webpack-watch" 12 | ], 13 | "isBackground": true, 14 | "presentation": { 15 | "reveal": "never", 16 | "group": "watchers" 17 | }, 18 | "group": { 19 | "kind": "build", 20 | "isDefault": true 21 | } 22 | }, 23 | { 24 | "type": "npm", 25 | "script": "watch-tests", 26 | "problemMatcher": "$tsc-watch", 27 | "isBackground": true, 28 | "presentation": { 29 | "reveal": "never", 30 | "group": "watchers" 31 | }, 32 | "group": "build" 33 | }, 34 | { 35 | "label": "tasks: watch-tests", 36 | "dependsOn": [ 37 | "npm: watch", 38 | "npm: watch-tests" 39 | ], 40 | "problemMatcher": [] 41 | } 42 | ] 43 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "args": [ 13 | "--extensionDevelopmentPath=${workspaceFolder}" 14 | ], 15 | "outFiles": [ 16 | "${workspaceFolder}/dist/**/*.js" 17 | ], 18 | "preLaunchTask": "${defaultBuildTask}" 19 | }, 20 | { 21 | "name": "Extension Tests", 22 | "type": "extensionHost", 23 | "request": "launch", 24 | "args": [ 25 | "--extensionDevelopmentPath=${workspaceFolder}", 26 | "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" 27 | ], 28 | "outFiles": [ 29 | "${workspaceFolder}/out/**/*.js", 30 | "${workspaceFolder}/dist/**/*.js" 31 | ], 32 | "preLaunchTask": "tasks: watch-tests" 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Hubleur Damien 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | //@ts-check 2 | 3 | 'use strict'; 4 | 5 | const path = require('path'); 6 | 7 | //@ts-check 8 | /** @typedef {import('webpack').Configuration} WebpackConfig **/ 9 | 10 | /** @type WebpackConfig */ 11 | const extensionConfig = { 12 | target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ 13 | mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') 14 | 15 | entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ 16 | output: { 17 | // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/ 18 | path: path.resolve(__dirname, 'dist'), 19 | filename: 'extension.js', 20 | libraryTarget: 'commonjs2' 21 | }, 22 | externals: { 23 | vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/ 24 | // modules added here also need to be added in the .vscodeignore file 25 | }, 26 | resolve: { 27 | // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader 28 | extensions: ['.ts', '.js'] 29 | }, 30 | module: { 31 | rules: [ 32 | { 33 | test: /\.ts$/, 34 | exclude: /node_modules/, 35 | use: [ 36 | { 37 | loader: 'ts-loader' 38 | } 39 | ] 40 | } 41 | ] 42 | }, 43 | devtool: 'nosources-source-map', 44 | infrastructureLogging: { 45 | level: "log", // enables logging required for problem matchers 46 | }, 47 | }; 48 | module.exports = [ extensionConfig ]; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Table of content 2 | - [Table of content](#table-of-content) 3 | - [Road Map](#roadmap) 4 | - [Documentation](#documentation) 5 | - [Generator Pannel](#generator-pannel) 6 | - [Examples](#examples) 7 | - [Settings](#settings) 8 | - [Contributing](#contributing) 9 | # RoadMap 10 | - Automaticaly add 42 header 11 | - Give the choice to create constructors with only certain fields 12 | - Inheritance managing 13 | - All the features that I find useful ;) 14 | # Documentation 15 | ## Generator pannel 16 | - The extension is available on: 17 | - https://marketplace.visualstudio.com/items?itemName=DamienHubleur.cppclassgenerator 18 | - https://open-vsx.org/extension/DamienHubleur/cppclassgenerator 19 | - Open the generator pannel with the command `open C++ orthodox canonical class generator` 20 | - Choose a class name (like `MySuperClass`) 21 | - You can add all the fields you want 22 | - For the type, precise `std` if needed. Examples: `std::string` or `int` 23 | - Choose a name without the `_` (like `mySuperInt`) 24 | - It's not mandatory to add a default value to the field 25 | - You can add classe's exceptions 26 | - Precise the name (like `MySuperException`) 27 | - Precise whatever you want in the `what` function 28 | - If you fill it, you cann add the overload of the `<<` operator (use the precised format to print some field in the message) 29 | - You can generate debug message in constructor/destructor if the subject ask it 30 | --- 31 | ## Examples 32 | - Default generator (Errors are false positive detected by VScode but that's compile) 33 | ![Default](https://github.com/dams333/CPP_Class_Generator/raw/master/resources/defaultGenerator.gif) 34 | - Complete all generator fields 35 | ![Default](https://github.com/dams333/CPP_Class_Generator/raw/master/resources/completeGenerator.gif) 36 | --- 37 | ## Settings 38 | - "cppclassgenerator.defaultGetter" used to choose if the box "generate getter" is default checked 39 | - "cppclassgenerator.defaultSetter" used to choose if the box "generate setter" is default checked 40 | - "cppclassgenerator.defaultDebug" used to choose if the box "generate debug messages" is default checked 41 | # Contributing 42 | PR are welcome on Github to propose an improvement -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cppclassgenerator", 3 | "displayName": "42 C++ Orthodox Canonical Form Class Generator", 4 | "description": "Automatic generation of C++ classes in orthodox canonical form for 42's projects", 5 | "version": "1.1.1", 6 | "publisher": "DamienHubleur", 7 | "license: ": "SEE LICENSE IN license.txt", 8 | "icon": "resources/logo.png", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/dams333/CPP_Class_Generator" 12 | }, 13 | "engines": { 14 | "vscode": "^1.64.0" 15 | }, 16 | "categories": [ 17 | "Formatters", 18 | "Programming Languages" 19 | ], 20 | "keywords": [ 21 | "42", 22 | "cpp", 23 | "c++", 24 | "class", 25 | "generator", 26 | "orthodox", 27 | "canonical", 28 | "form" 29 | ], 30 | "activationEvents": [ 31 | "onCommand:cppclassgenerator.openPannel" 32 | ], 33 | "main": "./dist/extension.js", 34 | "contributes": { 35 | "commands": [ 36 | { 37 | "command": "cppclassgenerator.openPannel", 38 | "title": "Open C++ orthodox canonical class generator" 39 | } 40 | ], 41 | "configuration": { 42 | "title": "C++ Class generator", 43 | "properties": { 44 | "cppclassgenerator.defaultGetter": { 45 | "type": "boolean", 46 | "default": true, 47 | "description": "Is the \"create a getter\" box checked by default." 48 | }, 49 | "cppclassgenerator.defaultSetter": { 50 | "type": "boolean", 51 | "default": false, 52 | "description": "Is the \"create a setter\" box checked by default." 53 | }, 54 | "cppclassgenerator.defaultDebug": { 55 | "type": "boolean", 56 | "default": true, 57 | "description": "Is the \"generate debug messages\" box checked by default." 58 | } 59 | } 60 | } 61 | }, 62 | "scripts": { 63 | "vscode:prepublish": "npm run package", 64 | "compile": "webpack", 65 | "watch": "webpack --watch", 66 | "package": "webpack --mode production --devtool hidden-source-map", 67 | "compile-tests": "tsc -p . --outDir out", 68 | "watch-tests": "tsc -p . -w --outDir out", 69 | "pretest": "npm run compile-tests && npm run compile && npm run lint", 70 | "lint": "eslint src --ext ts", 71 | "test": "node ./out/test/runTest.js" 72 | }, 73 | "devDependencies": { 74 | "@types/glob": "^7.2.0", 75 | "@types/mocha": "^9.0.0", 76 | "@types/node": "14.x", 77 | "@types/vscode": "^1.64.0", 78 | "@typescript-eslint/eslint-plugin": "^5.11.0", 79 | "@typescript-eslint/parser": "^5.11.0", 80 | "@vscode/test-electron": "^2.1.2", 81 | "eslint": "^8.6.0", 82 | "glob": "^7.2.0", 83 | "mocha": "^9.1.3", 84 | "ts-loader": "^9.2.6", 85 | "typescript": "^4.5.4", 86 | "webpack": "^5.66.0", 87 | "webpack-cli": "^4.9.1" 88 | }, 89 | "dependencies": { 90 | "ovsx": "^0.3.0", 91 | "vsce": "^2.6.7" 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/HppGenerator.ts: -------------------------------------------------------------------------------- 1 | export function getHppConstructors(message: any) 2 | { 3 | let text = "\t\t// Constructors\n"; 4 | text += "\t\t" + message.className + "();\n"; 5 | text += "\t\t" + message.className + "(const " + message.className + " ©);\n"; 6 | if(message.fields.length > 0) 7 | { 8 | text += "\t\t" + message.className + "("; 9 | for(let i = 0; i < message.fields.length; i++) 10 | { 11 | if(i !== 0) 12 | { 13 | text += ", "; 14 | } 15 | text += message.fields[i].field_type + " " + message.fields[i].field_name; 16 | } 17 | text += ");\n"; 18 | } 19 | return text; 20 | } 21 | 22 | export function getHppDestructors(message: any) 23 | { 24 | let text = "\t\t\n\t\t// Destructor\n"; 25 | text += "\t\t~" + message.className + "();\n"; 26 | return text; 27 | } 28 | 29 | export function getHppOperators(message: any) 30 | { 31 | let text = "\t\t\n\t\t// Operators\n"; 32 | text += "\t\t" + message.className + " & operator=(const " + message.className + " &assign);\n"; 33 | return text; 34 | } 35 | 36 | export function getHppGettersSetters(message: any) 37 | { 38 | let text = ""; 39 | if(message.fields.length > 0) 40 | { 41 | text += "\t\t\n\t\t// Getters / Setters\n"; 42 | for(let i = 0; i < message.fields.length; i++) 43 | { 44 | if(message.fields[i].getter) 45 | { 46 | text += "\t\t" + message.fields[i].field_type + " get" + message.fields[i].field_name[0].toUpperCase() + message.fields[i].field_name.slice(1) + "() const;\n"; 47 | } 48 | if(message.fields[i].setter) 49 | { 50 | text += "\t\tvoid set" + message.fields[i].field_name[0].toUpperCase() + message.fields[i].field_name.slice(1) + "(" + message.fields[i].field_type + " " + message.fields[i].field_name + ");\n"; 51 | } 52 | } 53 | } 54 | return text; 55 | } 56 | 57 | export function getHppExceptions(message: any) 58 | { 59 | let text = ""; 60 | if(message.classExceptions.length > 0) 61 | { 62 | text += "\t\t\n\t\t// Exceptions\n"; 63 | for(let i = 0; i < message.classExceptions.length; i++) 64 | { 65 | text += "\t\tclass " + message.classExceptions[i].exception_name + " : public std::exception {\n"; 66 | text += "\t\t\tvirtual const char* what() const throw();\n"; 67 | text += "\t\t};\n"; 68 | } 69 | } 70 | return text; 71 | } 72 | 73 | export function getHppPrivate(message: any) 74 | { 75 | let text = ""; 76 | for(let i = 0; i < message.fields.length; i++) 77 | { 78 | text += "\t\t" + message.fields[i].field_type + " _" + message.fields[i].field_name + ";\n"; 79 | } 80 | return text; 81 | } 82 | 83 | export function getHppStreamOperator(message: any) 84 | { 85 | let text = ""; 86 | if(message.format !== "") 87 | { 88 | text += "// Stream operators\n"; 89 | text += "std::ostream & operator<<(std::ostream &stream, const " + message.className + " &object);\n\n"; 90 | } 91 | return text; 92 | } -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | import * as path from 'path'; 3 | import { getGuiHtml } from './GuiGenerator'; 4 | import { getHppConstructors, getHppDestructors, getHppOperators, getHppGettersSetters, getHppPrivate, getHppStreamOperator, getHppExceptions } from './HppGenerator'; 5 | import { getCppConstructors, getCppDestructors, getCppOperators, getCppGettersSetters, getCppStreamOperator, getCppExceptions } from './CppGenerators'; 6 | 7 | export function activate(context: vscode.ExtensionContext) { 8 | 9 | console.log('42CppClassGenerator is now active!'); 10 | 11 | let command = vscode.commands.registerCommand('cppclassgenerator.openPannel', () => { 12 | let onePanel: vscode.WebviewPanel; 13 | onePanel = vscode.window.createWebviewPanel( 14 | 'cppgenerator', 15 | 'Class Generator', 16 | { viewColumn: vscode.ViewColumn.One, preserveFocus: true }, 17 | { 18 | enableScripts: true, 19 | } 20 | ); 21 | onePanel.webview.html = getGuiHtml(vscode.workspace.getConfiguration('cppclassgenerator').get("defaultGetter"), vscode.workspace.getConfiguration('cppclassgenerator').get("defaultSetter"), vscode.workspace.getConfiguration('cppclassgenerator').get("defaultDebug")); 22 | onePanel.webview.onDidReceiveMessage( 23 | async (message: any) => { 24 | if(message.type === "error") 25 | { 26 | vscode.window.showErrorMessage('Please specify a class name'); 27 | } 28 | if(message.type === "error2") 29 | { 30 | vscode.window.showErrorMessage('One of the field is incomplete'); 31 | } 32 | if(message.type === "error3") 33 | { 34 | vscode.window.showErrorMessage('One of the exeption is incomplete'); 35 | } 36 | if(message.type === "generate") 37 | { 38 | console.log("Start generating class " + message.className); 39 | 40 | if(vscode.workspace.workspaceFolders !== undefined) 41 | { 42 | { 43 | let text = "#ifndef " + message.className.toUpperCase() + "_HPP\n# define " + message.className.toUpperCase() + "_HPP\n\n"; 44 | text += "# include \n"; 45 | text += "# include \n\n"; 46 | text += "class " + message.className + "\n{\n"; 47 | text += "\tpublic:\n"; 48 | text += getHppConstructors(message); 49 | text += getHppDestructors(message); 50 | text += getHppOperators(message); 51 | text += getHppGettersSetters(message); 52 | text += getHppExceptions(message); 53 | text += "\t\t\n"; 54 | text += "\tprivate:\n"; 55 | text += getHppPrivate(message); 56 | text += "\t\t\n"; 57 | text += "};\n\n"; 58 | text += getHppStreamOperator(message); 59 | text += "#endif"; 60 | 61 | const newFile = vscode.Uri.parse('untitled:' + path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, message.className + ".hpp")); 62 | vscode.workspace.openTextDocument(newFile).then(document => { 63 | const edit = new vscode.WorkspaceEdit(); 64 | edit.insert(newFile, new vscode.Position(0, 0), text); 65 | return vscode.workspace.applyEdit(edit).then(success => { 66 | if (success) { 67 | document.save(); 68 | } else { 69 | vscode.window.showErrorMessage('Error during HPP creation !'); 70 | } 71 | }); 72 | }); 73 | } 74 | { 75 | let text = "#include \"" + message.className + ".hpp\"\n\n"; 76 | text += getCppConstructors(message); 77 | text += getCppDestructors(message); 78 | text += getCppOperators(message); 79 | text += getCppGettersSetters(message); 80 | text += getCppExceptions(message); 81 | text += getCppStreamOperator(message); 82 | 83 | const newFile = vscode.Uri.parse('untitled:' + path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, message.className + ".cpp")); 84 | vscode.workspace.openTextDocument(newFile).then(document => { 85 | const edit = new vscode.WorkspaceEdit(); 86 | edit.insert(newFile, new vscode.Position(0, 0), text); 87 | return vscode.workspace.applyEdit(edit).then(success => { 88 | if (success) { 89 | document.save(); 90 | } else { 91 | vscode.window.showErrorMessage('Error during CPP creation !'); 92 | } 93 | }); 94 | }); 95 | } 96 | } 97 | else 98 | { 99 | console.error("Impossible to localise user"); 100 | } 101 | vscode.window.showInformationMessage('Files created !'); 102 | onePanel.dispose(); 103 | return; 104 | } 105 | }, 106 | undefined, 107 | context.subscriptions 108 | ); 109 | }); 110 | context.subscriptions.push(command); 111 | } 112 | 113 | export function deactivate() {} 114 | -------------------------------------------------------------------------------- /src/CppGenerators.ts: -------------------------------------------------------------------------------- 1 | export function getCppConstructors(message: any) 2 | { 3 | let text = "// Constructors\n"; 4 | text += message.className + "::" + message.className + "()\n{\n"; 5 | for(let i = 0; i < message.fields.length; i++) 6 | { 7 | text += "\t" + "_" + message.fields[i].field_name + " = " + message.fields[i].default + ";\n"; 8 | } 9 | if(message.debug) 10 | { 11 | text += "\tstd::cout << \"\\e[0;33mDefault Constructor called of " + message.className + "\\e[0m\" << std::endl;\n"; 12 | } 13 | text += "}\n\n"; 14 | text += message.className + "::" + message.className + "(const " + message.className + " ©)\n{\n"; 15 | if(message.fields.length === 0) 16 | { 17 | text += "\t(void) copy;\n"; 18 | } 19 | for(let i = 0; i < message.fields.length; i++) 20 | { 21 | text += "\t" + "_" + message.fields[i].field_name + " = copy.get" + message.fields[i].field_name[0].toUpperCase() + message.fields[i].field_name.slice(1) + "();\n"; 22 | } 23 | if(message.debug) 24 | { 25 | text += "\tstd::cout << \"\\e[0;33mCopy Constructor called of " + message.className + "\\e[0m\" << std::endl;\n"; 26 | } 27 | text += "}\n\n"; 28 | if(message.fields.length > 0) 29 | { 30 | text += message.className + "::" + message.className + "("; 31 | for(let i = 0; i < message.fields.length; i++) 32 | { 33 | if(i !== 0) 34 | { 35 | text += ", "; 36 | } 37 | text += message.fields[i].field_type + " " + message.fields[i].field_name; 38 | } 39 | text += ")\n{\n"; 40 | for(let i = 0; i < message.fields.length; i++) 41 | { 42 | text += "\t" + "_" + message.fields[i].field_name + " = " + message.fields[i].field_name + ";\n"; 43 | } 44 | if(message.debug) 45 | { 46 | text += "\tstd::cout << \"\\e[0;33mFields Constructor called of " + message.className + "\\e[0m\" << std::endl;\n"; 47 | } 48 | text += "}\n\n"; 49 | } 50 | return text; 51 | } 52 | 53 | export function getCppDestructors(message: any) 54 | { 55 | let text = "\n// Destructor\n"; 56 | text += message.className + "::" + "~" + message.className + "()\n{\n"; 57 | if(message.debug) 58 | { 59 | text += "\tstd::cout << \"\\e[0;31mDestructor called of " + message.className + "\\e[0m\" << std::endl;\n"; 60 | } 61 | text += "}\n\n"; 62 | return text; 63 | } 64 | 65 | export function getCppOperators(message: any) 66 | { 67 | let text = "\n// Operators\n"; 68 | text += message.className + " & " + message.className + "::operator=(const " + message.className + " &assign)\n{\n"; 69 | if(message.fields.length === 0) 70 | { 71 | text += "\t(void) assign;\n"; 72 | } 73 | for(let i = 0; i < message.fields.length; i++) 74 | { 75 | text += "\t" + "_" + message.fields[i].field_name + " = assign.get" + message.fields[i].field_name[0].toUpperCase() + message.fields[i].field_name.slice(1) + "();\n"; 76 | } 77 | text += "\treturn *this;\n}\n\n"; 78 | return text; 79 | } 80 | 81 | export function getCppGettersSetters(message: any) 82 | { 83 | let text = ""; 84 | if(message.fields.length > 0) 85 | { 86 | text += "\n// Getters / Setters\n"; 87 | for(let i = 0; i < message.fields.length; i++) 88 | { 89 | if(message.fields[i].getter) 90 | { 91 | text += message.fields[i].field_type + " " + message.className + "::get" + message.fields[i].field_name[0].toUpperCase() + message.fields[i].field_name.slice(1) + "() const\n{\n"; 92 | text += "\treturn _" + message.fields[i].field_name + ";\n}\n"; 93 | } 94 | if(message.fields[i].setter) 95 | { 96 | text += "void " + message.className + "::set" + message.fields[i].field_name[0].toUpperCase() + message.fields[i].field_name.slice(1) + "(" + message.fields[i].field_type + " " + message.fields[i].field_name + ")\n{\n"; 97 | text += "\t_" + message.fields[i].field_name + " = " + message.fields[i].field_name + ";\n}\n\n"; 98 | } 99 | } 100 | } 101 | return text; 102 | } 103 | 104 | export function getCppExceptions(message: any) 105 | { 106 | let text = ""; 107 | if(message.classExceptions.length > 0) 108 | { 109 | text += "\n\n// Exceptions\n"; 110 | for(let i = 0; i < message.classExceptions.length; i++) 111 | { 112 | text += "const char * " + message.className + "::" + message.classExceptions[i].exception_name + "::what() const throw()\n{\n"; 113 | text += "\treturn \"" + message.classExceptions[i].exception_what + "\";\n}\n"; 114 | } 115 | } 116 | return text; 117 | } 118 | 119 | 120 | export function getCppStreamOperator(message: any) 121 | { 122 | let text = ""; 123 | if(message.format !== "") 124 | { 125 | let format = message.format; 126 | for(let i = 0; i < message.fields.length; i++) 127 | { 128 | let toReplace = "${" + message.fields[i].field_name + "}"; 129 | let replacement = "\" << object.get" + message.fields[i].field_name[0].toUpperCase() + message.fields[i].field_name.slice(1) + "()" + " << \""; 130 | format = format.replaceAll(toReplace, replacement); 131 | } 132 | text += "\n\n// Stream operators\n"; 133 | text += "std::ostream & operator<<(std::ostream &stream, const " + message.className + " &object)\n{\n"; 134 | text += "\tstream << \"" + format + "\" << std::endl;\n"; 135 | text += "\treturn stream;\n}\n"; 136 | } 137 | return text; 138 | } -------------------------------------------------------------------------------- /src/GuiGenerator.ts: -------------------------------------------------------------------------------- 1 | export function getGuiHtml(getter: any, setter: any, debug: any) { 2 | let checkedDebug = debug ? "checked" : ""; 3 | let guiHTML = ` 4 | 5 | 6 | 7 | 8 | 9 | C++ Class Generators 10 | 209 | 210 | 211 |
212 |
213 |
214 |
Add a field
215 |
216 |
217 |
Add a class exception
218 |
219 |
220 |
221 |
222 |
223 |
224 | 225 |
226 |
Generate
227 |
228 | 386 | 387 | 388 | `; 389 | return guiHTML; 390 | } --------------------------------------------------------------------------------