/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

JobId.cc
Go to the documentation of this file.
00001 #include "Conventions/JobId.h"
00002 #include <string>
00003 #include <sstream>
00004 #include <iomanip>
00005 #include <string.h>
00006 #include <stdlib.h>
00007 
00008 
00009 DayaBay::JobId::JobId() 
00010 {
00011   m_data[0]=0;
00012   m_data[1]=0;
00013   m_data[2]=0;
00014   m_data[3]=0;
00015 }
00016 
00017 DayaBay::JobId::JobId(const std::string& uuid)
00018 {
00019   this->set(uuid);
00020 }
00021 
00022 DayaBay::JobId::~JobId() {}
00023 
00024 DayaBay::JobId::JobId(const DayaBay::JobId& jobId)
00025 {
00026   // Copy constructor
00027   m_data[0] = jobId.m_data[0];
00028   m_data[1] = jobId.m_data[1];
00029   m_data[2] = jobId.m_data[2];
00030   m_data[3] = jobId.m_data[3];
00031 }
00032 
00033 DayaBay::JobId& DayaBay::JobId::operator=(const DayaBay::JobId& jobId)
00034 {
00036   m_data[0] = jobId.m_data[0];
00037   m_data[1] = jobId.m_data[1];
00038   m_data[2] = jobId.m_data[2];
00039   m_data[3] = jobId.m_data[3];
00040   return *this;
00041 }
00042 
00043 bool DayaBay::JobId::operator==(const DayaBay::JobId& rhs) const
00044 { 
00045   return (m_data[0] == rhs.m_data[0]
00046           && m_data[1] == rhs.m_data[1]
00047           && m_data[2] == rhs.m_data[2]
00048           && m_data[3] == rhs.m_data[3]);
00049 }
00050 
00051 bool DayaBay::JobId::operator!=(const DayaBay::JobId& rhs) const
00052 {
00053   return !(*this == rhs);
00054 }
00055 
00056 void DayaBay::JobId::set(const std::string& uuid)
00057 {
00058   // Convert job ID string to data vector
00059   // Currently expects a UUID-structured string
00060   m_data[0]=0;
00061   m_data[1]=0;
00062   m_data[2]=0;
00063   m_data[3]=0;
00064   if(uuid.size()!=36 || uuid[8]!='-' || uuid[13]!='-'
00065      || uuid[18]!='-' || uuid[23]!='-'){
00066     // Invalid uuid
00067     return;
00068   }
00069   std::string a,b,c,d;
00070   a = std::string(&uuid[0],8);
00071   b = std::string(&uuid[9],4);
00072   b.append(&uuid[14],4);
00073   c = std::string(&uuid[19],4);
00074   c.append(&uuid[24],4);
00075   d = std::string(&uuid[28],8);
00076   char buffer[16];
00077   char hexTokens[] = "0123456789ABCDEFabcdef";
00078   if(strtok(strcpy(buffer,&a[0]),hexTokens)!=NULL
00079      || strtok(strcpy(buffer,&b[0]),hexTokens)!=NULL
00080      || strtok(strcpy(buffer,&c[0]),hexTokens)!=NULL
00081      || strtok(strcpy(buffer,&d[0]),hexTokens)!=NULL){
00082     // Invalid uuid
00083     return;
00084   }
00085   m_data[0] = strtoul(&a[0],NULL,16);
00086   m_data[1] = strtoul(&b[0],NULL,16);
00087   m_data[2] = strtoul(&c[0],NULL,16);
00088   m_data[3] = strtoul(&d[0],NULL,16);
00089 }
00090 
00091 std::string DayaBay::JobId::uuid() const 
00092 {
00093   // Return a string UUID representation of the job ID
00094   std::ostringstream jobIdHex;
00095   jobIdHex 
00096       << std::hex << std::setw(8) << std::setfill('0') 
00097       << m_data[0]
00098       << std::hex << std::setw(8) << std::setfill('0') 
00099       << m_data[1] 
00100       << std::hex << std::setw(8) << std::setfill('0') 
00101       << m_data[2] 
00102       << std::hex << std::setw(8) << std::setfill('0') 
00103       << m_data[3];
00104   std::string jobIdStr = jobIdHex.str();
00105   jobIdStr.insert(8,"-");
00106   jobIdStr.insert(13,"-");
00107   jobIdStr.insert(18,"-");
00108   jobIdStr.insert(23,"-");
00109   return jobIdStr;
00110 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:56:19 for Conventions by doxygen 1.7.4