Skip to content

Commit

Permalink
C++ style enums 3/N: ExperimentalFeature
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#39448

X-link: facebook/yoga#1386

This converts usages of YGExperimentalFeature to ExperimentalFeature

Reviewed By: rozele

Differential Revision: D49269440

fbshipit-source-id: 0fcb4f380e214a6aadcac457df5a989789bb05d2
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 15, 2023
1 parent defc79e commit 75d2907
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 39 deletions.
5 changes: 3 additions & 2 deletions lib/yoga/src/main/cpp/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,14 @@ void YGConfigSetExperimentalFeatureEnabled(
const YGConfigRef config,
const YGExperimentalFeature feature,
const bool enabled) {
resolveRef(config)->setExperimentalFeatureEnabled(feature, enabled);
resolveRef(config)->setExperimentalFeatureEnabled(
scopedEnum(feature), enabled);
}

bool YGConfigIsExperimentalFeatureEnabled(
const YGConfigConstRef config,
const YGExperimentalFeature feature) {
return resolveRef(config)->isExperimentalFeatureEnabled(feature);
return resolveRef(config)->isExperimentalFeatureEnabled(scopedEnum(feature));
}

void YGConfigSetUseWebDefaults(const YGConfigRef config, const bool enabled) {
Expand Down
8 changes: 4 additions & 4 deletions lib/yoga/src/main/cpp/yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static void computeFlexBasisForChild(
if (!resolvedFlexBasis.isUndefined() && !yoga::isUndefined(mainAxisSize)) {
if (child->getLayout().computedFlexBasis.isUndefined() ||
(child->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureWebFlexBasis) &&
ExperimentalFeature::WebFlexBasis) &&
child->getLayout().computedFlexBasisGeneration != generationCount)) {
const FloatOptional paddingAndBorder =
FloatOptional(paddingAndBorderForAxis(child, mainAxis, ownerWidth));
Expand Down Expand Up @@ -479,7 +479,7 @@ static void layoutAbsoluteChild(
leadingEdge(mainAxis));
} else if (
node->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) &&
child->isLeadingPositionDefined(mainAxis)) {
child->setLayoutPosition(
child->getLeadingPosition(
Expand Down Expand Up @@ -526,7 +526,7 @@ static void layoutAbsoluteChild(
leadingEdge(crossAxis));
} else if (
node->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge) &&
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge) &&
child->isLeadingPositionDefined(crossAxis)) {
child->setLayoutPosition(
child->getLeadingPosition(
Expand Down Expand Up @@ -2323,7 +2323,7 @@ static void calculateLayoutImpl(
}
const bool absolutePercentageAgainstPaddingEdge =
node->getConfig()->isExperimentalFeatureEnabled(
YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge);
ExperimentalFeature::AbsolutePercentageAgainstPaddingEdge);

layoutAbsoluteChild(
node,
Expand Down
19 changes: 0 additions & 19 deletions lib/yoga/src/main/cpp/yoga/bits/EnumBitset.h

This file was deleted.

10 changes: 5 additions & 5 deletions lib/yoga/src/main/cpp/yoga/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ bool Config::shouldPrintTree() const {
}

void Config::setExperimentalFeatureEnabled(
YGExperimentalFeature feature,
ExperimentalFeature feature,
bool enabled) {
experimentalFeatures_.set(feature, enabled);
experimentalFeatures_.set(static_cast<size_t>(feature), enabled);
}

bool Config::isExperimentalFeatureEnabled(YGExperimentalFeature feature) const {
return experimentalFeatures_.test(feature);
bool Config::isExperimentalFeatureEnabled(ExperimentalFeature feature) const {
return experimentalFeatures_.test(static_cast<size_t>(feature));
}

EnumBitset<YGExperimentalFeature> Config::getEnabledExperiments() const {
ExperimentalFeatureSet Config::getEnabledExperiments() const {
return experimentalFeatures_;
}

Expand Down
16 changes: 9 additions & 7 deletions lib/yoga/src/main/cpp/yoga/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

#pragma once

#include <bitset>

#include <yoga/Yoga.h>
#include <yoga/bits/EnumBitset.h>
#include <yoga/enums/ExperimentalFeature.h>

// Tag struct used to form the opaque YGConfigRef for the public C API
struct YGConfig {};
Expand All @@ -18,6 +20,8 @@ namespace facebook::yoga {
class Config;
class Node;

using ExperimentalFeatureSet = std::bitset<ordinalCount<ExperimentalFeature>()>;

// Whether moving a node from an old to new config should dirty previously
// calculated layout results.
bool configUpdateInvalidatesLayout(
Expand All @@ -43,11 +47,9 @@ class YG_EXPORT Config : public ::YGConfig {
void setShouldPrintTree(bool printTree);
bool shouldPrintTree() const;

void setExperimentalFeatureEnabled(
YGExperimentalFeature feature,
bool enabled);
bool isExperimentalFeatureEnabled(YGExperimentalFeature feature) const;
EnumBitset<YGExperimentalFeature> getEnabledExperiments() const;
void setExperimentalFeatureEnabled(ExperimentalFeature feature, bool enabled);
bool isExperimentalFeatureEnabled(ExperimentalFeature feature) const;
ExperimentalFeatureSet getEnabledExperiments() const;

void setErrata(YGErrata errata);
void addErrata(YGErrata errata);
Expand Down Expand Up @@ -79,7 +81,7 @@ class YG_EXPORT Config : public ::YGConfig {
YGLogger logger_;

ConfigFlags flags_{};
EnumBitset<YGExperimentalFeature> experimentalFeatures_{};
ExperimentalFeatureSet experimentalFeatures_{};
YGErrata errata_ = YGErrataNone;
float pointScaleFactor_ = 1.0f;
void* context_ = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions lib/yoga/src/main/cpp/yoga/enums/YogaEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
namespace facebook::yoga {

template <typename EnumT>
constexpr inline int32_t ordinalCount() = delete;
constexpr inline int32_t ordinalCount();

template <typename EnumT>
constexpr inline int32_t bitCount() = delete;
constexpr inline int32_t bitCount();

} // namespace facebook::yoga

0 comments on commit 75d2907

Please sign in to comment.