4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief ClockService non-inline non-template implementation */
31 #include "ClockService.hh"
32 //#include "ClockService.ih"
35 #include <boost/regex.hpp>
36 #include <senf/Utils/Console/Traits.hh>
38 //#include "ClockService.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43 senf::parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & tokens,
44 ClockService::clock_type & out)
49 console::CheckedArgumentIteratorWrapper arg (tokens);
50 console::parse( *(arg++), value );
52 static boost::sregex_iterator::regex_type rx ("[mun]?[dhms]");
53 boost::sregex_iterator i (value.begin(), value.end(), rx);
54 boost::sregex_iterator const i_end;
55 std::string::const_iterator j (value.begin());
56 for (; i != i_end; ++i) {
57 boost::sregex_iterator::value_type::value_type match ((*i)[0]);
58 long double v (boost::lexical_cast<long double>(std::string(j, match.first)));
61 if (match.length() == 2) {
63 unit = *boost::next(match.first);
65 SENF_ASSERT( match.length() == 1,
66 "Internal failure: RegEx match returns weird number of matches" );
71 case 'n': v /= 1000.0;
72 case 'u': v /= 1000.0;
73 case 'm': v /= 1000.0;
79 case 's': v *= 1000000000.0;
81 out += ClockService::nanoseconds(ClockService::int64_type(v));
85 throw console::SyntaxErrorException();
88 prefix_ void senf::formatClockServiceInterval(ClockService::clock_type interval,
91 os << interval << "ns";
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
96 //#include "ClockService.mpp"
102 // comment-column: 40
103 // c-file-style: "senf"
104 // indent-tabs-mode: nil
105 // ispell-local-dictionary: "american"
106 // compile-command: "scons -u test"