Skip to content

Commit

Permalink
C++ style enums 4/N: Errata
Browse files Browse the repository at this point in the history
Summary: This converts usages of YGErrata to Errata

Differential Revision: D49270354

fbshipit-source-id: 2e332e222ce38ab01ccd481ac6a60f1c0195ff7e
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 14, 2023
1 parent 092b3e7 commit b0a16e3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def to_hyphenated_lower(symbol):
ordinal = value[0] if isinstance(value, tuple) else value
f.write(f" {ordinal} = YG{name}{ordinal},\n")
f.write("};\n\n")
f.write(f"YG_DEFINE_ENUM_FLAG_OPERATORS({name})\n\n" if name in BITSET_ENUMS else "")

f.write("template <>\n")
f.write(f"constexpr inline int32_t ordinalCount<{name}>() {{\n")
Expand Down
4 changes: 2 additions & 2 deletions yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,11 +878,11 @@ void* YGConfigGetContext(const YGConfigConstRef config) {
}

void YGConfigSetErrata(YGConfigRef config, YGErrata errata) {
resolveRef(config)->setErrata(errata);
resolveRef(config)->setErrata(scopedEnum(errata));
}

YGErrata YGConfigGetErrata(YGConfigConstRef config) {
return resolveRef(config)->getErrata();
return unscopedEnum(resolveRef(config)->getErrata());
}

void YGConfigSetCloneNodeFunc(
Expand Down
2 changes: 1 addition & 1 deletion yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ static void calculateLayoutImpl(
availableInnerMainDim = maxInnerMainDim;
} else {
bool useLegacyStretchBehaviour =
node->hasErrata(YGErrataStretchFlexBasis);
node->hasErrata(Errata::StretchFlexBasis);

if (!useLegacyStretchBehaviour &&
((!yoga::isUndefined(flexLine.layout.totalFlexGrowFactors) &&
Expand Down
12 changes: 6 additions & 6 deletions yoga/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ ExperimentalFeatureSet Config::getEnabledExperiments() const {
return experimentalFeatures_;
}

void Config::setErrata(YGErrata errata) {
void Config::setErrata(Errata errata) {
errata_ = errata;
}

void Config::addErrata(YGErrata errata) {
void Config::addErrata(Errata errata) {
errata_ |= errata;
}

void Config::removeErrata(YGErrata errata) {
void Config::removeErrata(Errata errata) {
errata_ &= (~errata);
}

YGErrata Config::getErrata() const {
Errata Config::getErrata() const {
return errata_;
}

bool Config::hasErrata(YGErrata errata) const {
return (errata_ & errata) != YGErrataNone;
bool Config::hasErrata(Errata errata) const {
return (errata_ & errata) != Errata::None;
}

void Config::setPointScaleFactor(float pointScaleFactor) {
Expand Down
13 changes: 7 additions & 6 deletions yoga/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <bitset>

#include <yoga/Yoga.h>
#include <yoga/enums/Errata.h>
#include <yoga/enums/ExperimentalFeature.h>

// Tag struct used to form the opaque YGConfigRef for the public C API
Expand Down Expand Up @@ -51,11 +52,11 @@ class YG_EXPORT Config : public ::YGConfig {
bool isExperimentalFeatureEnabled(ExperimentalFeature feature) const;
ExperimentalFeatureSet getEnabledExperiments() const;

void setErrata(YGErrata errata);
void addErrata(YGErrata errata);
void removeErrata(YGErrata errata);
YGErrata getErrata() const;
bool hasErrata(YGErrata errata) const;
void setErrata(Errata errata);
void addErrata(Errata errata);
void removeErrata(Errata errata);
Errata getErrata() const;
bool hasErrata(Errata errata) const;

void setPointScaleFactor(float pointScaleFactor);
float getPointScaleFactor() const;
Expand All @@ -82,7 +83,7 @@ class YG_EXPORT Config : public ::YGConfig {

ConfigFlags flags_{};
ExperimentalFeatureSet experimentalFeatures_{};
YGErrata errata_ = YGErrataNone;
Errata errata_ = Errata::None;
float pointScaleFactor_ = 1.0f;
void* context_ = nullptr;
};
Expand Down
2 changes: 2 additions & 0 deletions yoga/enums/Errata.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ enum class Errata : uint32_t {
Classic = YGErrataClassic,
};

YG_DEFINE_ENUM_FLAG_OPERATORS(Errata)

template <>
constexpr inline int32_t ordinalCount<Errata>() {
return 4;
Expand Down
2 changes: 2 additions & 0 deletions yoga/enums/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum class PrintOptions : uint32_t {
Children = YGPrintOptionsChildren,
};

YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions)

template <>
constexpr inline int32_t ordinalCount<PrintOptions>() {
return 3;
Expand Down
3 changes: 2 additions & 1 deletion yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <yoga/Yoga.h>

#include <yoga/config/Config.h>
#include <yoga/enums/Errata.h>
#include <yoga/enums/NodeType.h>
#include <yoga/node/LayoutResults.h>
#include <yoga/style/CompactValue.h>
Expand Down Expand Up @@ -109,7 +110,7 @@ class YG_EXPORT Node : public ::YGNode {

float baseline(float width, float height) const;

bool hasErrata(YGErrata errata) const {
bool hasErrata(Errata errata) const {
return config_->hasErrata(errata);
}

Expand Down

0 comments on commit b0a16e3

Please sign in to comment.