version_information.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2022 FZI Forschungszentrum Informatik
5 // Created on behalf of Universal Robots A/S
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // -- END LICENSE BLOCK ------------------------------------------------
19 
20 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 
31 
32 namespace urcl
33 {
34 std::vector<std::string> splitString(std::string input, const std::string& delimiter)
35 {
36  std::vector<std::string> result;
37  size_t pos = 0;
38  std::string substring;
39  while ((pos = input.find(delimiter)) != std::string::npos)
40  {
41  substring = input.substr(0, pos);
42  result.push_back(substring);
43  input.erase(0, pos + delimiter.length());
44  }
45  result.push_back(input);
46  return result;
47 }
48 
50 {
51  // Since 'major' and 'minor' are keywords in <sys/types> we don't use the initializer list and
52  // specify this->major explicitly.
53  this->major = 0;
54  this->minor = 0;
55  this->bugfix = 0;
56  this->build = 0;
57 }
58 
60 {
61  auto components = splitString(str);
62  VersionInformation info;
63  if (components.size() >= 2)
64  {
65  info.major = std::stoi(components[0]);
66  info.minor = std::stoi(components[1]);
67  if (components.size() >= 3)
68  {
69  info.bugfix = std::stoi(components[2]);
70  if (components.size() == 4)
71  {
72  info.build = std::stoi(components[3]);
73  }
74  else if (components.size() > 4)
75  {
76  throw UrException("Given string '" + str + "' does not conform a version string format.");
77  }
78  }
79  }
80  else
81  {
82  throw UrException("Given string '" + str + "' does not conform a version string format.");
83  }
84 
85  return info;
86 }
87 
89 {
90  return this->major >= 5;
91 }
92 
94 {
95  return v1.major == v2.major && v1.minor == v2.minor && v1.bugfix == v2.bugfix && v1.build == v2.build;
96 }
97 
99 {
100  return !(v1 == v2);
101 }
102 
104 {
105  if (v1.major <= v2.major)
106  {
107  if (v1.major < v2.major)
108  {
109  return true;
110  }
111  if (v1.minor <= v2.minor)
112  {
113  if (v1.minor < v2.minor)
114  {
115  return true;
116  }
117  if (v1.bugfix <= v2.bugfix)
118  {
119  if (v1.bugfix < v2.bugfix)
120  {
121  return true;
122  }
123  }
124  if (v1.build < v2.build)
125  {
126  return true;
127  }
128  }
129  }
130  return false;
131 }
132 
134 {
135  return v1 < v2 || v1 == v2;
136 }
137 
139 {
140  return !(v1 <= v2);
141 }
142 
144 {
145  return !(v1 < v2);
146 }
147 } // namespace urcl
uint32_t minor
Minor version number.
friend bool operator==(const VersionInformation &v1, const VersionInformation &v2)
friend bool operator>=(const VersionInformation &v1, const VersionInformation &v2)
uint32_t bugfix
Bugfix version number.
Struct containing a robot&#39;s version information.
friend bool operator<=(const VersionInformation &v1, const VersionInformation &v2)
std::vector< std::string > splitString(std::string input, const std::string &delimiter=".")
friend bool operator>(const VersionInformation &v1, const VersionInformation &v2)
friend bool operator!=(const VersionInformation &v1, const VersionInformation &v2)
uint32_t major
Major version number.
uint32_t build
Build number.
friend bool operator<(const VersionInformation &v1, const VersionInformation &v2)
Our base class for exceptions. Specialized exceptions should inherit from those.
Definition: exceptions.h:41
static VersionInformation fromString(const std::string &str)
Parses a version string into a VersionInformation object.


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47