4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief ClockService non-inline non-template implementation */
26 #include "ClockService.hh"
27 //#include "ClockService.ih"
30 #include <boost/regex.hpp>
31 #include <senf/Utils/Console/Console.hh>
33 //#include "ClockService.mpp"
35 ///////////////////////////////cc.p////////////////////////////////////////
38 senf::parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & tokens,
39 ClockService::clock_type & out)
44 senf::console::CheckedArgumentIteratorWrapper arg (tokens);
45 senf::console::parse( *(arg++), value );
47 static boost::sregex_iterator::regex_type rx ("[mun]?[dhms]");
48 boost::sregex_iterator i (value.begin(), value.end(), rx);
49 boost::sregex_iterator const i_end;
50 std::string::const_iterator j (value.begin());
51 for (; i != i_end; ++i) {
52 boost::sregex_iterator::value_type::value_type match ((*i)[0]);
53 long double v (boost::lexical_cast<long double>(std::string(j, match.first)));
56 if (match.length() == 2) {
58 unit = *boost::next(match.first);
60 SENF_ASSERT( match.length() == 1);
65 case 'n': v /= 1000.0;
66 case 'u': v /= 1000.0;
67 case 'm': v /= 1000.0;
73 case 's': v *= 1000000000.0;
75 out += senf::ClockService::nanoseconds(senf::ClockService::int64_type(v));
79 throw senf::console::SyntaxErrorException();
82 prefix_ void senf::formatClockServiceInterval(ClockService::clock_type interval,
85 os << interval << "ns";
88 ///////////////////////////////cc.e////////////////////////////////////////
90 //#include "ClockService.mpp"
97 // c-file-style: "senf"
98 // indent-tabs-mode: nil
99 // ispell-local-dictionary: "american"
100 // compile-command: "scons -u test"