Vowpal Wabbit
version.cc
Go to the documentation of this file.
1 #include "version.h"
2 
3 #include <cstdio>
4 
5 namespace VW
6 {
7 version_struct::version_struct(int maj, int min, int rv)
8 {
9  major = maj;
10  minor = min;
11  rev = rv;
12 }
13 
14 version_struct::version_struct(const char* v_str) { from_string(v_str); }
15 
17 {
18  major = v.major;
19  minor = v.minor;
20  rev = v.rev;
21 }
22 
24 {
25  major = v.major;
26  minor = v.minor;
27  rev = v.rev;
28 }
29 
30 void version_struct::operator=(const char* v_str) { from_string(v_str); }
31 
33 {
34  return (major == v.major && minor == v.minor && rev == v.rev);
35 }
36 
37 bool version_struct::operator==(const char* v_str) const
38 {
39  version_struct v_tmp(v_str);
40  return (*this == v_tmp);
41 }
42 
43 bool version_struct::operator!=(const version_struct& v) const { return !(*this == v); }
44 
45 bool version_struct::operator!=(const char* v_str) const { return !(*this == v_str); }
46 
48 {
49  if (major < v.major)
50  return false;
51  if (major > v.major)
52  return true;
53  if (minor < v.minor)
54  return false;
55  if (minor > v.minor)
56  return true;
57  if (rev >= v.rev)
58  return true;
59  return false;
60 }
61 
62 bool version_struct::operator>=(const char* v_str) const
63 {
64  version_struct v_tmp(v_str);
65  return (*this >= v_tmp);
66 }
67 
69 {
70  if (major < v.major)
71  return false;
72  if (major > v.major)
73  return true;
74  if (minor < v.minor)
75  return false;
76  if (minor > v.minor)
77  return true;
78  if (rev > v.rev)
79  return true;
80  return false;
81 }
82 
83 bool version_struct::operator>(const char* v_str) const
84 {
85  version_struct v_tmp(v_str);
86  return (*this > v_tmp);
87 }
88 
89 bool version_struct::operator<=(const version_struct& v) const { return !(*this > v); }
90 
91 bool version_struct::operator<=(const char* v_str) const { return !(*this > v_str); }
92 
93 bool version_struct::operator<(const version_struct& v) const { return !(*this >= v); }
94 
95 bool version_struct::operator<(const char* v_str) const { return !(*this >= v_str); }
96 
97 std::string version_struct::to_string() const
98 {
99  // int32_t has up to 10 digits, base-10.
100  // 3 * 30 + 2 = 92 => 128
101  char v_str[128];
102 
103  std::snprintf(v_str, sizeof(v_str), "%d.%d.%d", major, minor, rev);
104  std::string s = v_str;
105  return s;
106 }
107 
108 void version_struct::from_string(const char* str)
109 {
110 #ifdef _WIN32
111  sscanf_s(str, "%d.%d.%d", &major, &minor, &rev);
112 #else
113  std::sscanf(str, "%d.%d.%d", &major, &minor, &rev);
114 #endif
115 }
116 } // namespace VW
void operator=(const version_struct &v)
Definition: version.cc:23
bool operator==(const version_struct &v) const
Definition: version.cc:32
void from_string(const char *str)
Definition: version.cc:108
int32_t major
Definition: version.h:12
bool operator!=(const version_struct &v) const
Definition: version.cc:43
bool operator<(const version_struct &v) const
Definition: version.cc:93
bool operator>=(const version_struct &v) const
Definition: version.cc:47
int32_t minor
Definition: version.h:13
std::string to_string() const
Definition: version.cc:97
Definition: autolink.cc:11
bool operator>(const version_struct &v) const
Definition: version.cc:68
version_struct(int maj=0, int min=0, int rv=0)
Definition: version.cc:7
bool operator<=(const version_struct &v) const
Definition: version.cc:89