Sirikata
|
00001 /* Sirikata 00002 * Time.hpp 00003 * 00004 * Copyright (c) 2009, Daniel Reiter Horn 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are 00009 * met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * * Neither the name of Sirikata nor the names of its contributors may 00017 * be used to endorse or promote products derived from this software 00018 * without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00021 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00022 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00023 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00024 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 */ 00032 00033 #include <sstream> 00034 00035 #ifndef _SIRIKATA_TIME_HPP_ 00036 #define _SIRIKATA_TIME_HPP_ 00037 #include "../task/Time.hpp" 00038 namespace Sirikata { 00039 class Time : private Task::LocalTime{ 00040 00041 Time (const LocalTime &local):LocalTime(local) { 00042 00043 } 00044 public: 00045 Time () 00046 : LocalTime() 00047 {} 00048 00049 Time (uint64 raw) :LocalTime(raw){} 00050 00051 uint64 raw() const { 00052 return static_cast<const LocalTime*>(this)->raw(); 00053 } 00055 inline bool operator== (const Time &other) const { 00056 return *static_cast<const LocalTime*>(this)==other; 00057 } 00058 inline bool operator!= (const Time& other) const { 00059 return *static_cast<const LocalTime*>(this)!=other; 00060 } 00061 00062 00064 inline bool operator< (const Time &other) const { 00065 return *static_cast<const LocalTime*>(this)<other; 00066 } 00067 inline bool operator<= (const Time &other) const { 00068 return *static_cast<const LocalTime*>(this)<=other; 00069 } 00070 inline bool operator> (const Time &other) const { 00071 return *static_cast<const LocalTime*>(this)>other; 00072 } 00073 inline bool operator>= (const Time &other) const { 00074 return *static_cast<const LocalTime*>(this)>=other; 00075 } 00076 00082 inline Duration operator- (const Time &other) const { 00083 return *static_cast<const LocalTime*>(this)-other; 00084 } 00090 inline Time operator+ (const Duration &otherDelta) const { 00091 return *static_cast<const LocalTime*>(this)+otherDelta; 00092 } 00093 inline Time operator- (const Duration &otherDelta) const { 00094 return *static_cast<const LocalTime*>(this)-otherDelta; 00095 } 00096 inline void operator+= (const Duration &otherDelta) { 00097 return *static_cast<LocalTime*>(this)+=otherDelta; 00098 } 00099 inline void operator-= (const Duration &otherDelta) { 00100 return *static_cast<LocalTime*>(this)-=otherDelta; 00101 } 00102 00103 static Time microseconds(int64 abstime){ 00104 return Time(abstime); 00105 } 00106 00113 static Time now(const Duration&spaceDurationOffset){ 00114 return Time(LocalTime::now()+spaceDurationOffset); 00115 } 00116 00120 static Time local() { 00121 return now(Duration::zero()); 00122 } 00123 00129 static Time epoch() { return Time(0); } 00130 00138 static Time null() { return Time(0); } 00142 static Time convertFrom(const LocalTime<, const Duration&serverOffset){ 00143 return Time(lt)+serverOffset; 00144 } 00145 }; 00146 } 00147 #endif