Mania++
 All Classes Functions Variables Pages
VersionCompare.h
1 #ifndef VERSIONCOMPARE_H_
2 #define VERSIONCOMPARE_H_
3 
4 #include <string>
5 #include <sstream>
6 
7 //* VersionCompare
12 {
13 public:
20  static bool NewerThanCurrent(const std::string& current, const std::string& other)
21  {
22  int parsedCurrent[3], parsedOther[3];
23  parseVersion(parsedCurrent, current);
24  parseVersion(parsedOther, other);
25  return std::lexicographical_compare(parsedCurrent, parsedCurrent + 3, parsedOther, parsedOther + 3);
26  }
27 
34  static bool NotOlderThan(const std::string& base, const std::string& comp)
35  {
36  int parsedBase[3], parsedComp[3];
37  parseVersion(parsedBase, base);
38  parseVersion(parsedComp, comp);
39  return !std::lexicographical_compare(parsedComp, parsedComp + 3, parsedBase, parsedBase + 3);
40  }
41 
42 private:
49  static void parseVersion(int result[3], const std::string& input)
50  {
51  std::istringstream parser(input);
52  parser >> result[0];
53  for(int idx = 1; idx < 3; idx++)
54  {
55  parser.get();
56  parser >> result[idx];
57  }
58  }
59 };
60 
61 #endif // VERSIONCOMPARE_H_
Compares string versions.
Definition: VersionCompare.h:11
static void parseVersion(int result[3], const std::string &input)
Definition: VersionCompare.h:49
static bool NewerThanCurrent(const std::string &current, const std::string &other)
Definition: VersionCompare.h:20
static bool NotOlderThan(const std::string &base, const std::string &comp)
Definition: VersionCompare.h:34