`YGStyle`: Make getters/setters template args of `BitfieldRef`
Summary: @public Makes bitfield getters/setters part of the bitfield ref template. Since we introduced the tracking bit as template parameter in D14933022, every bitfield ref is an individual class anyway, and having function pointers doesn’t potentially lead to less code generation anyway. Furthermore, this change can (in the absence of tracking bits) avoid less specialized templates dealing with refs, and to dynamic dispatch as a consequence. Reviewed By: SidharthGuglani Differential Revision: D15085495 fbshipit-source-id: 0dd70fa05e9d43a29e38a619cddb642c9ca3f7ab
This commit is contained in:
Родитель
0e17af907e
Коммит
0c7376c7ce
|
@ -27,7 +27,11 @@
|
|||
void set_##FIELD(decltype(FIELD##_) x) { FIELD##_ = x; }
|
||||
|
||||
#define BITFIELD_REF(FIELD) \
|
||||
{ *this, &YGStyle::get_##FIELD, &YGStyle::set_##FIELD }
|
||||
BitfieldRef< \
|
||||
decltype(FIELD##_), \
|
||||
&YGStyle::get_##FIELD, \
|
||||
&YGStyle::set_##FIELD, \
|
||||
FIELD##Bit>
|
||||
|
||||
class YGStyle {
|
||||
template <typename Enum>
|
||||
|
@ -82,15 +86,17 @@ public:
|
|||
CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; }
|
||||
};
|
||||
|
||||
template <typename T, int PropBit>
|
||||
template <
|
||||
typename T,
|
||||
T (YGStyle::*Get)() const,
|
||||
void (YGStyle::*Set)(T),
|
||||
int PropBit>
|
||||
struct BitfieldRef {
|
||||
YGStyle& style;
|
||||
T (YGStyle::*get)() const;
|
||||
void (YGStyle::*set)(T);
|
||||
|
||||
operator T() const { return (style.*get)(); }
|
||||
BitfieldRef<T, PropBit>& operator=(T x) {
|
||||
(style.*set)(x);
|
||||
operator T() const { return (style.*Get)(); }
|
||||
BitfieldRef<T, Get, Set, PropBit>& operator=(T x) {
|
||||
(style.*Set)(x);
|
||||
style.assignedProps_.set(PropBit);
|
||||
return *this;
|
||||
}
|
||||
|
@ -168,6 +174,17 @@ private:
|
|||
// Yoga specific properties, not compatible with flexbox specification
|
||||
YGFloatOptional aspectRatio_ = {};
|
||||
|
||||
BITFIELD_ACCESSORS(direction)
|
||||
BITFIELD_ACCESSORS(flexDirection)
|
||||
BITFIELD_ACCESSORS(justifyContent)
|
||||
BITFIELD_ACCESSORS(alignContent);
|
||||
BITFIELD_ACCESSORS(alignItems);
|
||||
BITFIELD_ACCESSORS(alignSelf);
|
||||
BITFIELD_ACCESSORS(positionType);
|
||||
BITFIELD_ACCESSORS(flexWrap);
|
||||
BITFIELD_ACCESSORS(overflow);
|
||||
BITFIELD_ACCESSORS(display);
|
||||
|
||||
public:
|
||||
const decltype(assignedProps_)& assignedProps() const {
|
||||
return assignedProps_;
|
||||
|
@ -177,50 +194,34 @@ public:
|
|||
using ValueRepr = std::remove_reference<decltype(margin_[0])>::type;
|
||||
|
||||
YGDirection direction() const { return direction_; }
|
||||
BitfieldRef<YGDirection, directionBit> direction() {
|
||||
return BITFIELD_REF(direction);
|
||||
}
|
||||
BITFIELD_REF(direction) direction() { return {*this}; }
|
||||
|
||||
YGFlexDirection flexDirection() const { return flexDirection_; }
|
||||
BitfieldRef<YGFlexDirection, flexDirectionBit> flexDirection() {
|
||||
return BITFIELD_REF(flexDirection);
|
||||
}
|
||||
BITFIELD_REF(flexDirection) flexDirection() { return {*this}; }
|
||||
|
||||
YGJustify justifyContent() const { return justifyContent_; }
|
||||
BitfieldRef<YGJustify, justifyContentBit> justifyContent() {
|
||||
return BITFIELD_REF(justifyContent);
|
||||
}
|
||||
BITFIELD_REF(justifyContent) justifyContent() { return {*this}; }
|
||||
|
||||
YGAlign alignContent() const { return alignContent_; }
|
||||
BitfieldRef<YGAlign, alignContentBit> alignContent() {
|
||||
return BITFIELD_REF(alignContent);
|
||||
}
|
||||
BITFIELD_REF(alignContent) alignContent() { return {*this}; }
|
||||
|
||||
YGAlign alignItems() const { return alignItems_; }
|
||||
BitfieldRef<YGAlign, alignItemsBit> alignItems() {
|
||||
return BITFIELD_REF(alignItems);
|
||||
}
|
||||
BITFIELD_REF(alignItems) alignItems() { return {*this}; }
|
||||
|
||||
YGAlign alignSelf() const { return alignSelf_; }
|
||||
BitfieldRef<YGAlign, alignSelfBit> alignSelf() {
|
||||
return BITFIELD_REF(alignSelf);
|
||||
}
|
||||
BITFIELD_REF(alignSelf) alignSelf() { return {*this}; }
|
||||
|
||||
YGPositionType positionType() const { return positionType_; }
|
||||
BitfieldRef<YGPositionType, positionTypeBit> positionType() {
|
||||
return BITFIELD_REF(positionType);
|
||||
}
|
||||
BITFIELD_REF(positionType) positionType() { return {*this}; }
|
||||
|
||||
YGWrap flexWrap() const { return flexWrap_; }
|
||||
BitfieldRef<YGWrap, flexWrapBit> flexWrap() { return BITFIELD_REF(flexWrap); }
|
||||
BITFIELD_REF(flexWrap) flexWrap() { return {*this}; }
|
||||
|
||||
YGOverflow overflow() const { return overflow_; }
|
||||
BitfieldRef<YGOverflow, overflowBit> overflow() {
|
||||
return BITFIELD_REF(overflow);
|
||||
}
|
||||
BITFIELD_REF(overflow) overflow() { return {*this}; }
|
||||
|
||||
YGDisplay display() const { return display_; }
|
||||
BitfieldRef<YGDisplay, displayBit> display() { return BITFIELD_REF(display); }
|
||||
BITFIELD_REF(display) display() { return {*this}; }
|
||||
|
||||
YGFloatOptional flex() const { return flex_; }
|
||||
Ref<YGFloatOptional, &YGStyle::flex_, flexBit> flex() { return {*this}; }
|
||||
|
@ -276,18 +277,6 @@ public:
|
|||
Ref<YGFloatOptional, &YGStyle::aspectRatio_, aspectRatioBit> aspectRatio() {
|
||||
return {*this};
|
||||
}
|
||||
|
||||
private:
|
||||
BITFIELD_ACCESSORS(direction)
|
||||
BITFIELD_ACCESSORS(flexDirection)
|
||||
BITFIELD_ACCESSORS(justifyContent)
|
||||
BITFIELD_ACCESSORS(alignContent);
|
||||
BITFIELD_ACCESSORS(alignItems);
|
||||
BITFIELD_ACCESSORS(alignSelf);
|
||||
BITFIELD_ACCESSORS(positionType);
|
||||
BITFIELD_ACCESSORS(flexWrap);
|
||||
BITFIELD_ACCESSORS(overflow);
|
||||
BITFIELD_ACCESSORS(display);
|
||||
};
|
||||
|
||||
bool operator==(const YGStyle& lhs, const YGStyle& rhs);
|
||||
|
|
Загрузка…
Ссылка в новой задаче