• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kunitoki / LuaBridge3 / 4729482225

pending completion
4729482225

push

github

kunitoki
Unit tests for FlagSet

4 of 4 new or added lines in 1 file covered. (100.0%)

3144 of 3302 relevant lines covered (95.22%)

54056.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.67
/Source/LuaBridge/detail/FlagSet.h
1
// https://github.com/kunitoki/LuaBridge3
2
// Copyright 2023, Lucio Asnaghi
3
// SPDX-License-Identifier: MIT
4

5
#pragma once
6

7
#include "Config.h"
8

9
#include <type_traits>
10
#include <algorithm>
11
#include <string>
12

13
namespace luabridge {
14

15
template <class T, class... Ts>
16
class FlagSet
17
{
18
    static_assert(std::is_integral_v<T>);
19

20
public:
21
    constexpr FlagSet() noexcept = default;
22

23
    constexpr void set(FlagSet other) noexcept
69✔
24
    {
25
        flags |= other.flags;
69✔
26
    }
69✔
27

28
    constexpr FlagSet withSet(FlagSet other) const noexcept
69✔
29
    {
30
        FlagSet result { flags };
69✔
31
        result.flags |= other.flags;
69✔
32
        return result;
69✔
33
    }
34

35
    constexpr void unset(FlagSet other) noexcept
69✔
36
    {
37
        flags &= ~other.flags;
69✔
38
    }
69✔
39

40
    constexpr FlagSet withUnset(FlagSet other) const noexcept
69✔
41
    {
42
        FlagSet result { flags };
69✔
43
        result.flags &= ~other.flags;
69✔
44
        return result;
69✔
45
    }
46

47
    constexpr bool test(FlagSet other) const noexcept
776,940✔
48
    {
49
        return (flags & other.flags) != 0;
776,940✔
50
    }
51

52
    constexpr FlagSet operator|(FlagSet other) const noexcept
138✔
53
    {
54
        return FlagSet(flags | other.flags);
138✔
55
    }
56

57
    constexpr FlagSet operator&(FlagSet other) const noexcept
69✔
58
    {
59
        return FlagSet(flags & other.flags);
69✔
60
    }
61

62
    constexpr FlagSet operator~() const noexcept
69✔
63
    {
64
        return FlagSet(~flags);
69✔
65
    }
66

67
    constexpr T toUnderlying() const noexcept
28,350✔
68
    {
69
        return flags;
28,350✔
70
    }
71

72
    std::string toString() const
276✔
73
    {
74
        std::string result;
276✔
75
        result.reserve(sizeof(T) * std::numeric_limits<uint8_t>::digits);
276✔
76

77
        (result.append((mask<Ts>() & flags) ? "1" : "0"), ...);
276✔
78

79
        for (std::size_t i = sizeof...(Ts); i < sizeof(T) * std::numeric_limits<uint8_t>::digits; ++i)
8,556✔
80
            result.append("0");
8,280✔
81

82
        std::reverse(result.begin(), result.end());
276✔
83

84
        return result;
276✔
85
    }
×
86

87
    template <class... Us>
88
    static constexpr FlagSet Value() noexcept
89
    {
90
        return FlagSet{ mask<Us...>() };
91
    }
92

93
    template <class U>
94
    static constexpr auto fromUnderlying(U newFlags) noexcept
710,937✔
95
        -> std::enable_if_t<std::is_integral_v<U> && std::is_convertible_v<U, T>, FlagSet>
96
    {
97
        return { static_cast<T>(newFlags) };
710,937✔
98
    }
99

100
private:
101
    template <class U, class V, class... Us>
102
    static constexpr T indexOf() noexcept
828✔
103
    {
104
        if constexpr (std::is_same_v<U, V>)
105
            return static_cast<T>(0);
552✔
106
        else
107
            return static_cast<T>(1) + indexOf<U, Us...>();
276✔
108
    }
109

110
    template <class... Us>
111
    static constexpr T mask() noexcept
552✔
112
    {
113
        return ((static_cast<T>(1) << indexOf<Us, Ts...>()) | ...);
552✔
114
    }
115

116
    constexpr FlagSet(T flags) noexcept
711,351✔
117
        : flags(flags)
711,351✔
118
    {
119
    }
711,351✔
120

121
    T flags = 0;
122
};
123

124
} // namespace luabridge
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc