b2e224354b
Using operator= is not quite sound in presence of destructors and operator overloading. It's perfectly fine to assume that the left-hand-side of an operator= expression is valid memory, however we're using uninitialized memory here, that may not be the case. Use placement new to properly construct tagged unions. I don't need this with any urgency, but it's the right thing to do in presence of complex types, and the current code seems a bomb waiting to explode :)
40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
#include <cstdarg>
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <new>
|
|
|
|
/// 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"
|