00001 /* 00002 Aseba - an event-based framework for distributed robot control 00003 Copyright (C) 2007--2009: 00004 Stephane Magnenat <stephane at magnenat dot net> 00005 (http://stephane.magnenat.net) 00006 and other contributors, see authors.txt for details 00007 Mobots group, Laboratory of Robotics Systems, EPFL, Lausanne 00008 00009 This program is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 any other version as decided by the two original authors 00013 Stephane Magnenat and Valentin Longchamp. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 #ifndef ASEBA_UTILS_H 00025 #define ASEBA_UTILS_H 00026 00027 #include <iostream> 00028 #include <string> 00029 #include <cassert> 00030 00031 namespace Aseba 00032 { 00037 00039 struct UnifiedTime 00040 { 00042 typedef long long unsigned Value; 00044 Value value; 00045 00047 UnifiedTime(); 00049 UnifiedTime(Value ms); 00051 UnifiedTime(Value seconds, Value milliseconds); 00052 00054 void operator +=(const UnifiedTime &that) { value += that.value; } 00056 void operator -=(const UnifiedTime &that) { value -= that.value; } 00058 void operator /=(const long long unsigned factor) { assert(factor); value /= factor; } 00060 void operator *=(const long long unsigned factor) { value *= factor; } 00062 UnifiedTime operator +(const UnifiedTime &that) const { return UnifiedTime(value + that.value); } 00064 UnifiedTime operator -(const UnifiedTime &that) const { return UnifiedTime(value - that.value); } 00066 UnifiedTime operator /(const long long unsigned factor) const { assert(factor); return UnifiedTime(value / factor); } 00068 UnifiedTime operator *(const long long unsigned factor) const { return UnifiedTime(value * factor); } 00070 bool operator <(const UnifiedTime &that) const { return value < that.value; } 00071 00073 void sleep() const; 00074 00076 std::string toHumanReadableStringFromEpoch() const; 00077 00079 std::string toRawTimeString() const; 00080 00082 static UnifiedTime fromRawTimeString(const std::string& rawTimeString); 00083 }; 00084 00086 void dumpTime(std::ostream &stream, bool raw = false); 00087 00090 }; 00091 00092 #endif