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* fmtContId = "[CID=%08X]";
00007 static const char* fmtItemId = "[OID=%08X]";
00008
00009 ora::OId::OId():
00010 m_containerId(-1),
00011 m_itemId(-1){
00012 }
00013
00014 ora::OId::OId( int contId, int itemId ):
00015 m_containerId( contId),
00016 m_itemId( itemId ){
00017 }
00018
00019 ora::OId::OId( const OId& rhs ):
00020 m_containerId( rhs.m_containerId),
00021 m_itemId( rhs.m_itemId ){
00022 }
00023
00024 ora::OId& ora::OId::operator=( const OId& rhs ){
00025 m_containerId = rhs.m_containerId;
00026 m_itemId = rhs.m_itemId;
00027 return *this;
00028 }
00029
00030 bool ora::OId::operator==( const OId& rhs ) const {
00031 if(m_containerId != rhs.m_containerId ) return false;
00032 if(m_itemId != rhs.m_itemId ) return false;
00033 return true;
00034 }
00035
00036 bool ora::OId::operator!=( const OId& rhs ) const {
00037 return !operator==(rhs);
00038 }
00039
00040 int ora::OId::containerId() const{
00041 return m_containerId;
00042 }
00043
00044 int ora::OId::itemId() const{
00045 return m_itemId;
00046 }
00047
00048 std::string ora::OId::toString(){
00049 std::string str("");
00050 char text[128];
00051 ::sprintf(text, fmtContId, m_containerId);
00052 str += text;
00053 ::sprintf(text, fmtItemId, m_itemId);
00054 str += text;
00055 return str;
00056 }
00057
00058 void ora::OId::fromString( const std::string& source ){
00059 std::string tmp = source;
00060 for(char* p1 = (char*)tmp.c_str(); p1; p1 = ::strchr(++p1,'[')) {
00061 char* p2 = ::strchr(p1, '=');
00062 char* p3 = ::strchr(p1, ']');
00063 if ( p2 && p3 ) {
00064 if ( ::strncmp(fmtContId, p1, 4) == 0 ) {
00065 ::sscanf(p1, fmtContId, &m_containerId );
00066 }
00067 else if ( ::strncmp(fmtItemId, p1, 4) == 0 ) {
00068 ::sscanf(p1, fmtItemId, &m_itemId );
00069 }
00070 else {
00071 *p3 = *p2 = 0;
00072 }
00073 *p3 = ']';
00074 *p2 = '=';
00075 }
00076 }
00077 }
00078