CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/FWCore/Utilities/src/ReleaseVersion.cc

Go to the documentation of this file.
00001 #include "FWCore/Utilities/interface/ReleaseVersion.h"
00002 
00003 #include "boost/algorithm/string.hpp"
00004 #include "boost/lexical_cast.hpp"
00005 
00006 #include <algorithm>
00007 #include <cassert>
00008 #include <cctype>
00009 #include <vector>
00010 
00011 namespace edm {
00012   namespace releaseversion {
00013     
00014     struct IsNotDigit {
00015       bool operator()(char const c) const {
00016         return !isdigit(c);
00017       } 
00018     };
00019 
00020     struct IsEmpty {
00021       bool operator()(std::string const& s) const {
00022         return s.empty();
00023       } 
00024     };
00025 
00026     DecomposedReleaseVersion::DecomposedReleaseVersion(std::string releaseVersion) : irregular_(true), major_(0), minor_(0)/*, point_(0), patch_(0), pre_(0)*/ {
00027       try {
00028         std::vector<std::string> parts;
00029         parts.reserve(releaseVersion.size());
00030         boost::algorithm::split(parts, releaseVersion, IsNotDigit(), boost::algorithm::token_compress_on);
00031         parts.erase(remove_if(parts.begin(), parts.end(), IsEmpty()), parts.end());
00032 
00033         if(parts.size() < 3) {
00034           return;
00035         }
00036 /*
00037         if(parts.size() == 4) {
00038           if(releaseVersion.find("patch") != std::string::npos) {
00039             patch_ = boost::lexical_cast<unsigned int>(parts[3]);
00040           } else if(releaseVersion.find("pre") != std::string::npos) {
00041             pre_ = boost::lexical_cast<unsigned int>(parts[3]);
00042           } else {
00043             return;
00044           }
00045         }
00046 */
00047         major_ = boost::lexical_cast<unsigned int>(parts[0]);
00048         minor_ = boost::lexical_cast<unsigned int>(parts[1]);
00049 //        point_ = boost::lexical_cast<unsigned int>(parts[2]);
00050         irregular_ = false;
00051       } catch(std::exception const&) {
00052       }
00053     }
00054 
00055 
00056     bool DecomposedReleaseVersion::operator<(DecomposedReleaseVersion const& other) const {
00057       if(irregular_ || other.irregular_) return false;
00058       if(major_ < other.major_) return true;
00059       if(major_ > other.major_) return false;
00060       if(minor_ < other.minor_) return true;
00061 //      if(minor_ > other.minor_) return false;
00062 //      if(point_ < other.point_) return true;
00063 //      if(point_ > other.point_) return false;
00064 //      if(patch_ < other.patch_) return true;
00065 //      if(patch_ > other.patch_) return false;
00066 //      if(pre_ < other.pre_) return true;
00067       return false;
00068     }
00069 
00070     bool
00071     isEarlierRelease(std::string const& a, std::string const& b) {
00072       return(DecomposedReleaseVersion(a) < DecomposedReleaseVersion(b));
00073     }
00074 
00075     bool
00076     isEarlierRelease(DecomposedReleaseVersion const& a, std::string const& b) {
00077       return(a < DecomposedReleaseVersion(b));
00078     }
00079 
00080     bool
00081     isEarlierRelease(std::string const& a, DecomposedReleaseVersion const& b) {
00082       return(DecomposedReleaseVersion(a) < b);
00083     }
00084 
00085     bool
00086     isEarlierRelease(DecomposedReleaseVersion const& a, DecomposedReleaseVersion const& b) {
00087       return(a < b);
00088     }
00089 
00090   }
00091 }