Implement methods to modify version object in various ways (#2)

* Initial implementation of non-mutable setting and resetting version components.

* Document new functionality in source code and update README.
This commit is contained in:
2017-01-05 21:18:51 +01:00
committed by GitHub
parent 0ca0088ee2
commit f24208aa9f
9 changed files with 683 additions and 76 deletions
+40 -2
View File
@@ -1,5 +1,5 @@
# About
This project is MIT-licensed, C++14 implementation of [semantic versioning](http://semver.org) parser and comparator. Semantic versioning 2.0.0 specification is supported out-of-the-box and the code should be flexible-enough to support future revisions or other similar versioning schemes.
This project is MIT-licensed, C++14 implementation of [semantic versioning](http://semver.org) parser and comparator with support for modifying parsed version strings. Semantic versioning 2.0.0 specification is supported out-of-the-box and the code should be flexible-enough to support future revisions or other similar versioning schemes.
# Usage
Parsing and comparing two version strings:
@@ -42,8 +42,46 @@ Pre-release: alpha.1
Build: build.no.123
```
Parsed version object supports a few modification methods. All modification methods are non-destructive i.e. they return new objects with modified properties and original objects are never changed. You can:
- set major, minor, patch, pre-release or build version to desired value while keeping other fields unchanged;
- reset major, minor, patch, pre-release or build version to desired value by resetting lower-priority fields to zero/empty values (Priority is major > minor > patch > pre-release > build);
- increase/decrease major, minor or patch version by desired increment (can be negative); this is reset-type operation which will zero/empty lower priority fields.
A few examples of version modifications:
```c++
#include "semver200.h"
void main(int, char**) {
version::Semver200_version v("1.2.3-alpha.1+build.no.123");
std::cout << "Next major version: " << v.inc_major() << std::endl;
std::cout << "Next but one major: " << v.inc_major(2) << std::endl;
std::cout << "Next minor version: " << v.inc_minor() << std::endl;
std::cout << "Previous minor version: " << v.inc_minor(-1) << std::endl;
std::cout << "Next patch version: " << v.inc_patch() << std::endl;
std::cout << "Change pre-release: " << v.set_prerelease("beta.3") << std::endl;
std::cout << "Change build: " << v.set_build("170105") << std::endl;
std::cout << "Set major to 3, minor to 1: " << v.set_major(3).set_minor(1) << std::endl;
std::cout << "Reset major to 3, minor to 1: " << v.reset_major(3).reset_minor(1) << std::endl;
}
```
should generate following output:
```
Next major version: 2.0.0
Next but one major: 3.0.0
Next minor version: 1.3.0
Previous minor version: 1.1.0
Next patch version: 1.2.4
Change pre-release: 1.2.3-beta.3+build.no.123
Change build: 1.2.3-alpha.1+170105
Set major to 3, minor to 1: 3.1.3-alpha.1+build.no.123
Reset major to 3, minor to 1: 3.1.0
```
# Build
The code is written in C++14, so, fairly recent compiler is required to build it. Following compiler were tested:
The code is written in C++14, so, fairly recent compiler is required to build it. Following compilers were tested:
- Microsoft Visual Studio 2015
- GCC 5.1.1
- Clang 3.7.0