GCC Code Coverage Report


Directory: ../
File: src/util/DeferredLogic.h
Date: 2025-08-26 18:26:32
Exec Total Coverage
Lines: 10 10 100.0%
Functions: 3 3 100.0%
Branches: 4 4 100.0%

Line Branch Exec Source
1 // Copyright (c) 2021-2025 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include <functional>
6 #include <utility>
7
8 namespace spice::compiler {
9
10 struct DeferredLogic {
11 // Constructors
12 16134 explicit DeferredLogic(std::function<void()> deferredFunc, bool triggerOnDestruct = true)
13 16134 : deferredFunc(std::move(deferredFunc)), triggerOnDestruct(triggerOnDestruct) {}
14
15 // Destructor
16 16289 ~DeferredLogic() {
17
4/4
✓ Branch 0 (2→3) taken 15841 times.
✓ Branch 1 (2→5) taken 448 times.
✓ Branch 2 (3→4) taken 8153 times.
✓ Branch 3 (3→5) taken 7688 times.
16289 if (triggerOnDestruct && !alreadyExecuted)
18 8153 deferredFunc();
19 16289 }
20
21 // Public methods
22 7981 void execute() {
23 7981 deferredFunc();
24 7981 alreadyExecuted = true;
25 7981 }
26
27 private:
28 // Private members
29 std::function<void()> deferredFunc;
30 bool triggerOnDestruct;
31 bool alreadyExecuted = false;
32 };
33
34 } // namespace spice::compiler
35