Skip to content

Commit 941802d

Browse files
authored
feat: add Json::version() to expose runtime version (#1531) (#1678)
This adds a runtime function `Json::version()` that returns the `JSONCPP_VERSION_STRING`. This allows a program using jsoncpp to display the version information of the runtime linked shared library, or check at runtime that the version of the shared library is compatible with what the program expects. Fixes #1531
1 parent 2179730 commit 941802d

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

include/json/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
105105
#endif // if !defined(JSON_IS_AMALGAMATION)
106106

107107
namespace Json {
108+
JSON_API const char* version();
108109
using Int = int;
109110
using UInt = unsigned int;
110111
#if defined(JSON_NO_INT64)

src/lib_json/json_value.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,4 +1704,6 @@ Value& Path::make(Value& root) const {
17041704
return *node;
17051705
}
17061706

1707+
const char* version() { return JSONCPP_VERSION_STRING; }
1708+
17071709
} // namespace Json

src/test_lib_json/main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4188,6 +4188,11 @@ JSONTEST_FIXTURE_LOCAL(VersionTest, VersionNumbersMatch) {
41884188
JSONTEST_ASSERT_EQUAL(vstr.str(), std::string(JSONCPP_VERSION_STRING));
41894189
}
41904190

4191+
JSONTEST_FIXTURE_LOCAL(VersionTest, RuntimeVersionString) {
4192+
JSONTEST_ASSERT_EQUAL(std::string(JSONCPP_VERSION_STRING),
4193+
std::string(Json::version()));
4194+
}
4195+
41914196
#if defined(__GNUC__)
41924197
#pragma GCC diagnostic pop
41934198
#endif

0 commit comments

Comments
 (0)