[#291] Make the version number comparable #294
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Three new constants are introduced here:
that represent, as integer literals and string composition,
the parts of the version number.
The values are copied from the variables in the
CmakeLists.txt
filethat creates the building flow, so changing the values in a single
place changes and propagates the changes all over the source code.
A few utility functions have been introduced to compose the three
constant into a unique number that can be used to compare the version
currently running, so that features and/or message can be targeted as
conditionals.
Introduced functions are:
number. For example, version 1.5.0 is returned as 15000, version 1.6.2
as 16002, and so on;
number, that is invokes pgagroal_version_as_number() with the
predefined constants.
The
pgagroal_version_as_number()
accepts individual values, whilepgagroal_version_number()
provides the currently running versionnumber. The idea is that, thanks to both the functions, it is possible
to check for a feature that depends on a version in a way like the
following one:
if (pgagroal_version_numer() >=
pgagroal_version_as_number(2,1,0))
// version is greater than 2.1.0 !
The utility function
pgagroal_version_ge()
does exactly the above:it accepts the three parts of a version number and checks if the
currently running version is greater or equal (hence, 'ge') of the
specified triplet, so that the above piece of code becomes:
if (pgagroal_version_ge(2,1,0))
// version greater or equal 2.1.0
Close #292
See #253, #289, #290, #293