Files
cbindgen/tests/expectations/bitflags.cpp
T
Emilio Cobos Álvarez 90d26107b8 bitflags: Derive more stuff for bitflags.
The static_cast is needed to avoid -Wnarrowing conversions, but I can also write
it like:

Foo ret;
ret.bits = bits | other.bits;
return ret;

if you prefer.
2019-03-06 14:14:02 -06:00

39 lines
1.1 KiB
C++

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
/// Constants shared by multiple CSS Box Alignment properties
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
struct AlignFlags {
uint8_t bits;
explicit operator bool() const {
return !!bits;
}
AlignFlags operator|(const AlignFlags& other) const {
return {static_cast<decltype(bits)>(this->bits | other.bits)};
}
AlignFlags& operator|=(const AlignFlags& other) {
*this = (*this | other);
return *this;
}
AlignFlags operator&(const AlignFlags& other) const {
return {static_cast<decltype(bits)>(this->bits & other.bits)};
}
AlignFlags& operator&=(const AlignFlags& other) {
*this = (*this & other);
return *this;
}
};
static const AlignFlags AlignFlags_AUTO = (AlignFlags){ .bits = 0 };
static const AlignFlags AlignFlags_NORMAL = (AlignFlags){ .bits = 1 };
static const AlignFlags AlignFlags_START = (AlignFlags){ .bits = 1 << 1 };
static const AlignFlags AlignFlags_END = (AlignFlags){ .bits = 1 << 2 };
static const AlignFlags AlignFlags_FLEX_START = (AlignFlags){ .bits = 1 << 3 };
extern "C" {
void root(AlignFlags flags);
} // extern "C"