make static varaibles const via lamdbas

this pr also makes `sfSoundRecorder_getAvailableDevices` return a const pointer to a const char pointer so you can no longer modify where the pointers of the strings are pointing into becuase it doesn't make sense.
This commit is contained in:
ZXShady authored and Chris Thrasher committed 2024-09-28 19:21:25 -06:00
1 parent ef81fbd337
commit f297287951
4 files changed
+16 -18

No files matched your search

+1 -1
View File
@@ -129,7 +129,7 @@ CSFML_AUDIO_API bool sfSoundRecorder_isAvailable(void);
/// \return An array of strings containing the names /// \return An array of strings containing the names
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_AUDIO_API const char** sfSoundRecorder_getAvailableDevices(size_t* count); CSFML_AUDIO_API const char* const* sfSoundRecorder_getAvailableDevices(size_t* count);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the name of the default audio capture device /// \brief Get the name of the default audio capture device
+9 -10
View File
@@ -81,18 +81,17 @@ bool sfSoundRecorder_isAvailable()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const char** sfSoundRecorder_getAvailableDevices(size_t* count) const char* const* sfSoundRecorder_getAvailableDevices(size_t* count)
{ {
static std::vector<std::string> stringDevices = sf::SoundRecorder::getAvailableDevices(); static const auto cstringDevices = []
static std::vector<const char*> cstringDevices;
if (cstringDevices.empty() && !stringDevices.empty())
{ {
static const std::vector<std::string> stringDevices = sf::SoundRecorder::getAvailableDevices();
std::vector<const char*> devices;
devices.reserve(stringDevices.size());
for (const auto& stringDevice : stringDevices) for (const auto& stringDevice : stringDevices)
{ devices.push_back(stringDevice.c_str());
cstringDevices.push_back(stringDevice.c_str()); return devices;
} }();
}
if (count) if (count)
*count = cstringDevices.size(); *count = cstringDevices.size();
@@ -104,7 +103,7 @@ const char** sfSoundRecorder_getAvailableDevices(size_t* count)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const char* sfSoundRecorder_getDefaultDevice() const char* sfSoundRecorder_getDefaultDevice()
{ {
static std::string defaultDevice = sf::SoundRecorder::getDefaultDevice(); static const std::string defaultDevice = sf::SoundRecorder::getDefaultDevice();
return !defaultDevice.empty() ? defaultDevice.c_str() : nullptr; return !defaultDevice.empty() ? defaultDevice.c_str() : nullptr;
} }
+5 -6
View File
@@ -41,14 +41,13 @@ sfVideoMode sfVideoMode_getDesktopMode()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const sfVideoMode* sfVideoMode_getFullscreenModes(size_t* count) const sfVideoMode* sfVideoMode_getFullscreenModes(size_t* count)
{ {
static std::vector<sfVideoMode> modes; static const auto modes = []
// Populate the array on first call
if (modes.empty())
{ {
std::vector<sfVideoMode> videomodes;
for (const auto& mode : sf::VideoMode::getFullscreenModes()) for (const auto& mode : sf::VideoMode::getFullscreenModes())
modes.push_back(convertVideoMode(mode)); videomodes.push_back(convertVideoMode(mode));
} return videomodes;
}();
if (count) if (count)
*count = modes.size(); *count = modes.size();
+1 -1
View File
@@ -52,7 +52,7 @@ sfVulkanFunctionPointer sfVulkan_getFunction(const char* name)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const char* const* sfVulkan_getGraphicsRequiredInstanceExtensions(size_t* count) const char* const* sfVulkan_getGraphicsRequiredInstanceExtensions(size_t* count)
{ {
static std::vector<const char*> extensions = sf::Vulkan::getGraphicsRequiredInstanceExtensions(); static const std::vector<const char*> extensions = sf::Vulkan::getGraphicsRequiredInstanceExtensions();
if (count) if (count)
*count = extensions.size(); *count = extensions.size();