From ad3a2c68b703fde3f1ebfd0905bf6c0a627a9b90 Mon Sep 17 00:00:00 2001 From: David Hart Date: Mon, 19 Dec 2016 20:09:50 +0100 Subject: [PATCH] transform the Count enum values into private constants --- enums.py | 15 ++++++++++++--- yoga/YGEnums-Private.h | 30 ++++++++++++++++++++++++++++++ yoga/YGEnums.h | 13 ------------- yoga/Yoga.c | 6 +----- 4 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 yoga/YGEnums-Private.h diff --git a/enums.py b/enums.py index d2fc6dc0..e7e7cabf 100644 --- a/enums.py +++ b/enums.py @@ -111,9 +111,9 @@ def to_java_upper(symbol): return out -root = os.path.dirname(__file__) +root = os.path.dirname(os.path.abspath(__file__)) -# write out C header +# write out C headers with open(root + '/yoga/YGEnums.h', 'w') as f: f.write(LICENSE) f.write('#pragma once\n\n') @@ -126,11 +126,20 @@ with open(root + '/yoga/YGEnums.h', 'w') as f: f.write(' YG%s%s = %d,\n' % (name, value[0], value[1])) else: f.write(' YG%s%s,\n' % (name, value)) - f.write(' YG%sCount,\n' % name) f.write('} YG%s;\n' % name) f.write('\n') f.write('YG_EXTERN_C_END\n') +with open(root + '/yoga/YGEnums-Private.h', 'w') as f: + f.write(LICENSE) + f.write('#pragma once\n\n') + f.write('#include "YGMacros.h"\n\n') + f.write('YG_EXTERN_C_BEGIN\n\n') + for name, values in ENUMS.items(): + f.write('#define YG%sCount %s\n' % (name, len(values))) + f.write('\n') + f.write('YG_EXTERN_C_END\n') + # write out java files for name, values in ENUMS.items(): with open(root + '/java/com/facebook/yoga/Yoga%s.java' % name, 'w') as f: diff --git a/yoga/YGEnums-Private.h b/yoga/YGEnums-Private.h new file mode 100644 index 00000000..8ada82b4 --- /dev/null +++ b/yoga/YGEnums-Private.h @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#pragma once + +#include "YGMacros.h" + +YG_EXTERN_C_BEGIN + +#define YGFlexDirectionCount 4 +#define YGMeasureModeCount 3 +#define YGPrintOptionsCount 3 +#define YGEdgeCount 9 +#define YGPositionTypeCount 2 +#define YGDimensionCount 2 +#define YGJustifyCount 5 +#define YGDirectionCount 3 +#define YGLogLevelCount 5 +#define YGWrapCount 2 +#define YGOverflowCount 3 +#define YGExperimentalFeatureCount 2 +#define YGAlignCount 5 + +YG_EXTERN_C_END diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index 85d9d2f9..fd6c8dba 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -18,21 +18,18 @@ typedef enum YGFlexDirection { YGFlexDirectionColumnReverse, YGFlexDirectionRow, YGFlexDirectionRowReverse, - YGFlexDirectionCount, } YGFlexDirection; typedef enum YGMeasureMode { YGMeasureModeUndefined, YGMeasureModeExactly, YGMeasureModeAtMost, - YGMeasureModeCount, } YGMeasureMode; typedef enum YGPrintOptions { YGPrintOptionsLayout = 1, YGPrintOptionsStyle = 2, YGPrintOptionsChildren = 4, - YGPrintOptionsCount, } YGPrintOptions; typedef enum YGEdge { @@ -45,19 +42,16 @@ typedef enum YGEdge { YGEdgeHorizontal, YGEdgeVertical, YGEdgeAll, - YGEdgeCount, } YGEdge; typedef enum YGPositionType { YGPositionTypeRelative, YGPositionTypeAbsolute, - YGPositionTypeCount, } YGPositionType; typedef enum YGDimension { YGDimensionWidth, YGDimensionHeight, - YGDimensionCount, } YGDimension; typedef enum YGJustify { @@ -66,14 +60,12 @@ typedef enum YGJustify { YGJustifyFlexEnd, YGJustifySpaceBetween, YGJustifySpaceAround, - YGJustifyCount, } YGJustify; typedef enum YGDirection { YGDirectionInherit, YGDirectionLTR, YGDirectionRTL, - YGDirectionCount, } YGDirection; typedef enum YGLogLevel { @@ -82,26 +74,22 @@ typedef enum YGLogLevel { YGLogLevelInfo, YGLogLevelDebug, YGLogLevelVerbose, - YGLogLevelCount, } YGLogLevel; typedef enum YGWrap { YGWrapNoWrap, YGWrapWrap, - YGWrapCount, } YGWrap; typedef enum YGOverflow { YGOverflowVisible, YGOverflowHidden, YGOverflowScroll, - YGOverflowCount, } YGOverflow; typedef enum YGExperimentalFeature { YGExperimentalFeatureRounding, YGExperimentalFeatureWebFlexBasis, - YGExperimentalFeatureCount, } YGExperimentalFeature; typedef enum YGAlign { @@ -110,7 +98,6 @@ typedef enum YGAlign { YGAlignCenter, YGAlignFlexEnd, YGAlignStretch, - YGAlignCount, } YGAlign; YG_EXTERN_C_END diff --git a/yoga/Yoga.c b/yoga/Yoga.c index dad81116..0738c894 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -11,6 +11,7 @@ #include "YGNodeList.h" #include "Yoga.h" +#include "YGEnums-Private.h" #ifdef _MSC_VER #include @@ -950,8 +951,6 @@ static void YGConstrainMaxSizeForMode(const float maxSize, YGMeasureMode *mode, *size = maxSize; } break; - case YGMeasureModeCount: - break; } } @@ -1934,7 +1933,6 @@ static void YGNodelayoutImpl(const YGNodeRef node, leadingMainDim = betweenMainDim / 2; break; case YGJustifyFlexStart: - case YGJustifyCount: break; } @@ -2127,7 +2125,6 @@ static void YGNodelayoutImpl(const YGNodeRef node, break; case YGAlignAuto: case YGAlignFlexStart: - case YGAlignCount: break; } @@ -2187,7 +2184,6 @@ static void YGNodelayoutImpl(const YGNodeRef node, break; } case YGAlignAuto: - case YGAlignCount: break; } } -- 2.50.1.windows.1