Transform the Count enum values into private constants #292

Closed
hartbit wants to merge 1 commits from private-count into master
4 changed files with 43 additions and 21 deletions

View File

@@ -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:

30
yoga/YGEnums-Private.h Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -11,6 +11,7 @@
#include "YGNodeList.h"
#include "Yoga.h"
#include "YGEnums-Private.h"
#ifdef _MSC_VER
#include <float.h>
@@ -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;
}
}