Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ClockService.cc

Go to the documentation of this file.
00001 // $Id: ClockService.cc 1772 2011-03-10 12:45:21Z tho $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #include "ClockService.hh"
00027 //#include "ClockService.ih"
00028 
00029 // Custom includes
00030 #include <boost/regex.hpp>
00031 #include <senf/Utils/Console/Traits.hh>
00032 
00033 //#include "ClockService.mpp"
00034 #define prefix_
00035 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00036 
00037 prefix_ void
00038 senf::parseClockServiceInterval(console::ParseCommandInfo::TokensRange const & tokens,
00039                                 ClockService::clock_type & out)
00040 {
00041     out = 0;
00042     std::string value;
00043     {
00044         console::CheckedArgumentIteratorWrapper arg (tokens);
00045         console::parse( *(arg++), value );
00046     }
00047     static boost::sregex_iterator::regex_type rx ("[mun]?[dhms]");
00048     boost::sregex_iterator i (value.begin(), value.end(), rx);
00049     boost::sregex_iterator const i_end;
00050     std::string::const_iterator j (value.begin());
00051     for (; i != i_end; ++i) {
00052         boost::sregex_iterator::value_type::value_type match ((*i)[0]);
00053         long double v (boost::lexical_cast<long double>(std::string(j, match.first)));
00054         char scale (0);
00055         char unit (0);
00056         if (match.length() == 2) {
00057             scale = *match.first;
00058             unit = *boost::next(match.first);
00059         } else {
00060             SENF_ASSERT( match.length() == 1,
00061                          "Internal failure: RegEx match returns weird number of matches" );
00062             unit = *match.first;
00063         }
00064         switch (scale) {
00065         case 0: break;
00066         case 'n': v /= 1000.0;
00067         case 'u': v /= 1000.0;
00068         case 'm': v /= 1000.0;
00069         }
00070         switch (unit) {
00071         case 'd': v *= 24.0;
00072         case 'h': v *= 60.0;
00073         case 'm': v *= 60.0;
00074         case 's': v *= 1000000000.0;
00075         }
00076         out += ClockService::nanoseconds(ClockService::int64_type(v));
00077         j = match.second;
00078     }
00079     if (j != value.end())
00080         throw console::SyntaxErrorException();
00081 }
00082 
00083 prefix_ void senf::formatClockServiceInterval(ClockService::clock_type interval,
00084                                               std::ostream & os)
00085 {
00086     os << interval << "ns";
00087 }
00088 
00089 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00090 #undef prefix_
00091 //#include "ClockService.mpp"
00092 
00093 
00094 // Local Variables:
00095 // mode: c++
00096 // fill-column: 100
00097 // comment-column: 40
00098 // c-file-style: "senf"
00099 // indent-tabs-mode: nil
00100 // ispell-local-dictionary: "american"
00101 // compile-command: "scons -u test"
00102 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research