Skip to content

Commit 884dcde

Browse files
ZXShadyChrisThrasher
authored andcommitted
Make enumeration counts constant expressions
This change allows now having these variables as array sizes that are not Variable Length Arrays like in structs for example. To note however that this changes the type from unsigned int to an implementation defined type which usually `int` which is signed and not unsigned.
1 parent cc92ca3 commit 884dcde

File tree

9 files changed

+20
-24
lines changed

9 files changed

+20
-24
lines changed

include/CSFML/Window/Keyboard.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ typedef enum
144144
sfKeyPause, ///< The Pause key
145145
} sfKeyCode;
146146

147-
CSFML_WINDOW_API const unsigned int sfKeyCount; ///< The total number of keyboard keys
148-
147+
enum
148+
{
149+
sfKeyCount = sfKeyPause + 1 ///< The total number of keyboard keys
150+
};
149151

150152
////////////////////////////////////////////////////////////
151153
/// \brief Scancodes
@@ -312,8 +314,10 @@ typedef enum
312314
sfScanLaunchMediaSelect, //!< Keyboard Launch Media Select key
313315
} sfScancode;
314316

315-
CSFML_WINDOW_API const unsigned int sfScancodeCount; //!< The total number of scancodes
316-
317+
enum
318+
{
319+
sfScancodeCount = sfScanLaunchMediaSelect + 1 //!< The total number of scancodes
320+
};
317321

318322
////////////////////////////////////////////////////////////
319323
/// \brief Check if a key is pressed

include/CSFML/Window/Mouse.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ typedef enum
4646
sfMouseButtonExtra2, ///< The second extra mouse button
4747
} sfMouseButton;
4848

49-
CSFML_WINDOW_API const unsigned int sfMouseButtonCount; ///< The total number of mouse buttons
49+
enum
50+
{
51+
sfMouseButtonCount = sfMouseButtonExtra2 + 1 ///< The total number of mouse buttons
52+
};
5053

5154
////////////////////////////////////////////////////////////
5255
/// \brief Mouse wheels

include/CSFML/Window/Sensor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ typedef enum
4747
sfSensorOrientation, ///< Measures the absolute 3D orientation (degrees)
4848
} sfSensorType;
4949

50-
CSFML_WINDOW_API const unsigned int sfSensorCount; ///< The total number of sensor types
51-
50+
enum
51+
{
52+
sfSensorCount = sfSensorOrientation + 1 ///< The total number of sensor types
53+
};
5254

5355
////////////////////////////////////////////////////////////
5456
/// \brief Check if a sensor is available on the underlying platform

src/CSFML/Window/Keyboard.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333
#include <cstring>
3434

3535

36-
////////////////////////////////////////////////////////////
37-
const unsigned int sfKeyCount = sfKeyPause + 1;
38-
const unsigned int sfScancodeCount = sfScanLaunchMediaSelect + 1;
39-
40-
4136
////////////////////////////////////////////////////////////
4237
bool sfKeyboard_isKeyPressed(sfKeyCode key)
4338
{

src/CSFML/Window/Mouse.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
#include <SFML/Window/Mouse.hpp>
3434

3535

36-
////////////////////////////////////////////////////////////
37-
const unsigned int sfMouseButtonCount = sfMouseButtonExtra2 + 1;
38-
39-
4036
////////////////////////////////////////////////////////////
4137
bool sfMouse_isButtonPressed(sfMouseButton button)
4238
{

src/CSFML/Window/Sensor.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
#include <SFML/Window/Sensor.hpp>
3232

3333

34-
////////////////////////////////////////////////////////////
35-
const unsigned int sfSensorCount = sfSensorOrientation + 1;
36-
37-
3834
////////////////////////////////////////////////////////////
3935
bool sfSensor_isAvailable(sfSensorType sensor)
4036
{

test/Window/Keyboard.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TEST_CASE("[Window] sfKeyboard")
1414
STATIC_CHECK(sfKeyC == static_cast<int>(sf::Keyboard::Key::C));
1515
STATIC_CHECK(sfKeyD == static_cast<int>(sf::Keyboard::Key::D));
1616
STATIC_CHECK(sfKeyPause == static_cast<int>(sf::Keyboard::Key::Pause));
17-
CHECK(sfKeyCount == sf::Keyboard::KeyCount);
17+
STATIC_CHECK(sfKeyCount == sf::Keyboard::KeyCount);
1818
}
1919

2020
SECTION("sfScancode")
@@ -24,6 +24,6 @@ TEST_CASE("[Window] sfKeyboard")
2424
STATIC_CHECK(sfScanB == static_cast<int>(sf::Keyboard::Scan::B));
2525
STATIC_CHECK(sfScanC == static_cast<int>(sf::Keyboard::Scan::C));
2626
STATIC_CHECK(sfScanD == static_cast<int>(sf::Keyboard::Scan::D));
27-
CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount);
27+
STATIC_CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount);
2828
}
2929
}

test/Window/Mouse.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ TEST_CASE("[Window] sfMouse")
1313
STATIC_CHECK(sfMouseMiddle == static_cast<int>(sf::Mouse::Button::Middle));
1414
STATIC_CHECK(sfMouseButtonExtra1 == static_cast<int>(sf::Mouse::Button::Extra1));
1515
STATIC_CHECK(sfMouseButtonExtra2 == static_cast<int>(sf::Mouse::Button::Extra2));
16-
CHECK(sfMouseButtonCount == sf::Mouse::ButtonCount);
16+
STATIC_CHECK(sfMouseButtonCount == sf::Mouse::ButtonCount);
1717
}
1818

1919
SECTION("sfMouseWheel")

test/Window/Sensor.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ TEST_CASE("[Window] sfSensor")
1414
STATIC_CHECK(sfSensorGravity == static_cast<int>(sf::Sensor::Type::Gravity));
1515
STATIC_CHECK(sfSensorUserAcceleration == static_cast<int>(sf::Sensor::Type::UserAcceleration));
1616
STATIC_CHECK(sfSensorOrientation == static_cast<int>(sf::Sensor::Type::Orientation));
17-
CHECK(sfSensorCount == sf::Sensor::Count);
17+
STATIC_CHECK(sfSensorCount == sf::Sensor::Count);
1818
}
1919
}

0 commit comments

Comments
 (0)