fixes for ClockService::clock_type -> RestrictedInt change introduced by last commit
[senf.git] / senf / Scheduler / ClockService.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
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
10 //
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.
14 //
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.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
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.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief ClockService non-inline non-template implementation */
30
31 #include "ClockService.hh"
32 //#include "ClockService.ih"
33
34 // Custom includes
35 #include <boost/regex.hpp>
36 #include <senf/Utils/Console/Traits.hh>
37
38 #define prefix_
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 prefix_ void
42 senf::parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & tokens,
43                                 ClockService::clock_type & out)
44 {
45     out = senf::ClockService::clock_type(0);
46     std::string value;
47     {
48         console::CheckedArgumentIteratorWrapper arg (tokens);
49         console::parse( *(arg++), value );
50     }
51     static boost::sregex_iterator::regex_type rx ("[mun]?[dhms]");
52     boost::sregex_iterator i (value.begin(), value.end(), rx);
53     boost::sregex_iterator const i_end;
54     std::string::const_iterator j (value.begin());
55     for (; i != i_end; ++i) {
56         boost::sregex_iterator::value_type::value_type match ((*i)[0]);
57         long double v (boost::lexical_cast<long double>(std::string(j, match.first)));
58         char scale (0);
59         char unit (0);
60         if (match.length() == 2) {
61             scale = *match.first;
62             unit = *boost::next(match.first);
63         } else {
64             SENF_ASSERT( match.length() == 1,
65                          "Internal failure: RegEx match returns weird number of matches" );
66             unit = *match.first;
67         }
68         switch (scale) {
69         case 0: break;
70         case 'n': v /= 1000.0;
71         case 'u': v /= 1000.0;
72         case 'm': v /= 1000.0;
73         }
74         switch (unit) {
75         case 'd': v *= 24.0;
76         case 'h': v *= 60.0;
77         case 'm': v *= 60.0;
78         case 's': v *= 1000000000.0;
79         }
80         out += ClockService::nanoseconds(ClockService::int64_type(v));
81         j = match.second;
82     }
83     if (j != value.end())
84         throw console::SyntaxErrorException();
85 }
86
87 prefix_ void senf::formatClockServiceInterval(ClockService::clock_type interval,
88                                               std::ostream & os)
89 {
90     os << interval << "ns";
91 }
92
93 //-/////////////////////////////////////////////////////////////////////////////////////////////////
94 #undef prefix_
95 //#include "ClockService.mpp"
96
97 \f
98 // Local Variables:
99 // mode: c++
100 // fill-column: 100
101 // comment-column: 40
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"
106 // End: