Browse Source

Squelches warnings for switch statements that do not contain case statements for all values of an enumeration because some of the enumeration values do not apply.

David Wimsey 11 years ago
parent
commit
06ebf81d6b

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

@@ -75,4 +75,11 @@
 
 #define ROCKET_UNUSED(x)
 
+// 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

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

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

+ 1 - 0
Source/Core/WidgetSlider.cpp

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