00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #include "ClockService.hh"
00027
00028
00029
00030 #include <boost/regex.hpp>
00031 #include <senf/Utils/Console/Traits.hh>
00032
00033
00034 #define prefix_
00035
00036
00037 prefix_ void
00038 senf::parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & tokens,
00039 ClockService::clock_type & out)
00040 {
00041 out = 0;
00042 std::string value;
00043 {
00044 console::CheckedArgumentIteratorWrapper arg (tokens);
00045 console::parse( *(arg++), value );
00046 }
00047 static boost::sregex_iterator::regex_type rx ("[mun]?[dhms]");
00048 boost::sregex_iterator i (value.begin(), value.end(), rx);
00049 boost::sregex_iterator const i_end;
00050 std::string::const_iterator j (value.begin());
00051 for (; i != i_end; ++i) {
00052 boost::sregex_iterator::value_type::value_type match ((*i)[0]);
00053 long double v (boost::lexical_cast<long double>(std::string(j, match.first)));
00054 char scale (0);
00055 char unit (0);
00056 if (match.length() == 2) {
00057 scale = *match.first;
00058 unit = *boost::next(match.first);
00059 } else {
00060 SENF_ASSERT( match.length() == 1,
00061 "Internal failure: RegEx match returns weird number of matches" );
00062 unit = *match.first;
00063 }
00064 switch (scale) {
00065 case 0: break;
00066 case 'n': v /= 1000.0;
00067 case 'u': v /= 1000.0;
00068 case 'm': v /= 1000.0;
00069 }
00070 switch (unit) {
00071 case 'd': v *= 24.0;
00072 case 'h': v *= 60.0;
00073 case 'm': v *= 60.0;
00074 case 's': v *= 1000000000.0;
00075 }
00076 out += ClockService::nanoseconds(ClockService::int64_type(v));
00077 j = match.second;
00078 }
00079 if (j != value.end())
00080 throw console::SyntaxErrorException();
00081 }
00082
00083 prefix_ void senf::formatClockServiceInterval(ClockService::clock_type interval,
00084 std::ostream & os)
00085 {
00086 os << interval << "ns";
00087 }
00088
00089
00090 #undef prefix_
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102