Fix SCons 1.2.0 build failure
[senf.git] / Scheduler / ClockService.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief ClockService non-inline non-template implementation */
25
26 #include "ClockService.hh"
27 //#include "ClockService.ih"
28
29 // Custom includes
30 #include <boost/regex.hpp>
31 #include "../Utils/Console/Console.hh"
32
33 //#include "ClockService.mpp"
34 #define prefix_
35 ///////////////////////////////cc.p////////////////////////////////////////
36
37 prefix_ void
38 senf::parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & tokens,
39                                 ClockService::clock_type & out)
40 {
41     out = 0;
42     std::string value;
43     {
44         senf::console::CheckedArgumentIteratorWrapper arg (tokens);
45         senf::console::parse( *(arg++), value );
46     }
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)));
54         char scale (0);
55         char unit (0);
56         if (match.length() == 2) {
57             scale = *match.first;
58             unit = *boost::next(match.first);
59         } else {
60             SENF_ASSERT( match.length() == 1);
61             unit = *match.first;
62         }
63         switch (scale) {
64         case 0: break;
65         case 'n': v /= 1000.0;
66         case 'u': v /= 1000.0;
67         case 'm': v /= 1000.0;
68         }
69         switch (unit) {
70         case 'd': v *= 24.0;
71         case 'h': v *= 60.0;
72         case 'm': v *= 60.0;
73         case 's': v *= 1000000000.0;
74         }
75         out += senf::ClockService::nanoseconds(senf::ClockService::int64_type(v));
76         j = match.second;
77     }
78     if (j != value.end())
79         throw senf::console::SyntaxErrorException();
80 }
81
82 prefix_ void senf::formatClockServiceInterval(ClockService::clock_type interval,
83                                               std::ostream & os)
84 {
85     os << interval << "ns";
86 }
87
88 ///////////////////////////////cc.e////////////////////////////////////////
89 #undef prefix_
90 //#include "ClockService.mpp"
91
92 \f
93 // Local Variables:
94 // mode: c++
95 // fill-column: 100
96 // comment-column: 40
97 // c-file-style: "senf"
98 // indent-tabs-mode: nil
99 // ispell-local-dictionary: "american"
100 // compile-command: "scons -u test"
101 // End: