diff --git a/docs/api/reference.rst b/docs/api/reference.rst index fa1c6772..a8c0d74a 100644 --- a/docs/api/reference.rst +++ b/docs/api/reference.rst @@ -4,6 +4,15 @@ API Reference .. contents:: +Constants +========= + +.. doxygenvariable:: loot::LIBLOOT_VERSION_MAJOR + +.. doxygenvariable:: loot::LIBLOOT_VERSION_MINOR + +.. doxygenvariable:: loot::LIBLOOT_VERSION_PATCH + Enumerations ============ @@ -30,6 +39,10 @@ Functions .. doxygenfunction:: loot::CreateGameHandle +.. doxygenfunction:: loot::GetLiblootVersion + +.. doxygenfunction:: loot::GetLiblootRevision + Interfaces ========== @@ -60,9 +73,6 @@ Classes .. doxygenclass:: loot::Location :members: -.. doxygenclass:: loot::LootVersion - :members: - .. doxygenclass:: loot::MessageContent :members: diff --git a/include/loot/loot_version.h b/include/loot/loot_version.h index d955624b..d7878f81 100644 --- a/include/loot/loot_version.h +++ b/include/loot/loot_version.h @@ -30,30 +30,26 @@ along with LOOT. If not, see #include "loot/api_decorator.h" namespace loot { +/** @brief libloot's major version number. */ +inline constexpr unsigned int LIBLOOT_VERSION_MAJOR = 0; + +/** @brief libloot's minor version number. */ +inline constexpr unsigned int LIBLOOT_VERSION_MINOR = 17; + +/** @brief libloot's patch version number. */ +inline constexpr unsigned int LIBLOOT_VERSION_PATCH = 3; + /** - * @brief A purely static class that provides information about the version of - * libloot that is being run. + * @brief Get the library version. + * @return A string of the form "major.minor.patch". */ -class LootVersion { -public: - /** @brief The major version number. */ - LOOT_API static const unsigned int major; +LOOT_API std::string GetLiblootVersion(); - /** @brief The minor version number. */ - LOOT_API static const unsigned int minor; - - /** @brief The patch version number. */ - LOOT_API static const unsigned int patch; - - /** @brief The source control revision that the API was built from. */ - LOOT_API static const std::string revision; - - /** - * @brief Get the API version as a string. - * @return A string of the form "major.minor.patch". - */ - LOOT_API static std::string GetVersionString(); -}; +/** + * @brief Get the source control revision that libloot was built from. + * @return A string containing the revision ID. + */ +LOOT_API std::string GetLiblootRevision(); } #endif diff --git a/include/loot/metadata/message.h b/include/loot/metadata/message.h index 0ce0a463..645fd72f 100644 --- a/include/loot/metadata/message.h +++ b/include/loot/metadata/message.h @@ -145,7 +145,9 @@ LOOT_API bool operator<=(const Message& lhs, const Message& rhs); LOOT_API bool operator>=(const Message& lhs, const Message& rhs); /** - * Get the message as a SimpleMessage given a language. + * Get a given Message as a SimpleMessage given a language. + * @param message + * The message to convert. * @param language * The preferred language for the message content. * @return A SimpleMessage object for the preferred language, or for English @@ -156,7 +158,9 @@ LOOT_API std::optional ToSimpleMessage( const std::string& language); /** - * Get the messages as SimpleMessages given a language. + * Get the given messages as simple messages given a language. + * @param messages + * The messages to convert. * @param language * The preferred language for the message content. * @return A vector of SimpleMessage objects for the preferred language, or for @@ -165,7 +169,7 @@ LOOT_API std::optional ToSimpleMessage( * without the preferred language or English content will be omitted. */ LOOT_API std::vector ToSimpleMessages( - const std::vector& message, + const std::vector& messages, const std::string& language); } diff --git a/scripts/set_version_number.py b/scripts/set_version_number.py index b53c8753..e452df92 100644 --- a/scripts/set_version_number.py +++ b/scripts/set_version_number.py @@ -20,9 +20,9 @@ def replace_in_file(path, regex, replacement): def update_cpp_file(path, version): version_parts = version.split('.') - replace_in_file(path, 'LootVersion::major = \d+;', 'LootVersion::major = {};'.format(version_parts[0])) - replace_in_file(path, 'LootVersion::minor = \d+;', 'LootVersion::minor = {};'.format(version_parts[1])) - replace_in_file(path, 'LootVersion::patch = \d+;', 'LootVersion::patch = {};'.format(version_parts[2])) + replace_in_file(path, 'LIBLOOT_VERSION_MAJOR = \d+;', 'LIBLOOT_VERSION_MAJOR = {};'.format(version_parts[0])) + replace_in_file(path, 'LIBLOOT_VERSION_MINOR = \d+;', 'LIBLOOT_VERSION_MINOR = {};'.format(version_parts[1])) + replace_in_file(path, 'LIBLOOT_VERSION_PATCH = \d+;', 'LIBLOOT_VERSION_PATCH = {};'.format(version_parts[2])) def update_resource_file(path, version): comma_separated_version = version.replace('.', ', ') @@ -42,5 +42,5 @@ if __name__ == "__main__": if len(arguments.version[0].split('.')) != 3: raise RuntimeError('The version number must be a three-part semantic version.') - update_cpp_file(os.path.join('src', 'api', 'loot_version.cpp.in'), arguments.version[0]) + update_cpp_file(os.path.join('include', 'loot', 'loot_version.h'), arguments.version[0]) update_resource_file(os.path.join('src', 'api', 'resource.rc'), arguments.version[0]) diff --git a/src/api/api.cpp b/src/api/api.cpp index 760a1ba0..59bbe9a1 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -67,9 +67,9 @@ LOOT_API bool IsCompatible(const unsigned int versionMajor, const unsigned int versionMinor, const unsigned int) { if (versionMajor > 0) - return versionMajor == loot::LootVersion::major; + return versionMajor == LIBLOOT_VERSION_MAJOR; else - return versionMinor == loot::LootVersion::minor; + return versionMinor == LIBLOOT_VERSION_MINOR; } LOOT_API std::unique_ptr CreateGameHandle( diff --git a/src/api/loot_version.cpp.in b/src/api/loot_version.cpp.in index be14df90..67978063 100644 --- a/src/api/loot_version.cpp.in +++ b/src/api/loot_version.cpp.in @@ -25,12 +25,15 @@ #include "loot/loot_version.h" namespace loot { -const unsigned int LootVersion::major = 0; -const unsigned int LootVersion::minor = 17; -const unsigned int LootVersion::patch = 3; -const std::string LootVersion::revision = "@GIT_COMMIT_STRING@"; +LOOT_API std::string GetLiblootVersion() { + static const std::string version = + std::to_string(LIBLOOT_VERSION_MAJOR) + '.' + + std::to_string(LIBLOOT_VERSION_MINOR) + '.' + + std::to_string(LIBLOOT_VERSION_PATCH); + return version; +} -LOOT_API std::string LootVersion::GetVersionString() { - return std::to_string(major) + '.' + std::to_string(minor) + '.' + std::to_string(patch); +LOOT_API std::string GetLiblootRevision() { + return "@GIT_COMMIT_STRING@"; } } diff --git a/src/tests/api/interface/is_compatible_test.h b/src/tests/api/interface/is_compatible_test.h index 2c20b644..30a48411 100644 --- a/src/tests/api/interface/is_compatible_test.h +++ b/src/tests/api/interface/is_compatible_test.h @@ -34,13 +34,26 @@ namespace test { TEST(IsCompatible, shouldReturnTrueWithEqualMajorAndMinorVersionsAndUnequalPatchVersion) { EXPECT_TRUE(IsCompatible( - LootVersion::major, LootVersion::minor, LootVersion::patch + 1)); + LIBLOOT_VERSION_MAJOR, LIBLOOT_VERSION_MINOR, LIBLOOT_VERSION_PATCH)); } TEST(IsCompatible, shouldReturnFalseWithEqualMajorVersionAndUnequalMinorAndPatchVersions) { - EXPECT_FALSE(IsCompatible( - LootVersion::major, LootVersion::minor + 1, LootVersion::patch + 1)); + EXPECT_FALSE(IsCompatible(LIBLOOT_VERSION_MAJOR, + LIBLOOT_VERSION_MINOR + 1, + LIBLOOT_VERSION_PATCH + 1)); +} + +TEST(GetLiblootRevision, shouldReturnANonEmptyString) { + EXPECT_FALSE(GetLiblootRevision().empty()); +} + +TEST(GetVersion, shouldConcatenateMajorMinorAndPatchVersionNumbersWithPeriods) { + auto expectedVersion = std::to_string(LIBLOOT_VERSION_MAJOR) + "." + + std::to_string(LIBLOOT_VERSION_MINOR) + "." + + std::to_string(LIBLOOT_VERSION_PATCH); + + EXPECT_EQ(expectedVersion, GetLiblootVersion()); } } }