Browse Source

Merge pull request #153 from dwimsey/feature/warningfix-unhandled-switch-enums

Squelches warnings for switch statements that do not contain case statements
David Wimsey 11 years ago
parent
commit
dc18fb6b48

+ 7 - 0
Include/Rocket/Core/Platform.h

@@ -128,4 +128,11 @@
 #  define ROCKET_UNUSED_FUNCTION(x) UNUSED_ ## x
 #  define ROCKET_UNUSED_FUNCTION(x) UNUSED_ ## x
 #endif
 #endif
 
 
+// Squelchs warnings for unused enums in switch statements, this should only be used for special values
+// that are known to NEVER be used.
+#define ROCKET_UNUSED_SWITCH_ENUM(x) \
+  case x: \
+    ROCKET_ERRORMSG("Switch case for unhandled ENUM has been hit!  This shouldn't happen!  ENUM Name: " # x); \
+    break;
+
 #endif
 #endif

+ 3 - 0
Samples/invaders/src/Invader.cpp

@@ -228,6 +228,7 @@ bool Invader::CheckHit(const Rocket::Core::Vector2f& check_position)
 		int score = 0;
 		int score = 0;
 		switch (type)
 		switch (type)
 		{
 		{
+			ROCKET_UNUSED_SWITCH_ENUM(UNKNOWN);
 			case MOTHERSHIP: score = (Rocket::Core::Math::RandomInteger(6) + 1) * 50; break;	// 50 -> 300
 			case MOTHERSHIP: score = (Rocket::Core::Math::RandomInteger(6) + 1) * 50; break;	// 50 -> 300
 			case RANK3: score = 40; break;
 			case RANK3: score = 40; break;
 			case RANK2: score = 20; break;
 			case RANK2: score = 20; break;
@@ -253,6 +254,8 @@ int Invader::GetSpriteIndex() const
 	int index = animation_frame;
 	int index = animation_frame;
 	switch (type)
 	switch (type)
 	{
 	{
+		ROCKET_UNUSED_SWITCH_ENUM(UNKNOWN);
+		case RANK1: break;	// animation_frame is the right index already
 		case RANK2:	index += 2; break;
 		case RANK2:	index += 2; break;
 		case RANK3:	index += 4; break;
 		case RANK3:	index += 4; break;
 		case MOTHERSHIP: index = 6; break;
 		case MOTHERSHIP: index = 6; break;

+ 3 - 0
Samples/pyinvaders/src/Invader.cpp

@@ -228,6 +228,7 @@ bool Invader::CheckHit(const Rocket::Core::Vector2f& check_position)
 		int score = 0;
 		int score = 0;
 		switch (type)
 		switch (type)
 		{
 		{
+			ROCKET_UNUSED_SWITCH_ENUM(UNKNOWN);
 			case MOTHERSHIP: score = (Rocket::Core::Math::RandomInteger(6) + 1) * 50; break;	// 50 -> 300
 			case MOTHERSHIP: score = (Rocket::Core::Math::RandomInteger(6) + 1) * 50; break;	// 50 -> 300
 			case RANK3: score = 40; break;
 			case RANK3: score = 40; break;
 			case RANK2: score = 20; break;
 			case RANK2: score = 20; break;
@@ -253,6 +254,8 @@ int Invader::GetSpriteIndex() const
 	int index = animation_frame;
 	int index = animation_frame;
 	switch (type)
 	switch (type)
 	{
 	{
+		ROCKET_UNUSED_SWITCH_ENUM(UNKNOWN);
+		case RANK1: break;	// animation_frame is the right index already
 		case RANK2:	index += 2; break;
 		case RANK2:	index += 2; break;
 		case RANK3:	index += 4; break;
 		case RANK3:	index += 4; break;
 		case MOTHERSHIP: index = 6; break;
 		case MOTHERSHIP: index = 6; break;

+ 7 - 0
Source/Core/ElementUtilities.cpp

@@ -146,6 +146,13 @@ int ElementUtilities::GetLineHeight(Element* element)
 
 
 	switch (line_height_property->unit)
 	switch (line_height_property->unit)
 	{
 	{
+	ROCKET_UNUSED_SWITCH_ENUM(Property::UNKNOWN);
+	ROCKET_UNUSED_SWITCH_ENUM(Property::KEYWORD);
+	ROCKET_UNUSED_SWITCH_ENUM(Property::STRING);
+	ROCKET_UNUSED_SWITCH_ENUM(Property::COLOUR);
+	ROCKET_UNUSED_SWITCH_ENUM(Property::ABSOLUTE_UNIT);
+	ROCKET_UNUSED_SWITCH_ENUM(Property::PPI_UNIT);
+	ROCKET_UNUSED_SWITCH_ENUM(Property::RELATIVE_UNIT);
 	case Property::NUMBER:
 	case Property::NUMBER:
 	case Property::EM:
 	case Property::EM:
 		// If the property is a straight number or an em measurement, then it scales the line height.
 		// If the property is a straight number or an em measurement, then it scales the line height.

+ 1 - 0
Source/Core/StyleSheetNode.cpp

@@ -397,6 +397,7 @@ void StyleSheetNode::GetApplicableDescendants(std::vector< const StyleSheetNode*
 	// Check if this node matches this element.
 	// Check if this node matches this element.
 	switch (type)
 	switch (type)
 	{
 	{
+		ROCKET_UNUSED_SWITCH_ENUM(NUM_NODE_TYPES);
 		case ROOT:
 		case ROOT:
 		case TAG:
 		case TAG:
 		{
 		{

+ 1 - 0
Source/Core/WidgetSlider.cpp

@@ -213,6 +213,7 @@ void WidgetSlider::GetDimensions(Vector2f& dimensions) const
 {
 {
 	switch (orientation)
 	switch (orientation)
 	{
 	{
+		ROCKET_UNUSED_SWITCH_ENUM(UNKNOWN);
 		case VERTICAL:		dimensions.x = 256; dimensions.y = 16; break;
 		case VERTICAL:		dimensions.x = 256; dimensions.y = 16; break;
 		case HORIZONTAL:	dimensions.x = 16; dimensions.y = 256; break;
 		case HORIZONTAL:	dimensions.x = 16; dimensions.y = 256; break;
 	}
 	}