mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-27 05:26:13 +01:00
Add sfGetVersion to retrieve the runtime SFML version
This commit is contained in:
6 files changed
+124
No files matched your search
@@ -37,3 +37,4 @@
|
||||
#include <CSFML/System/Time.h>
|
||||
#include <CSFML/System/Vector2.h>
|
||||
#include <CSFML/System/Vector3.h>
|
||||
#include <CSFML/System/Version.h>
|
||||
@@ -0,0 +1,64 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/System/Export.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Version information of the SFML library
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{
|
||||
int8_t major; ///< SFML major version
|
||||
int8_t minor; ///< SFML minor version
|
||||
int8_t patch; ///< SFML patch version
|
||||
bool isRelease; ///< true if this is a release version, false if this is a development version
|
||||
const char* string; ///< String representation of the SFML version, e.g. 3.1.0 or 3.1.0-dev
|
||||
} sfVersion;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the version of the SFML library loaded at runtime
|
||||
///
|
||||
/// This is the version of the SFML library CSFML is linked
|
||||
/// against at runtime, which can differ from the version
|
||||
/// CSFML was compiled with (see CSFML_VERSION_MAJOR,
|
||||
/// CSFML_VERSION_MINOR and CSFML_VERSION_PATCH).
|
||||
///
|
||||
/// The returned string is owned by SFML and stays valid
|
||||
/// for the whole lifetime of the program.
|
||||
///
|
||||
/// \return Version information of the SFML library
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
CSFML_SYSTEM_API sfVersion sfGetVersion(void);
|
||||
@@ -23,6 +23,8 @@ set(SRC
|
||||
${INCROOT}/Types.h
|
||||
${INCROOT}/Vector2.h
|
||||
${INCROOT}/Vector3.h
|
||||
${SRCROOT}/Version.cpp
|
||||
${INCROOT}/Version.h
|
||||
)
|
||||
|
||||
# define the csfml-system target
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <CSFML/System/Version.h>
|
||||
|
||||
#include <SFML/System/Version.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sfVersion sfGetVersion()
|
||||
{
|
||||
const auto& version = sf::version();
|
||||
static const std::string string(version.string);
|
||||
return {version.major, version.minor, version.patch, version.isRelease, string.c_str()};
|
||||
}
|
||||
@@ -27,6 +27,7 @@ add_executable(test-csfml-system
|
||||
System/Time.test.cpp
|
||||
System/Vector2.test.cpp
|
||||
System/Vector3.test.cpp
|
||||
System/Version.test.cpp
|
||||
)
|
||||
target_link_libraries(test-csfml-system PRIVATE csfml-system Catch2::Catch2WithMain)
|
||||
set_target_warnings(test-csfml-system)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include <CSFML/System/Version.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("[System] sfGetVersion")
|
||||
{
|
||||
const sfVersion version = sfGetVersion();
|
||||
CHECK(version.major == 3);
|
||||
CHECK(version.minor >= 1);
|
||||
CHECK(version.patch >= 0);
|
||||
REQUIRE(version.string != nullptr);
|
||||
CHECK(std::string(version.string).rfind(std::to_string(version.major) + "." + std::to_string(version.minor), 0) == 0);
|
||||
}
|
||||
Reference in new issue
Block a user