CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CondCore/ORA/src/Version.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Version.h"
00002 //
00003 #include <cstdio>
00004 #include <cstring>
00005 
00006 static const char* thisSchemaVersionLabel = "1.1.0";
00007 
00008 static const char* poolSchemaVersionLabel = "POOL";
00009 static const char* fmt = "%3d.%3d.%3d";
00010 
00011 ora::Version& ora::Version::poolSchemaVersion(){
00012   static Version s_ver;
00013   s_ver.m_label = std::string(poolSchemaVersionLabel);
00014   s_ver.m_main = -1;
00015   return s_ver;
00016 }
00017 
00018 ora::Version& ora::Version::thisSchemaVersion(){
00019   static Version s_ver;
00020   s_ver = fromString( std::string( thisSchemaVersionLabel ));
00021   return s_ver;
00022 }
00023 
00024 ora::Version ora::Version::fromString( const std::string& source ){
00025   if ( source == poolSchemaVersionLabel ) return poolSchemaVersion();
00026   Version ver;
00027   ver.m_label = source;
00028   std::string tmp = source;
00029   char* p = (char*)tmp.c_str();
00030   ::sscanf(p, fmt, &ver.m_main, &ver.m_release, &ver.m_patch );
00031   return ver;
00032 }
00033 
00034 ora::Version::Version():
00035   m_label(""),
00036   m_main( -999 ),
00037   m_release( 0 ),
00038   m_patch( 0 ){
00039 }
00040 
00041 ora::Version::Version( const Version& rhs ):
00042   m_label( rhs.m_label ),
00043   m_main( rhs.m_main ),
00044   m_release( rhs.m_release ),
00045   m_patch( rhs.m_patch ){
00046 }
00047   
00048 ora::Version& ora::Version::operator=( const Version& rhs ){
00049   m_label = rhs.m_label;
00050   m_main = rhs.m_main;
00051   m_release = rhs.m_release;
00052   m_patch = rhs.m_patch;
00053   return *this;
00054 }
00055 
00056 bool ora::Version::operator==( const Version& rhs ) const {
00057   return m_main == rhs.m_main && m_release == rhs.m_release && m_patch == rhs.m_patch;
00058 }
00059 
00060 bool ora::Version::operator!=( const Version& rhs ) const{
00061   return !operator==( rhs );
00062 }
00063 
00064 bool ora::Version::operator>( const Version& rhs ) const {
00065   if( m_main > rhs.m_main ) return true;
00066   if( m_main == rhs.m_main ){
00067     if( m_release > rhs.m_release ) return true;
00068     if( m_release == rhs.m_release ){
00069       if(m_patch > rhs.m_patch ) return true;
00070     }
00071   }
00072   return false;
00073 }
00074 
00075 bool ora::Version::operator<( const Version& rhs ) const {
00076   if( m_main < rhs.m_main ) return true;
00077   if( m_main == rhs.m_main ){
00078     if( m_release < rhs.m_release ) return true;
00079     if( m_release == rhs.m_release ){
00080       if(m_patch < rhs.m_patch ) return true;
00081     }
00082   }
00083   return false;
00084 }
00085 
00086 bool ora::Version::operator>=( const Version& rhs ) const {
00087   if( m_main >= rhs.m_main ) return true;
00088   if( m_main == rhs.m_main ){
00089     if( m_release >= rhs.m_release ) return true;
00090     if( m_release == rhs.m_release ){
00091       if(m_patch >= rhs.m_patch ) return true;
00092     }
00093   }
00094   return false;
00095 }
00096 
00097 bool ora::Version::operator<=( const Version& rhs ) const {
00098   if( m_main <= rhs.m_main ) return true;
00099   if( m_main == rhs.m_main ){
00100     if( m_release <= rhs.m_release ) return true;
00101     if( m_release == rhs.m_release ){
00102       if(m_patch <= rhs.m_patch ) return true;
00103     }
00104   }
00105   return false;
00106 }
00107 
00108 std::string ora::Version::toString() const {
00109   return m_label;
00110 }
00111 
00112 void ora::Version::toOutputStream( std::ostream& os ) const {
00113   os << m_label;
00114 }
00115