Skip to content

Commit 85e8375

Browse files
authored
Merge pull request #16 from m-peko/support-raw-flags
Support raw flags
2 parents 220ce9a + 181d9ba commit 85e8375

3 files changed

Lines changed: 389 additions & 123 deletions

File tree

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int main() {
4545
4646
* [Motivation](#motivation)
4747
* [Getting Started](#getting-started)
48+
* [Raw flags vs flags](#raw-flags-vs-flags)
4849
* [How to Declare Set of Flags?](#how-to-declare-set-of-flags)
4950
* [Bits and Names](#bits-and-names)
5051
* [Bitwise Operators](#bitwise-operators)
@@ -94,9 +95,29 @@ _So, why should I use `bitflags` library?_
9495

9596
`bitflags` is a single-header header-only C++17 library for easily managing set of auto-generated type-safe flags.
9697

98+
### Raw flags vs flags?
99+
100+
`bitflags` library provides you with 2 flag types:
101+
102+
- __raw_flag__ without its string representation (sort of lightweight version)
103+
- __flag__ with its string representation
104+
97105
### How to Declare Set of Flags?
98106

99-
In order to declare a set of auto-generated flags, there are few helper macros that hide kind of "ugly" declaration syntax and provide auto-generated value for each flag:
107+
In order to declare a set of auto-generated flags, there are few helper macros that hide kind of "ugly" declaration syntax and provide auto-generated value for each flag.
108+
109+
Macros for creating set of raw flags, i.e. flags __without__ string representation:
110+
111+
* `BEGIN_RAW_BITFLAGS(NAME)`
112+
- `NAME` - name of set of raw flags
113+
114+
* `RAW_FLAG(NAME)`
115+
- `NAME` - name of specific raw flag
116+
117+
* `END_RAW_BITFLAGS(NAME)`
118+
- `NAME` - name of set of raw flags
119+
120+
Macros for creating set of ordinary flags, i.e. flags __with__ string representation:
100121

101122
* `BEGIN_BITFLAGS(NAME)`
102123
- `NAME` - name of set of flags
@@ -139,10 +160,26 @@ using Flags = bf::bitflags<
139160
>;
140161
```
141162

163+
Usage is basically the same for `raw_flag`s.
164+
142165
### Bits and Names
143166

167+
While bits are part of both `raw_flag` and `flag`, names are part of `flag` type only.
168+
144169
Once the flags are specified, it is possible to get bits representing each flag as well as string representation of each flag:
145170

171+
```cpp
172+
BEGIN_RAW_BITFLAGS(RawFlags)
173+
RAW_FLAG(none)
174+
RAW_FLAG(flag_a)
175+
RAW_FLAG(flag_b)
176+
END_RAW_BITFLAGS(RawFlags)
177+
178+
std::cout << RawFlags::flag_a.bits << std::endl;
179+
```
180+
181+
and
182+
146183
```cpp
147184
BEGIN_BITFLAGS(Flags)
148185
FLAG(none)

0 commit comments

Comments
 (0)