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:
committed by
Facebook Github Bot
parent
011c1964a0
commit
a803421739
@@ -27,7 +27,11 @@
|
|||||||
void set_##FIELD(decltype(FIELD##_) x) { FIELD##_ = x; }
|
void set_##FIELD(decltype(FIELD##_) x) { FIELD##_ = x; }
|
||||||
|
|
||||||
#define BITFIELD_REF(FIELD) \
|
#define BITFIELD_REF(FIELD) \
|
||||||
{ *this, &YGStyle::get_##FIELD, &YGStyle::set_##FIELD }
|
BitfieldRef< \
|
||||||
|
decltype(FIELD##_), \
|
||||||
|
&YGStyle::get_##FIELD, \
|
||||||
|
&YGStyle::set_##FIELD, \
|
||||||
|
FIELD##Bit>
|
||||||
|
|
||||||
class YGStyle {
|
class YGStyle {
|
||||||
template <typename Enum>
|
template <typename Enum>
|
||||||
@@ -82,15 +86,17 @@ public:
|
|||||||
CompactValue operator[](Idx idx) const { return (style.*Prop)[idx]; }
|
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 {
|
struct BitfieldRef {
|
||||||
YGStyle& style;
|
YGStyle& style;
|
||||||
T (YGStyle::*get)() const;
|
|
||||||
void (YGStyle::*set)(T);
|
|
||||||
|
|
||||||
operator T() const { return (style.*get)(); }
|
operator T() const { return (style.*Get)(); }
|
||||||
BitfieldRef<T, PropBit>& operator=(T x) {
|
BitfieldRef<T, Get, Set, PropBit>& operator=(T x) {
|
||||||
(style.*set)(x);
|
(style.*Set)(x);
|
||||||
style.assignedProps_.set(PropBit);
|
style.assignedProps_.set(PropBit);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -168,6 +174,17 @@ private:
|
|||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
YGFloatOptional aspectRatio_ = {};
|
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:
|
public:
|
||||||
const decltype(assignedProps_)& assignedProps() const {
|
const decltype(assignedProps_)& assignedProps() const {
|
||||||
return assignedProps_;
|
return assignedProps_;
|
||||||
@@ -177,50 +194,34 @@ public:
|
|||||||
using ValueRepr = std::remove_reference<decltype(margin_[0])>::type;
|
using ValueRepr = std::remove_reference<decltype(margin_[0])>::type;
|
||||||
|
|
||||||
YGDirection direction() const { return direction_; }
|
YGDirection direction() const { return direction_; }
|
||||||
BitfieldRef<YGDirection, directionBit> direction() {
|
BITFIELD_REF(direction) direction() { return {*this}; }
|
||||||
return BITFIELD_REF(direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGFlexDirection flexDirection() const { return flexDirection_; }
|
YGFlexDirection flexDirection() const { return flexDirection_; }
|
||||||
BitfieldRef<YGFlexDirection, flexDirectionBit> flexDirection() {
|
BITFIELD_REF(flexDirection) flexDirection() { return {*this}; }
|
||||||
return BITFIELD_REF(flexDirection);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGJustify justifyContent() const { return justifyContent_; }
|
YGJustify justifyContent() const { return justifyContent_; }
|
||||||
BitfieldRef<YGJustify, justifyContentBit> justifyContent() {
|
BITFIELD_REF(justifyContent) justifyContent() { return {*this}; }
|
||||||
return BITFIELD_REF(justifyContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGAlign alignContent() const { return alignContent_; }
|
YGAlign alignContent() const { return alignContent_; }
|
||||||
BitfieldRef<YGAlign, alignContentBit> alignContent() {
|
BITFIELD_REF(alignContent) alignContent() { return {*this}; }
|
||||||
return BITFIELD_REF(alignContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGAlign alignItems() const { return alignItems_; }
|
YGAlign alignItems() const { return alignItems_; }
|
||||||
BitfieldRef<YGAlign, alignItemsBit> alignItems() {
|
BITFIELD_REF(alignItems) alignItems() { return {*this}; }
|
||||||
return BITFIELD_REF(alignItems);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGAlign alignSelf() const { return alignSelf_; }
|
YGAlign alignSelf() const { return alignSelf_; }
|
||||||
BitfieldRef<YGAlign, alignSelfBit> alignSelf() {
|
BITFIELD_REF(alignSelf) alignSelf() { return {*this}; }
|
||||||
return BITFIELD_REF(alignSelf);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGPositionType positionType() const { return positionType_; }
|
YGPositionType positionType() const { return positionType_; }
|
||||||
BitfieldRef<YGPositionType, positionTypeBit> positionType() {
|
BITFIELD_REF(positionType) positionType() { return {*this}; }
|
||||||
return BITFIELD_REF(positionType);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGWrap flexWrap() const { return flexWrap_; }
|
YGWrap flexWrap() const { return flexWrap_; }
|
||||||
BitfieldRef<YGWrap, flexWrapBit> flexWrap() { return BITFIELD_REF(flexWrap); }
|
BITFIELD_REF(flexWrap) flexWrap() { return {*this}; }
|
||||||
|
|
||||||
YGOverflow overflow() const { return overflow_; }
|
YGOverflow overflow() const { return overflow_; }
|
||||||
BitfieldRef<YGOverflow, overflowBit> overflow() {
|
BITFIELD_REF(overflow) overflow() { return {*this}; }
|
||||||
return BITFIELD_REF(overflow);
|
|
||||||
}
|
|
||||||
|
|
||||||
YGDisplay display() const { return display_; }
|
YGDisplay display() const { return display_; }
|
||||||
BitfieldRef<YGDisplay, displayBit> display() { return BITFIELD_REF(display); }
|
BITFIELD_REF(display) display() { return {*this}; }
|
||||||
|
|
||||||
YGFloatOptional flex() const { return flex_; }
|
YGFloatOptional flex() const { return flex_; }
|
||||||
Ref<YGFloatOptional, &YGStyle::flex_, flexBit> flex() { return {*this}; }
|
Ref<YGFloatOptional, &YGStyle::flex_, flexBit> flex() { return {*this}; }
|
||||||
@@ -276,18 +277,6 @@ public:
|
|||||||
Ref<YGFloatOptional, &YGStyle::aspectRatio_, aspectRatioBit> aspectRatio() {
|
Ref<YGFloatOptional, &YGStyle::aspectRatio_, aspectRatioBit> aspectRatio() {
|
||||||
return {*this};
|
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);
|
bool operator==(const YGStyle& lhs, const YGStyle& rhs);
|
||||||
|
Reference in New Issue
Block a user