semver-utils  1.1.1
version.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Enrico M. Crisostomo
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 3, or (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program. If not, see <http://www.gnu.org/licenses/>.
15  */
28 #ifndef SEMVER_UTILS_VERSION_H
29 #define SEMVER_UTILS_VERSION_H
30 
31 #include <vector>
32 #include <string>
33 
34 #pragma clang diagnostic push
35 #pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
36 
40 namespace semver
41 {
49  {
50  private:
54  bool is_number;
55 
59  std::string identifier;
60 
66  unsigned long value_as_number;
67 
68  public:
69  prerelease_component(std::string s);
70  bool operator<(const prerelease_component& rh) const;
71  bool operator>(const prerelease_component& rh) const;
72  bool operator==(const prerelease_component& v) const;
73  };
74 
84  class version
85  {
86  private:
87  std::vector<unsigned int> versions;
88  std::string prerelease;
89  std::vector<prerelease_component> prerelease_comp;
90  std::string metadata;
91 
92  void parse_prerelease();
93 
94  public:
106  static version from_string(std::string v);
107 
121  version(const std::vector<unsigned int> versions,
122  const std::string prerelease = "",
123  const std::string metadata = "");
124 
130  std::string str() const;
131 
137  std::vector<unsigned int> get_version() const;
138 
145  unsigned int get_version(unsigned int index) const;
146 
152  std::string get_prerelease() const;
153 
159  std::string get_metadata() const;
160 
168  version bump_major() const;
169 
177  version bump_minor() const;
178 
186  version bump_patch() const;
187 
198  version bump(unsigned int index) const;
199 
205  version strip_prerelease() const;
206 
212  version strip_metadata() const;
213 
220  bool is_release() const;
221 
230  bool operator==(const version& rh) const;
231 
244  bool operator<(const version& rh) const;
245 
258  bool operator>(const version& rh) const;
259  };
260 }
261 
262 #endif // SEMVER_UTILS_VERSION_H
263 
264 #pragma clang diagnostic pop
version bump_patch() const
Bumps the patch version component.
Definition: version.cpp:221
version strip_prerelease() const
Strips the prerelease component.
Definition: version.cpp:263
bool operator==(const version &rh) const
Checks two instances for equality.
Definition: version.cpp:278
version bump_major() const
Bumps the major version component.
Definition: version.cpp:211
static version from_string(std::string v)
Constructs a semver::version instance from a std::string.
Definition: version.cpp:118
bool operator<(const version &rh) const
Compares two instances.
Definition: version.cpp:283
std::string get_prerelease() const
Gets the prerelease string.
Definition: version.cpp:253
bool operator>(const version &rh) const
Compares two instances.
Definition: version.cpp:298
std::string str() const
Converts a version to its string representation.
Definition: version.cpp:186
version(const std::vector< unsigned int > versions, const std::string prerelease="", const std::string metadata="")
Constructs a semver::version instance with the specified parameters. The parameters must comply with ...
Definition: version.cpp:164
version bump_minor() const
Bumps the minor version component.
Definition: version.cpp:216
std::vector< unsigned int > get_version() const
Gets the version components.
Definition: version.cpp:248
version strip_metadata() const
Strips the metadata component.
Definition: version.cpp:268
std::string get_metadata() const
Gets the metadata string.
Definition: version.cpp:258
Class that represents a prerelease identifier.
Definition: version.hpp:48
bool is_release() const
Checks whether the instance is a release version.
Definition: version.cpp:273
Class that represents a version number.
Definition: version.hpp:84
version bump(unsigned int index) const
Bumps the specified version component.
Definition: version.cpp:226
Main namespace of libsemver.
Definition: version.cpp:80