MiKTeX 26.5-next
A scalable TeX distribution
Loading...
Searching...
No Matches
OptionSet.h
Go to the documentation of this file.
1
13
14#pragma once
15
16#include <miktex/Util/config.h>
17
18#include <cstddef>
19
20#include <bitset>
21#include <initializer_list>
22
23MIKTEX_UTIL_BEGIN_NAMESPACE;
24
25template<typename EnumClass_, int Size_ = 32> class OptionSet
26{
27
28public:
29
30 OptionSet() = default;
31 OptionSet(const OptionSet& other) = default;
32 OptionSet& operator=(const OptionSet& other) = default;
33 OptionSet(OptionSet&& other) = default;
34 OptionSet& operator=(OptionSet&& other) = default;
35 ~OptionSet() = default;
36
37 OptionSet(const std::initializer_list<EnumClass_>& options)
38 {
39 for (const EnumClass_& opt : options)
40 {
41 bits[(std::size_t)opt] = true;
42 }
43 }
44
45 OptionSet& operator+=(EnumClass_ opt)
46 {
47 bits[(std::size_t)opt] = true;
48 return *this;
49 }
50
51 OptionSet& operator+=(const OptionSet<EnumClass_>& other)
52 {
53 this->bits |= other.bits;
54 return *this;
55 }
56
57 OptionSet operator+(const EnumClass_& other) const
58 {
59 OptionSet<EnumClass_> result(*this);
60 return result += other;
61 }
62
63 OptionSet& operator-=(EnumClass_ opt)
64 {
65 bits[(std::size_t)opt] = false;
66 return *this;
67 }
68
69 OptionSet operator-(const EnumClass_& other) const
70 {
71 OptionSet<EnumClass_> result(*this);
72 return result -= other;
73 }
74
75 bool operator[](EnumClass_ opt) const
76 {
77 return bits[(std::size_t)opt];
78 }
79
80 bool operator==(const OptionSet<EnumClass_>& other) const
81 {
82 return bits == other.bits;
83 }
84
85 bool operator!=(const OptionSet<EnumClass_>& other) const
86 {
87 return bits != other.bits;
88 }
89
90 void Set()
91 {
92 bits.set();
93 }
94
95 void Reset()
96 {
97 bits.reset();
98 }
99
100private:
101
102 std::bitset<Size_> bits;
103};
104
105MIKTEX_UTIL_END_NAMESPACE;