diff --git a/CMakeLists.txt b/CMakeLists.txt index 762bb971..ef7efaf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,8 @@ c4_add_library(ryml c4/yml/tag.cpp c4/yml/tree.hpp c4/yml/tree.cpp + c4/yml/version.hpp + c4/yml/version.cpp c4/yml/writer.hpp c4/yml/yml.hpp ryml.natvis diff --git a/changelog/current.md b/changelog/current.md index 08c4eb7e..b73e3a85 100644 --- a/changelog/current.md +++ b/changelog/current.md @@ -1,3 +1,17 @@ +## New features + +- [PR#459](https://github.com/biojppm/rapidyaml/pull/459): Add version functions and macros: + ```cpp + #define RYML_VERSION "0.7.1" + #define RYML_VERSION_MAJOR 0 + #define RYML_VERSION_MINOR 7 + #define RYML_VERSION_PATCH 1 + csubstr version(); + int version_major(); + int version_minor(); + int version_patch(); + ``` + ## Fixes - Fix [#455](https://github.com/biojppm/rapidyaml/issues/455): parsing of trailing val-less nested maps when deindented to maps ([PR#460](https://github.com/biojppm/rapidyaml/pull/460)) @@ -15,6 +29,7 @@ ## Thanks +- @marcalff - @toge - @musicinmybrain - @buty4649 diff --git a/src/c4/yml/version.cpp b/src/c4/yml/version.cpp new file mode 100644 index 00000000..c54c1f4f --- /dev/null +++ b/src/c4/yml/version.cpp @@ -0,0 +1,27 @@ +#include "c4/yml/version.hpp" + +namespace c4 { +namespace yml { + +csubstr version() +{ + return RYML_VERSION; +} + +int version_major() +{ + return RYML_VERSION_MAJOR; +} + +int version_minor() +{ + return RYML_VERSION_MINOR; +} + +int version_patch() +{ + return RYML_VERSION_PATCH; +} + +} // namespace yml +} // namespace c4 diff --git a/src/c4/yml/version.hpp b/src/c4/yml/version.hpp new file mode 100644 index 00000000..3057b79c --- /dev/null +++ b/src/c4/yml/version.hpp @@ -0,0 +1,25 @@ +#ifndef _C4_YML_VERSION_HPP_ +#define _C4_YML_VERSION_HPP_ + +/** @file version.hpp */ + +#define RYML_VERSION "0.7.0" +#define RYML_VERSION_MAJOR 0 +#define RYML_VERSION_MINOR 7 +#define RYML_VERSION_PATCH 0 + +#include +#include + +namespace c4 { +namespace yml { + +RYML_EXPORT csubstr version(); +RYML_EXPORT int version_major(); +RYML_EXPORT int version_minor(); +RYML_EXPORT int version_patch(); + +} // namespace yml +} // namespace c4 + +#endif /* _C4_YML_VERSION_HPP_ */ diff --git a/src/c4/yml/yml.hpp b/src/c4/yml/yml.hpp index dcd7c18d..0f997246 100644 --- a/src/c4/yml/yml.hpp +++ b/src/c4/yml/yml.hpp @@ -1,6 +1,7 @@ #ifndef _C4_YML_YML_HPP_ #define _C4_YML_YML_HPP_ +#include "c4/yml/version.hpp" #include "c4/yml/tree.hpp" #include "c4/yml/node.hpp" #include "c4/yml/emit.hpp" diff --git a/tbump.toml b/tbump.toml index a7751f39..c59b3db9 100644 --- a/tbump.toml +++ b/tbump.toml @@ -49,7 +49,21 @@ search = ".*{current_version}.*" [[file]] src = "doc/sphinx_*.rst" search = ".*{current_version}.*" - +[[file]] +src = "src/c4/yml/version.hpp" +search = "#define RYML_VERSION ['\"]{current_version}['\"]" +[[file]] +src = "src/c4/yml/version.hpp" +version_template = "{major}" +search = "#define RYML_VERSION_MAJOR {current_version}" +[[file]] +src = "src/c4/yml/version.hpp" +version_template = "{minor}" +search = "#define RYML_VERSION_MINOR {current_version}" +[[file]] +src = "src/c4/yml/version.hpp" +version_template = "{patch}" +search = "#define RYML_VERSION_PATCH {current_version}" # You can specify a list of commands to # run after the files have been patched diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f4908326..e5cad7ef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -79,6 +79,7 @@ ryml_add_engine_test(parse_engine_6_qmrk) ryml_add_engine_test(parse_engine_7_seqimap) ryml_add_engine_test(parse_engine_8_scalars_tokens) ryml_add_engine_test(yaml_events) +ryml_add_test(version) ryml_add_test(callbacks) ryml_add_test(stack) ryml_add_test(filter) diff --git a/test/test_version.cpp b/test/test_version.cpp new file mode 100644 index 00000000..60cef79a --- /dev/null +++ b/test/test_version.cpp @@ -0,0 +1,29 @@ +#ifndef RYML_SINGLE_HEADER +#include "c4/yml/version.hpp" +#endif +#include "./test_lib/test_case.hpp" +#include + +TEST(version, str) +{ + c4::csubstr v = c4::yml::version(); + EXPECT_GE(v.len, 5); +} + +TEST(version, major) +{ + int v = c4::yml::version_major(); + EXPECT_GE(v, 0); +} + +TEST(version, minor) +{ + int v = c4::yml::version_minor(); + EXPECT_GE(v, 0); +} + +TEST(version, patch) +{ + int v = c4::yml::version_patch(); + EXPECT_GE(v, 0); +} diff --git a/tools/amalgamate.py b/tools/amalgamate.py index 9ace1a9b..4f8c761d 100644 --- a/tools/amalgamate.py +++ b/tools/amalgamate.py @@ -87,6 +87,7 @@ def amalgamate_ryml(filename: str, am.onlyif(with_c4core, c4core_amalgamated), "src/c4/yml/export.hpp", "src/c4/yml/fwd.hpp", + "src/c4/yml/version.hpp", "src/c4/yml/common.hpp", "src/c4/yml/node_type.hpp", "src/c4/yml/tag.hpp", @@ -110,6 +111,7 @@ def amalgamate_ryml(filename: str, am.onlyif(with_stl, "src/c4/yml/std/string.hpp"), am.onlyif(with_stl, "src/c4/yml/std/vector.hpp"), am.onlyif(with_stl, "src/c4/yml/std/std.hpp"), + "src/c4/yml/version.cpp", "src/c4/yml/common.cpp", "src/c4/yml/node_type.cpp", "src/c4/yml/tag.cpp",