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 GAZEBO_COMMON_SEMANTICVERSION_HH_
19 #define GAZEBO_COMMON_SEMANTICVERSION_HH_
20 
21 #include <string>
22 #include <memory>
23 #include "gazebo/util/system.hh"
24 
25 namespace gazebo
26 {
27  namespace common
28  {
29  // Forward declare private data class
30  class SemanticVersionPrivate;
31 
34 
38  class GZ_COMMON_VISIBLE SemanticVersion
39  {
42  public: SemanticVersion();
43 
46  public: explicit SemanticVersion(const std::string &_v);
47 
50  public: SemanticVersion(const SemanticVersion &_copy);
51 
55  public: SemanticVersion &operator=(const SemanticVersion &_other);
56 
63  public: SemanticVersion(const unsigned int _major,
64  const unsigned int _minor = 0,
65  const unsigned int _patch = 0,
66  const std::string &_prerelease = "",
67  const std::string &_build = "");
68 
70  public: ~SemanticVersion();
71 
76  public: bool Parse(const std::string &_versionStr);
77 
80  public: std::string Version() const;
81 
84  public: unsigned int Major() const;
85 
88  public: unsigned int Minor() const;
89 
92  public: unsigned int Patch() const;
93 
97  public: std::string Prerelease() const;
98 
103  public: std::string Build() const;
104 
108  public: bool operator<(const SemanticVersion &_other) const;
109 
113  public: bool operator<=(const SemanticVersion &_other) const;
114 
118  public: bool operator>(const SemanticVersion &_other) const;
119 
123  public: bool operator>=(const SemanticVersion &_other) const;
124 
128  public: bool operator==(const SemanticVersion &_other) const;
129 
133  public: bool operator!=(const SemanticVersion &_other) const;
134 
139  public: friend std::ostream &operator<<(std::ostream &_out,
140  const SemanticVersion &_v)
141  {
142  _out << _v.Version();
143  return _out;
144  }
145 
147  private: std::unique_ptr<SemanticVersionPrivate> dataPtr;
148  };
149  }
150 }
151 #endif
friend std::ostream & operator<<(std::ostream &_out, const SemanticVersion &_v)
Stream insertion operator.
Definition: SemanticVersion.hh:139
std::string Version() const
Returns the version as a string.
Version comparison class based on Semantic Versioning 2.0.0 http://semver.org/ Compares versions and ...
Definition: SemanticVersion.hh:38