compileTimestamp.cpp
Go to the documentation of this file.00001
00014 #include <iomanip>
00015 #include <sstream>
00016 #include <dlrCommon/compileTimestamp.h>
00017 #include <dlrCommon/exception.h>
00018 #include <dlrCommon/inputStream.h>
00019
00020 namespace dlr {
00021
00022 namespace common {
00023
00024 std::string
00025 CompileTimestamp::
00026 getISOString()
00027 {
00028 std::ostringstream isoStream;
00029 isoStream << std::setfill('0')
00030 << std::setw(4) << m_year << "-"
00031 << std::setw(2) << m_month + 1 << "-"
00032 << std::setw(2) << m_day + 1 << " "
00033 << std::setw(2) << m_hour << ":"
00034 << std::setw(2) << m_minute << ":"
00035 << std::setw(2) << m_second;
00036 return isoStream.str();
00037 }
00038
00039
00040 void
00041 CompileTimestamp::
00042 parseCompilerDateString(const std::string& compilerDateString)
00043 {
00044 std::istringstream compilerDateStream(compilerDateString);
00045
00046 std::string monthString;
00047 compilerDateStream >> monthString;
00048 if(monthString == "Jan") {m_month = 0;}
00049 else if(monthString == "Feb") {m_month = 1;}
00050 else if(monthString == "Mar") {m_month = 2;}
00051 else if(monthString == "Apr") {m_month = 3;}
00052 else if(monthString == "May") {m_month = 4;}
00053 else if(monthString == "Jun") {m_month = 5;}
00054 else if(monthString == "Jul") {m_month = 6;}
00055 else if(monthString == "Aug") {m_month = 7;}
00056 else if(monthString == "Sep") {m_month = 8;}
00057 else if(monthString == "Oct") {m_month = 9;}
00058 else if(monthString == "Nov") {m_month = 10;}
00059 else if(monthString == "Dec") {m_month = 11;}
00060 else {
00061 std::ostringstream message;
00062 message << "Unable to recover month from date string \""
00063 << compilerDateString << "\".";
00064 DLR_THROW(ValueException,
00065 "CompileTimestamp::parseCompilerDateString()",
00066 message.str().c_str());
00067 }
00068
00069 compilerDateStream >> m_day;
00070 --m_day;
00071
00072 compilerDateStream >> m_year;
00073
00074 if(!compilerDateStream) {
00075 std::ostringstream message;
00076 message << "Unable to parse date string \"" << compilerDateString
00077 << "\".";
00078 DLR_THROW(ValueException,
00079 "CompileTimestamp::parseCompilerDateString()",
00080 message.str().c_str());
00081 }
00082 }
00083
00084
00085 void
00086 CompileTimestamp::
00087 parseCompilerTimeString(const std::string& compilerTimeString)
00088 {
00089 std::istringstream compilerTimeStream(compilerTimeString);
00090 InputStream dlrStream(compilerTimeStream);
00091 compilerTimeStream >> m_hour;
00092 dlrStream.expect(":");
00093 compilerTimeStream >> m_minute;
00094 dlrStream.expect(":");
00095 compilerTimeStream >> m_second;
00096 if(!compilerTimeStream) {
00097 std::ostringstream message;
00098 message << "Unable to parse time string \"" << compilerTimeString
00099 << "\".";
00100 DLR_THROW(ValueException,
00101 "CompileTimestamp::parseCompilerTimeString()",
00102 message.str().c_str());
00103 }
00104 }
00105
00106 }
00107
00108 }