Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
compactness.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <cstdint>
6#include <filesystem>
7#include <span>
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace portals::compactness {
13
15struct Metrics {
16 std::uint64_t files{};
17 std::uint64_t sourceBytes{};
18 std::uint64_t lexicalTokensApprox{};
19 std::uint64_t codeLines{};
20 std::uint64_t preprocessorDirectives{};
21 std::uint64_t preprocessorTokens{};
22 std::uint64_t commentBytes{};
23 std::uint64_t stringLiteralBytes{};
24 std::uint64_t maxLineBytes{};
25 std::uint64_t maxBraceNesting{};
26};
27
29struct Footprint {
30 std::vector<std::filesystem::path> paths;
32};
33
35struct Options {
36 std::vector<std::filesystem::path> before;
37 std::vector<std::filesystem::path> after;
38 std::string format{"json"};
39 bool help{};
40};
41
46Metrics measureSource(std::string_view source);
47
52Footprint measureFiles(std::span<const std::filesystem::path> paths);
53
58Options parseArguments(std::span<const std::string_view> arguments);
59
66std::string renderReport(const Footprint &before, const Footprint &after, std::string_view format);
67
71std::string_view helpText();
72
73} // namespace portals::compactness
Definition compactness.hpp:29
std::vector< std::filesystem::path > paths
Sorted, canonical input paths.
Definition compactness.hpp:30
Metrics metrics
Sums of counts and maxima of maximum measurements.
Definition compactness.hpp:31
Definition compactness.hpp:15
std::uint64_t codeLines
Physical lines intersecting token spelling.
Definition compactness.hpp:19
std::uint64_t lexicalTokensApprox
Approximate preprocessing tokens, including directives.
Definition compactness.hpp:18
std::uint64_t commentBytes
Normalized source spelling bytes occupied by comments.
Definition compactness.hpp:22
std::uint64_t maxBraceNesting
Maximum lexical brace depth outside directives, per file.
Definition compactness.hpp:25
std::uint64_t files
Number of canonical, distinct input paths.
Definition compactness.hpp:16
std::uint64_t preprocessorDirectives
Directives introduced at logical line start.
Definition compactness.hpp:20
std::uint64_t maxLineBytes
Maximum physical line length in UTF-8 bytes, excluding BOM/newline.
Definition compactness.hpp:24
std::uint64_t stringLiteralBytes
Normalized string spelling bytes including prefix and suffix.
Definition compactness.hpp:23
std::uint64_t sourceBytes
Original file bytes, including BOM and newlines.
Definition compactness.hpp:17
std::uint64_t preprocessorTokens
Tokens belonging to directives, including the introducer.
Definition compactness.hpp:21
Definition compactness.hpp:35
std::string format
Either json or markdown.
Definition compactness.hpp:38
std::vector< std::filesystem::path > after
Explicit candidate files.
Definition compactness.hpp:37
std::vector< std::filesystem::path > before
Explicit baseline files.
Definition compactness.hpp:36
bool help
Print usage without measurement.
Definition compactness.hpp:39