TsukiNi22/ai-utils / skills/cpp/cpp-class
cpp-class
UnverifiedGenerate C++ (C++20) .hpp/.cpp files and class architectures in Tsukini's style (Xartania header, indented include guards, INCLUDE/CLASS sections, Pre-Function/Function/Operator/Constructor/Destructor blocks, libutils attributes or standard [[...]]), with empty bodies only (never the logic), then register the .cpp in the CMakeLists.txt. Also creates the main.cpp entry point in the same style. Use whenever the user asks to create, scaffold or add a C++ class, a main / entry point, interface (I*), abstract class (A*), template, struct/Type or Define header, module or set of .hpp/.cpp files.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.5 KB |
| examples/ASocket.cpp | other | 11.7 KB |
| examples/ASocket.hpp | other | 7.5 KB |
| examples/ArgParserType.hpp | other | 3.6 KB |
| examples/ISocket.hpp | other | 5.4 KB |
| examples/IdHandler.hpp | other | 8.3 KB |
| examples/NetworkDefine.hpp | other | 1.1 KB |
| examples/Scheduler.cpp | other | 2.5 KB |
| examples/Scheduler.hpp | other | 4.7 KB |
| reference/layout.md | markdown | 17.5 KB |
| requires.txt | markdown | 32 B |
| scripts/cmake_add.pyexecutable | script | 4.7 KB |
| scripts/detect_libutils.shexecutable | script | 1.5 KB |
| scripts/fonts/ansi_shadow.flf | other | 11.9 KB |
| scripts/header.pyexecutable | script | 4.2 KB |
| scripts/list_attributes.shexecutable | script | 1.6 KB |
| templates/abstract.hpp | other | 1.5 KB |
| templates/class.cpp | other | 262 B |
| templates/class.hpp | other | 1.5 KB |
| templates/define.hpp | other | 463 B |
| templates/family.hpp | other | 417 B |
| templates/interface.hpp | other | 1.2 KB |
| templates/main-std.cpp | other | 474 B |
| templates/main.cpp | other | 753 B |
| templates/template.hpp | other | 1.6 KB |
| templates/type.hpp | other | 823 B |
scripts/cmake_add.py
View on GitHub#!/usr/bin/env python3
"""
Add a source file to the source list of a CMakeLists.txt.
Usage:
cmake_add.py <CMakeLists.txt> <src/path/File.cpp> [--var SRC] [--group "Name"] [--dry-run]
Behavior:
- already listed -> nothing to do (exit 0)
- sources found with a GLOB -> nothing to do (exit 0)
- inserted after the last file of the same directory (or of the closest parent),
otherwise appended at the end of the list inside a new '## <Group>' block
- no source list found -> exit 2 (must be done by hand)
"""
import argparse
import os
import re
import sys
LIST_VARS = ("SRC", "SRCS", "SOURCES", "SOURCE", "SRC_FILES", "SOURCE_FILES")
def find_block(lines: list[str], var: str | None) -> tuple[int, int] | None:
"""Return (start, end) line indexes of the source list: start = 'set(VAR', end = ')' line."""
names = (var,) if var else LIST_VARS
openers = [re.compile(rf"^\s*set\(\s*{re.escape(n)}\b", re.I) for n in names]
if not var: # fallback: target declaration with the sources inside
openers.append(re.compile(r"^\s*add_(executable|library)\(", re.I))
for opener in openers:
for start, line in enumerate(lines):
if not opener.search(line):
continue
depth = 0
for end in range(start, len(lines)):
code = lines[end].split("#", 1)[0]
depth += code.count("(") - code.count(")")
if depth <= 0:
block = lines[start:end + 1]
if any(".cpp" in l for l in block) or opener.pattern.startswith("^\\s*set"):
return start, end
break
return None
def entry(line: str) -> str | None:
code = line.split("#", 1)[0].strip().strip('"')
if code.startswith("${CMAKE_SOURCE_DIR}/"):
code = code[len("${CMAKE_SOURCE_DIR}/"):]
return code if re.search(r"\.(cpp|cc|cxx|c)$", code) else None
def closeness(a: str, b: str) -> int:
pa, pb = a.split("/"), b.split("/")
n = 0
while n < min(len(pa), len(pb)) and pa[n] == pb[n]:
n += 1
return n
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("cmake")
parser.add_argument("source")
parser.add_argument("--var", default=None, help="name of the source list variable (default: auto)")
parser.add_argument("--group", default=None, help="comment of the new block if a new one is needed")
parser.add_argument("--dry-run", action="store_true")
args = parser.parse_args()
with open(args.cmake, encoding="utf-8") as f:
content = f.read()
lines = content.split("\n")
source = os.path.normpath(args.source)
raw = re.sub(r"#.*", "", content)
# Already present
if re.search(rf"(^|[\s\"/]){re.escape(source)}([\s\")]|$)", raw, re.M):
print(f"already listed: {source}")
return 0
# Globbing: the file will be found automatically
if re.search(r"file\(\s*GLOB(_RECURSE)?[^)]*\.(cpp|cc|cxx)", raw, re.I):
print("sources collected with file(GLOB...): nothing to add")
return 0
block = find_block(lines, args.var)
if block is None:
sys.stderr.write("no source list found in the CMake, add it by hand\n")
return 2
start, end = block
entries = [(i, entry(lines[i])) for i in range(start, end + 1)]
entries = [(i, e) for i, e in entries if e]
folder = os.path.dirname(source)
if entries:
indent = re.match(r"^\s*", lines[entries[-1][0]]).group(0)
best = max(closeness(os.path.dirname(e), folder) for _, e in entries)
same = [i for i, e in entries if os.path.dirname(e) == folder]
if same:
new = [indent + source]
at = same[-1] + 1
else:
# New block with a group comment ('## Module (sub-part: x)' like the existing ones)
parts = folder.split("/")[1:] if folder.startswith("src/") else folder.split("/")
parts = [p for p in parts if p] or ["Sources"]
name = args.group or (parts[-1].capitalize() if len(parts) <= 2 else f"{parts[-2].capitalize()} (sub-part: {parts[-1]})")
new = ["", indent + f"## {name}", indent + source]
near = [i for i, e in entries if closeness(os.path.dirname(e), folder) == best and best > 0]
at = (near[-1] + 1) if near else entries[-1][0] + 1
else:
indent = " "
new = [indent + source]
at = end
lines[at:at] = new
if args.dry_run:
print("\n".join(lines[start:end + len(new) + 1]))
return 0
with open(args.cmake, "w", encoding="utf-8") as f:
f.write("\n".join(lines))
print(f"added {source} in {args.cmake} (line {at + len(new)})")
return 0
if __name__ == "__main__":
sys.exit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 192k | Updated | Claude CodeCodex | Verified | Install |