GCC Code Coverage Report


Directory: ../
File: src/util/DeferredLogic.h
Date: 2025-01-12 22:43: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 public:
12 // Constructors
13 14570 explicit DeferredLogic(std::function<void()> deferredFunc, bool triggerOnDestruct = true)
14 14570 : deferredFunc(std::move(deferredFunc)), triggerOnDestruct(triggerOnDestruct) {}
15
16 // Destructor
17 14701 ~DeferredLogic() {
18
4/4
✓ Branch 0 taken 14316 times.
✓ Branch 1 taken 385 times.
✓ Branch 2 taken 7595 times.
✓ Branch 3 taken 6721 times.
14701 if (triggerOnDestruct && !alreadyExecuted)
19 7595 deferredFunc();
20 14701 }
21
22 // Public methods
23 6975 void execute() {
24 6975 deferredFunc();
25 6975 alreadyExecuted = true;
26 6975 }
27
28 private:
29 // Private members
30 std::function<void()> deferredFunc;
31 bool triggerOnDestruct;
32 bool alreadyExecuted = false;
33 };
34
35 } // namespace spice::compiler
36