ktsu.Schema.Cpp 1.25.0

Prefix Reserved
dotnet add package ktsu.Schema.Cpp --version 1.25.0
                    
NuGet\Install-Package ktsu.Schema.Cpp -Version 1.25.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ktsu.Schema.Cpp" Version="1.25.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ktsu.Schema.Cpp" Version="1.25.0" />
                    
Directory.Packages.props
<PackageReference Include="ktsu.Schema.Cpp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ktsu.Schema.Cpp --version 1.25.0
                    
#r "nuget: ktsu.Schema.Cpp, 1.25.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ktsu.Schema.Cpp@1.25.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ktsu.Schema.Cpp&version=1.25.0
                    
Install as a Cake Addin
#tool nuget:?package=ktsu.Schema.Cpp&version=1.25.0
                    
Install as a Cake Tool

ktsu.Schema.Cpp

The C++ generator for ktsu.Schema: a .schema.json file in, C++ headers out.

NuGet Version NuGet Version NuGet Downloads

Overview

A schema says what your data is. This turns that into the C++ that says it too:

  • a class becomes a struct, its members in the order the schema declares them
  • an enum becomes an enum class at namespace scope, in a header of its own
  • a semantic type becomes a class that shims its representation - so an EntityId and a TextureId are both a long and neither is the other
  • an interface becomes a pure virtual base, one signature per declared function

The schema is turned into a ktsu.Coder AST, and that AST is what decides how C++ is spelled. Nothing in this package writes a brace.

Installation

dotnet add package ktsu.Schema.Cpp

Requirements

  • .NET 9.0 or 10.0

One framework short of ktsu.Schema itself, which also publishes net8.0. The AST this builds on has no net8.0 assembly, which is the whole reason the generator ships as a separate package rather than inside the library: defining and reading a schema stays available to net8.0, and only generating C++ from one does not.

Quick start

Register the generator, then run whatever names it:

using ktsu.Schema.Cpp;
using ktsu.Schema.Generation;

SchemaGenerator.Register(new CppCodeGenerator());

A schema names the language as cpp in its code generator element; Register is how that name finds this implementation. Schema.Tool/Program.cs in the repository is the worked example of a host doing it.

Telling the generator what your program already has

Almost everything comes from the schema. What is left is the short list of types standard C++ has no answer for - there is no fixed-shape numeric vector, no identifier-with-a-generation, no fallible return. A target says how it spells them:

CppGeneratorOptions options = new()
{
    Vector3 = new CppTypeSpelling("holo::Vector3", "holotype/core/vector.hpp"),
    Handle = new CppTypeSpelling("holo::Handle", "holotype/core/handle.hpp"),
    Result = new CppTypeSpelling("holo::Result", "holotype/core/result.hpp"),
};

SchemaGenerator.Register(new CppCodeGenerator(options));

Each spelling carries its header as well as its name, because they are one fact: a generated file naming holo::Vector3 without including the header that declares it does not compile, and only whoever supplied the name knows which header that is.

A target that says nothing is refused those schema types by name, with the option to set, rather than handed a header that will not compile.

ExistingTypes is the other direction - a semantic type your headers already declare is named where it is used rather than generated a second time:

ExistingTypes = new Dictionary<string, CppTypeSpelling>(StringComparer.Ordinal)
{
    ["Kilograms"] = new("holo::Kilograms", "holotype/core/units.hpp"),
    ["Seconds"] = new("holo::Seconds", "holotype/core/units.hpp"),
}

The rest of CppGeneratorOptions is cosmetic: HeaderExtension (.gen.hpp by default), MemberNaming (snake_case by default), and GeneratedBy, the name a generated file's banner opens with - which a target that vendors this behind its own build step should set to the thing a reader would run again.

Conventions the generated headers keep

Four conventions carry globally rather than being annotated per signature, so a schema never grows an ownership dialect:

The schema says C++ gets
Result in a return type the call can fail
Handle something the caller may keep
Span a borrow valid for the call
Direction on a parameter const, or not
IsQuery on a function a trailing const

On a Span, direction describes the elements: In Span<Velocity> is std::span<const Velocity>, Out Span<Position> is std::span<Position>.

License

Licensed under the MIT License. See LICENSE.md.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.25.0 0 9/11/2026
1.24.1 0 9/11/2026
1.24.0 8 9/11/2026
1.23.0 39 9/11/2026
1.22.0 39 9/11/2026

## v1.25.0 (minor)

Changes since v1.24.0:

- Judge a member's metadata by what its type is represented as [minor] ([@Claude](https://github.com/Claude))
- Flag three recorded rationales that decisions have since overtaken [patch] ([@Claude](https://github.com/Claude))
- Rename SchemaTool to Schema.Tool and SchemaEditor to Schema.Editor [patch] ([@Claude](https://github.com/Claude))