CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CondCore/ORA/src/OId.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/OId.h"
00002 //
00003 #include <cstdio>
00004 #include <cstring>
00005 
00006 static const char* OIDFMT = "%04X-%08X";
00007 static const size_t OIDSIZ = 14;
00008 
00009 bool ora::OId::isOId( const std::string& input ){
00010   ora::OId tmp;
00011   return tmp.fromString( input );
00012 }
00013 
00014 ora::OId::OId():
00015   m_containerId(-1),
00016   m_itemId(-1){
00017 }
00018 
00019 ora::OId::OId( const std::pair<int,int>& oidPair ):
00020   m_containerId( oidPair.first ),
00021   m_itemId( oidPair.second ){
00022 }
00023   
00024 ora::OId::OId( int contId, int itemId ):
00025   m_containerId( contId),
00026   m_itemId( itemId ){
00027 }
00028 
00029 ora::OId::OId( const OId& rhs ):
00030   m_containerId( rhs.m_containerId),
00031   m_itemId( rhs.m_itemId ){
00032 }
00033 
00034 ora::OId& ora::OId::operator=( const OId& rhs ){
00035   m_containerId = rhs.m_containerId;
00036   m_itemId = rhs.m_itemId;
00037   return *this;
00038 }
00039 
00040 bool ora::OId::operator==( const OId& rhs ) const {
00041   if(m_containerId != rhs.m_containerId ) return false;
00042   if(m_itemId != rhs.m_itemId ) return false;
00043   return true;
00044 }
00045 
00046 bool ora::OId::operator!=( const OId& rhs ) const {
00047   return !operator==(rhs);
00048 }
00049 
00050 int ora::OId::containerId() const{
00051   return m_containerId;
00052 }
00053 
00054 int ora::OId::itemId() const{
00055   return m_itemId;
00056 }
00057 
00058 std::string ora::OId::toString() const {
00059   char text[OIDSIZ];
00060   ::snprintf(text, OIDSIZ, OIDFMT, m_containerId, m_itemId );
00061   return std::string(text);
00062 }
00063 
00064 bool ora::OId::fromString( const std::string& source ){
00065   if(source.size()>OIDSIZ) return false; // constraint relaxed...
00066   const char* ptr = source.c_str();
00067   if( ::sscanf( ptr, OIDFMT, &m_containerId, &m_itemId )==2 ) return true;
00068   return false;
00069 }
00070 
00071 void ora::OId::toOutputStream( std::ostream& os ) const {
00072   os << this->toString();
00073 }
00074 
00075 void ora::OId::reset() {
00076   m_containerId = -1;
00077   m_itemId = -1;
00078 }
00079 
00080 bool ora::OId::isInvalid() const {
00081   return (m_containerId == -1 || m_itemId == -1);
00082 }
00083 
00084 std::pair<int,int> ora::OId::toPair() const {
00085   return std::make_pair( m_containerId, m_itemId );
00086 }