00001 /* 00002 * Copyright 2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef __TIME_H__ 00018 #define __TIME_H__ 00019 00020 #include "../compat/inttypes.h" 00021 00022 namespace oasys { 00023 00027 struct Time { 00028 u_int32_t sec_; 00029 u_int32_t usec_; 00030 00031 Time(u_int32_t sec = 0, 00032 u_int32_t usec = 0) 00033 : sec_(sec), usec_(usec) 00034 { 00035 cleanup(); 00036 } 00037 00039 void get_time(); 00040 00042 double in_seconds(); 00043 00045 u_int32_t in_microseconds(); 00046 00048 u_int32_t in_milliseconds(); 00049 00051 // current time. 00052 u_int32_t elapsed_ms(); 00053 00055 Time operator+(const Time& t) const; 00056 Time operator-(const Time& t) const; 00057 Time& operator+=(const Time& t); 00058 Time& operator-=(const Time& t); 00059 00060 bool operator==(const Time& t) const; 00061 bool operator<(const Time& t) const; 00062 bool operator>(const Time& t) const; 00063 bool operator>=(const Time& t) const; 00064 bool operator<=(const Time& t) const; 00066 00067 // Use default operator= 00068 00070 void cleanup(); 00071 }; 00072 00073 } // namespace oasys 00074 00075 #endif /* __TIME_H__ */