chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
7 / 9
77.8%
Branches:
9 / 9
100.0%
Functions:
1 / 1, 1 excl
100.0%

stage/structure/paths.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstdint>
5 #include <map>
6 #include <optional>
7 #include <span>
8 #include <string>
9 #include <string_view>
10 #include <unordered_map>
11 #include <vector>
12
13 #include "chrono_batch_render/stage/structure/tokens.h"
14
15 namespace chrono::batch_render {
16
17 struct PathShape {
18 std::vector<uint32_t> parent;
19 std::vector<Token> name;
20 std::vector<uint32_t> depth;
21 std::vector<std::vector<uint32_t>> children;
22 std::unordered_map<uint64_t, uint32_t> lookup;
23 };
24
25 class Paths {
26 public:
27 static constexpr uint32_t kNone = 0xFFFFFFFF;
28 static constexpr uint32_t kRoot = kNone;
29
30 509 explicit Paths(Tokens& tokens) : m_tokens(&tokens) {}
31
32 Paths(const Paths&) = delete;
33 Paths& operator=(const Paths&) = delete;
34 Paths(Paths&&) = default;
35 Paths& operator=(Paths&&) = default;
36
37 void Insert(std::string_view path, uint32_t prim);
38 PathShape Shape(uint32_t source);
39 void InsertClones(PathShape shape, std::span<const std::string> targets, uint32_t firstPrim);
40 void Erase(uint32_t prim);
41 void Move(uint32_t prim, std::string_view path);
42
43 uint32_t Find(std::string_view path) const;
44 uint32_t FindParent(std::string_view path) const;
45 bool Contains(uint32_t prim) const;
46
47 std::string Path(uint32_t prim) const;
48 std::string_view Name(uint32_t prim) const;
49 uint32_t Parent(uint32_t prim) const;
50 uint32_t Depth(uint32_t prim) const;
51 std::vector<uint32_t> Children(uint32_t prim) const;
52 std::vector<uint32_t> Subtree(uint32_t prim) const;
53
54 7 uint32_t Size() const {
55
7/7
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
7 return m_size + m_lazy;
56 }
57
58 2 uint32_t Explicit() const {
59
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 return m_size;
60 }
61
62 private:
63 137300 struct Node {
64 uint32_t parent = kNone;
65 Token name;
66 uint32_t depth = 0;
67 bool used = false;
68 std::vector<uint32_t> children;
69 };
70
71 107 struct Block {
72 PathShape shape;
73 uint32_t firstPrim = 0;
74 uint32_t copies = 0;
75 std::vector<bool> explicitCopy;
76 };
77
78 struct Lazy {
79 const Block* block;
80 uint32_t copy;
81 uint32_t index;
82 };
83
84 static uint64_t Key(uint32_t parent, Token name);
85 const Node& Get(uint32_t prim) const;
86 uint32_t Child(uint32_t parent, std::string_view name) const;
87 std::optional<Lazy> Locate(uint32_t prim) const;
88 void Materialize(uint32_t prim);
89 void Link(uint32_t prim, uint32_t parent, Token name);
90
91 Tokens* m_tokens;
92 std::vector<Node> m_nodes;
93 std::vector<uint32_t> m_roots;
94 std::unordered_map<uint64_t, uint32_t> m_children;
95 std::vector<Block> m_blocks;
96 std::map<uint32_t, uint32_t> m_blockStarts;
97 uint32_t m_size = 0;
98 uint32_t m_lazy = 0;
99 };
100
101 }
102