SemanticVersion.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef IGNITION_MATH_SEMANTICVERSION_HH_
19 #define IGNITION_MATH_SEMANTICVERSION_HH_
20 
21 #include <memory>
22 #include <string>
23 #include <ignition/math/Helpers.hh>
24 #include <ignition/math/config.hh>
25 
26 namespace ignition
27 {
28  namespace math
29  {
30  inline namespace IGNITION_MATH_VERSION_NAMESPACE
31  {
32  // Forward declare private data class
33  class SemanticVersionPrivate;
34 
40  class IGNITION_MATH_VISIBLE SemanticVersion
41  {
44  public: SemanticVersion();
45 
48  public: explicit SemanticVersion(const std::string &_v);
49 
52  public: SemanticVersion(const SemanticVersion &_copy);
53 
57  public: SemanticVersion &operator=(const SemanticVersion &_other);
58 
65  public: SemanticVersion(const unsigned int _major,
66  const unsigned int _minor = 0,
67  const unsigned int _patch = 0,
68  const std::string &_prerelease = "",
69  const std::string &_build = "");
70 
72  public: ~SemanticVersion();
73 
78  public: bool Parse(const std::string &_versionStr);
79 
82  public: std::string Version() const;
83 
86  public: unsigned int Major() const;
87 
90  public: unsigned int Minor() const;
91 
94  public: unsigned int Patch() const;
95 
99  public: std::string Prerelease() const;
100 
105  public: std::string Build() const;
106 
110  public: bool operator<(const SemanticVersion &_other) const;
111 
115  public: bool operator<=(const SemanticVersion &_other) const;
116 
120  public: bool operator>(const SemanticVersion &_other) const;
121 
125  public: bool operator>=(const SemanticVersion &_other) const;
126 
130  public: bool operator==(const SemanticVersion &_other) const;
131 
135  public: bool operator!=(const SemanticVersion &_other) const;
136 
141  public: friend std::ostream &operator<<(std::ostream &_out,
142  const SemanticVersion &_v)
143  {
144  _out << _v.Version();
145  return _out;
146  }
147 
148 #ifdef _WIN32
149 // Disable warning C4251 which is triggered by
150 // std::unique_ptr
151 #pragma warning(push)
152 #pragma warning(disable: 4251)
153 #endif
154  private: std::unique_ptr<SemanticVersionPrivate> dataPtr;
156 #ifdef _WIN32
157 #pragma warning(pop)
158 #endif
159  };
160  }
161  }
162 }
163 #endif
Helpers.hh
ignition
Definition: Angle.hh:40
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::Build
std::string Build() const
Get the build metadata string.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::Major
unsigned int Major() const
Get the major number.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::operator>
bool operator>(const SemanticVersion &_other) const
Greater than comparison operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion
Version comparison class based on Semantic Versioning 2.0.0 http://semver.org/ Compares versions and ...
Definition: SemanticVersion.hh:41
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::operator<<
friend std::ostream & operator<<(std::ostream &_out, const SemanticVersion &_v)
Stream insertion operator.
Definition: SemanticVersion.hh:141
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::SemanticVersion
SemanticVersion(const unsigned int _major, const unsigned int _minor=0, const unsigned int _patch=0, const std::string &_prerelease="", const std::string &_build="")
Constructor.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::SemanticVersion
SemanticVersion(const SemanticVersion &_copy)
Copy constructor.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::SemanticVersion
SemanticVersion()
Default constructor.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::operator<=
bool operator<=(const SemanticVersion &_other) const
Less than or equal comparison operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::Parse
bool Parse(const std::string &_versionStr)
Parse a version string and set the major, minor, patch numbers, and prerelease and build strings.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::Version
std::string Version() const
Returns the version as a string.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::SemanticVersion
SemanticVersion(const std::string &_v)
Constructor.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::operator==
bool operator==(const SemanticVersion &_other) const
Equality comparison operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::Patch
unsigned int Patch() const
Get the patch number.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::~SemanticVersion
~SemanticVersion()
Destructor.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::operator!=
bool operator!=(const SemanticVersion &_other) const
Inequality comparison operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::Minor
unsigned int Minor() const
Get the minor number.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::operator=
SemanticVersion & operator=(const SemanticVersion &_other)
Assignment operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::Prerelease
std::string Prerelease() const
Get the prerelease string.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::operator>=
bool operator>=(const SemanticVersion &_other) const
Greater than or equal comparison operator.
ignition::math::IGNITION_MATH_VERSION_NAMESPACE::SemanticVersion::operator<
bool operator<(const SemanticVersion &_other) const
Less than comparison operator.