Skip to content

C++ class

A blueprint that creates a C++ class in the common include/ + src/ layout. It asks for two values: the class name and the namespace.

blueprintor.config.js
module.exports = {
blueprints: [
{
title: "C++ class",
variables: [
{ key: "name", prompt: "Class name" },
{ key: "ns", prompt: "Namespace" },
],
snippets: {
header: `
#pragma once
namespace {ns.snake} {
class {name.pascal} {
public:
void run();
};
} // namespace {ns.snake}
`,
source: `
#include "{ns.snake}/{name.pascal}.hpp"
namespace {ns.snake} {
void {name.pascal}::run() {}
} // namespace {ns.snake}
`,
},
structure: {
folders: [
{
name: "include",
folders: [
{
name: "{ns.snake}",
files: [{ name: "{name.pascal}.hpp", snippet: "header" }],
},
],
},
{
name: "src",
files: [{ name: "{name.pascal}.cpp", snippet: "source" }],
},
],
},
},
],
};

An include guard would need an uppercase form of the name, so the header uses #pragma once.

  1. Right-click the project root in the Explorer and choose Run Blueprintor….

  2. Select C++ class.

  3. Enter http client as the class name, then my app as the namespace.

  • Directorymy-project
    • Directoryinclude
      • Directorymy_app
        • HttpClient.hpp
    • Directorysrc
      • HttpClient.cpp
#pragma once
namespace my_app {
class HttpClient {
public:
void run();
};
} // namespace my_app

The class name uses {name.pascal}, the namespace and its folder use {ns.snake}. One blueprint creates files in two different folders, and the #include path always matches the folder it points to.