Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-26 03:16:02

0001 #include "FWCore/Utilities/interface/ReleaseVersion.h"
0002 
0003 #include "boost/algorithm/string.hpp"
0004 
0005 #include <algorithm>
0006 #include <cassert>
0007 #include <cctype>
0008 #include <vector>
0009 
0010 namespace edm {
0011   namespace releaseversion {
0012 
0013     struct IsNotDigit {
0014       bool operator()(char const c) const { return !isdigit(c); }
0015     };
0016 
0017     struct IsEmpty {
0018       bool operator()(std::string const& s) const { return s.empty(); }
0019     };
0020 
0021     DecomposedReleaseVersion::DecomposedReleaseVersion(std::string releaseVersion)
0022         : irregular_(true), major_(0), minor_(0) /*, point_(0), patch_(0), pre_(0)*/ {
0023       try {
0024         std::vector<std::string> parts;
0025         parts.reserve(releaseVersion.size());
0026         boost::algorithm::split(parts, releaseVersion, IsNotDigit(), boost::algorithm::token_compress_on);
0027         parts.erase(remove_if(parts.begin(), parts.end(), IsEmpty()), parts.end());
0028 
0029         if (parts.size() < 3) {
0030           return;
0031         }
0032         /*
0033         if(parts.size() == 4) {
0034           if(releaseVersion.find("patch") != std::string::npos) {
0035             patch_ = std::stoul(parts[3]);
0036           } else if(releaseVersion.find("pre") != std::string::npos) {
0037             pre_ = std::stoul(parts[3]);
0038           } else {
0039             return;
0040           }
0041         }
0042 */
0043         major_ = std::stoul(parts[0]);
0044         minor_ = std::stoul(parts[1]);
0045         //        point_ = std::stoul(parts[2]);
0046         irregular_ = false;
0047       } catch (std::exception const&) {
0048       }
0049     }
0050 
0051     bool DecomposedReleaseVersion::operator<(DecomposedReleaseVersion const& other) const {
0052       if (irregular_ || other.irregular_)
0053         return false;
0054       if (major_ < other.major_)
0055         return true;
0056       if (major_ > other.major_)
0057         return false;
0058       if (minor_ < other.minor_)
0059         return true;
0060       //      if(minor_ > other.minor_) return false;
0061       //      if(point_ < other.point_) return true;
0062       //      if(point_ > other.point_) return false;
0063       //      if(patch_ < other.patch_) return true;
0064       //      if(patch_ > other.patch_) return false;
0065       //      if(pre_ < other.pre_) return true;
0066       return false;
0067     }
0068 
0069     bool isEarlierRelease(std::string const& a, std::string const& b) {
0070       return (DecomposedReleaseVersion(a) < DecomposedReleaseVersion(b));
0071     }
0072 
0073     bool isEarlierRelease(DecomposedReleaseVersion const& a, std::string const& b) {
0074       return (a < DecomposedReleaseVersion(b));
0075     }
0076 
0077     bool isEarlierRelease(std::string const& a, DecomposedReleaseVersion const& b) {
0078       return (DecomposedReleaseVersion(a) < b);
0079     }
0080 
0081     bool isEarlierRelease(DecomposedReleaseVersion const& a, DecomposedReleaseVersion const& b) { return (a < b); }
0082 
0083   }  // namespace releaseversion
0084 }  // namespace edm