chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
46 / 66
69.7%
Branches:
41 / 72
56.9%
Functions:
6 / 6
100.0%

util/environment.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <iterator>
5 #include <optional>
6 #include <string>
7 #include <string_view>
8 #include <type_traits>
9 #include <vector>
10
11 #include "chrono_batch_render/util/text.h"
12
13 namespace chrono::batch_render {
14
15 std::string Environment(const char* name);
16
17 template <class T> struct Choice {
18 std::string_view name;
19 T value;
20 };
21
22 [[noreturn]] void ThrowUnknownChoice(const char* name, std::string_view value,
23 const std::vector<std::string>& names);
24
25 template <class Choices>
26 89 auto EnvironmentChoice(const char* name, const Choices& choices)
27 -> std::optional<std::remove_cvref_t<decltype(std::begin(choices)->value)>> {
28
14/18
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [1]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [1]):
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 time.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [3]):
✓ Branch 2 taken 3 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 2 times.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::LogLevel> [5]>(char const*, chrono::batch_render::Choice<chrono::batch_render::LogLevel> const (&) [5]):
✓ Branch 2 taken 16 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 2 times.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Sampling> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Sampling> const (&) [3]):
✓ Branch 2 taken 23 times.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Traversal> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Traversal> const (&) [3]):
✓ Branch 2 taken 23 times.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::device::(anonymous namespace)::Implementation [5]>(char const*, chrono::batch_render::device::(anonymous namespace)::Implementation const (&) [5]):
✓ Branch 2 taken 23 times.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
178 const std::string value = Lowercase(Environment(name));
29
8/12
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [1]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [1]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [3]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::LogLevel> [5]>(char const*, chrono::batch_render::Choice<chrono::batch_render::LogLevel> const (&) [5]):
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 2 times.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Sampling> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Sampling> const (&) [3]):
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Traversal> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Traversal> const (&) [3]):
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::device::(anonymous namespace)::Implementation [5]>(char const*, chrono::batch_render::device::(anonymous namespace)::Implementation const (&) [5]):
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
89 if (value.empty()) {
30 84 return std::nullopt;
31 }
32
33 5 std::vector<std::string> names;
34
11/24
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [1]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [1]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [3]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1 time.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::LogLevel> [5]>(char const*, chrono::batch_render::Choice<chrono::batch_render::LogLevel> const (&) [5]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 1 time.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Sampling> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Sampling> const (&) [3]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Traversal> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Traversal> const (&) [3]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::device::(anonymous namespace)::Implementation [5]>(char const*, chrono::batch_render::device::(anonymous namespace)::Implementation const (&) [5]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 for (const auto& choice : choices) {
35
5/12
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [1]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [1]):
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [3]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 4 times.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::LogLevel> [5]>(char const*, chrono::batch_render::Choice<chrono::batch_render::LogLevel> const (&) [5]):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 8 times.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Sampling> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Sampling> const (&) [3]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Traversal> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Traversal> const (&) [3]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::device::(anonymous namespace)::Implementation [5]>(char const*, chrono::batch_render::device::(anonymous namespace)::Implementation const (&) [5]):
✗ Branch 0 not taken.
✗ Branch 1 not taken.
15 if (choice.name == value) {
36 2 return choice.value;
37 }
38
3/6
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [1]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [1]):
✓ Branch 1 taken 1 time.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::(anonymous namespace)::Fruit> const (&) [3]):
✓ Branch 1 taken 4 times.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::LogLevel> [5]>(char const*, chrono::batch_render::Choice<chrono::batch_render::LogLevel> const (&) [5]):
✓ Branch 1 taken 8 times.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Sampling> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Sampling> const (&) [3]):
✗ Branch 1 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::Choice<chrono::batch_render::device::Traversal> [3]>(char const*, chrono::batch_render::Choice<chrono::batch_render::device::Traversal> const (&) [3]):
✗ Branch 1 not taken.
std::optional<std::remove_cvref<decltype ((begin({parm#2}))->value)>::type> chrono::batch_render::EnvironmentChoice<chrono::batch_render::device::(anonymous namespace)::Implementation [5]>(char const*, chrono::batch_render::device::(anonymous namespace)::Implementation const (&) [5]):
✗ Branch 1 not taken.
13 names.emplace_back(choice.name);
39 }
40 3 ThrowUnknownChoice(name, value, names);
41 91 }
42
43 }
44