From: g0dil Date: Tue, 18 Nov 2008 08:35:11 +0000 (+0000) Subject: Scheduler: Add ClockService::clock_type interval console parser X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=88a1eaae226bb958a6e6a7c42f24f7f9818f91be;p=senf.git Scheduler: Add ClockService::clock_type interval console parser git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@963 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Scheduler/ClockService.cc b/Scheduler/ClockService.cc index d9733d8..612a579 100644 --- a/Scheduler/ClockService.cc +++ b/Scheduler/ClockService.cc @@ -27,16 +27,58 @@ //#include "ClockService.ih" // Custom includes -#include -#include -#include -#include -#include "../Utils/Exception.hh" +#include +#include "Console/Console.hh" //#include "ClockService.mpp" #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// +prefix_ void +senf::parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & tokens, + ClockService::clock_type & out) +{ + out = 0; + std::string value; + { + senf::console::CheckedArgumentIteratorWrapper arg (tokens); + senf::console::parse( *(arg++), value ); + } + static boost::sregex_iterator::regex_type rx ("[mun]?[dhms]"); + boost::sregex_iterator i (value.begin(), value.end(), rx); + boost::sregex_iterator const i_end; + std::string::const_iterator j (value.begin()); + for (; i != i_end; ++i) { + boost::sregex_iterator::value_type::value_type match ((*i)[0]); + long double v (boost::lexical_cast(std::string(j, match.first))); + char scale (0); + char unit (0); + if (match.length() == 2) { + scale = *match.first; + unit = *boost::next(match.first); + } else { + SENF_ASSERT( match.length() == 1); + unit = *match.first; + } + switch (scale) { + case 0: break; + case 'n': v /= 1000.0; + case 'u': v /= 1000.0; + case 'm': v /= 1000.0; + } + switch (unit) { + case 'd': v *= 24.0; + case 'h': v *= 60.0; + case 'm': v *= 60.0; + case 's': v *= 1000000000.0; + } + out += senf::ClockService::nanoseconds(senf::ClockService::int64_type(v)); + j = match.second; + } + if (j != value.end()) + throw senf::console::SyntaxErrorException(); +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "ClockService.mpp" diff --git a/Scheduler/ClockService.hh b/Scheduler/ClockService.hh index 5b02c19..bad8b6e 100644 --- a/Scheduler/ClockService.hh +++ b/Scheduler/ClockService.hh @@ -33,6 +33,7 @@ #include #include #include "../Utils/singleton.hh" +#include "Console/Parse.hh" //#include "ClockService.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -150,6 +151,41 @@ namespace senf { #endif }; + /** \brief Console argument parser to parse value as time interval + + This parser will parse a time interval specification into a ClockService::clock_type + value. The following units are supported: + + + + + + +
\c ddays
\c hhours
\c mminutes
\c sseconds
+ + Additionally, the unit may be prefixed by an SI scale: + + + + + +
\c mmilli
\c umicro
\c nnano
+ + An optional decimal point is also supported. A single timer interval may combine any number + of these specifications. The following are all valid intervals: + + + + + + + + + +
10d10 days
5d5d10 days
1d2h100m3.5s27 hours, 30 minutes and 3.5 seconds
1s100ms1.1 seconds
1.1s1.1 seconds
123.456us123.456 microseconds
2md(very unusual) 2 milli-days
+ */ + void parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & tokens, + ClockService::clock_type & out); } ///////////////////////////////hh.e////////////////////////////////////////