00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_TUIOTIME_H
00023 #define INCLUDED_TUIOTIME_H
00024
00025 #ifndef WIN32
00026 #include <pthread.h>
00027 #include <sys/time.h>
00028 #else
00029 #include <windows.h>
00030 #endif
00031
00032 #define MSEC_SECOND 1000
00033 #define USEC_SECOND 1000000
00034 #define USEC_MILLISECOND 1000
00035
00036 namespace TUIO {
00037
00048 class TuioTime {
00049
00050 private:
00051 long seconds, micro_seconds;
00052 static long start_seconds, start_micro_seconds;
00053
00054 public:
00055
00060 TuioTime () {
00061 seconds = 0;
00062 micro_seconds = 0;
00063 };
00064
00068 ~TuioTime() {}
00069
00076 TuioTime (long msec) {
00077 seconds = msec/MSEC_SECOND;
00078 micro_seconds = USEC_MILLISECOND*(msec%MSEC_SECOND);
00079 };
00080
00088 TuioTime (long sec, long usec) {
00089 seconds = sec;
00090 micro_seconds = usec;
00091 };
00092
00099 TuioTime operator+(long us) {
00100 long sec = seconds + us/USEC_SECOND;
00101 long usec = micro_seconds + us%USEC_SECOND;
00102 return TuioTime(sec,usec);
00103 };
00104
00111 TuioTime operator+(TuioTime ttime) {
00112 long sec = seconds + ttime.getSeconds();
00113 long usec = micro_seconds + ttime.getMicroseconds();
00114 sec += usec/USEC_SECOND;
00115 usec = usec%USEC_SECOND;
00116 return TuioTime(sec,usec);
00117 };
00118
00125 TuioTime operator-(long us) {
00126 long sec = seconds - us/USEC_SECOND;
00127 long usec = micro_seconds - us%USEC_SECOND;
00128
00129 if (usec<0) {
00130 usec += USEC_SECOND;
00131 sec--;
00132 }
00133
00134 return TuioTime(sec,usec);
00135 };
00136
00143 TuioTime operator-(TuioTime ttime) {
00144 long sec = seconds - ttime.getSeconds();
00145 long usec = micro_seconds - ttime.getMicroseconds();
00146
00147 if (usec<0) {
00148 usec += USEC_SECOND;
00149 sec--;
00150 }
00151
00152 return TuioTime(sec,usec);
00153 };
00154
00155
00161 void operator=(TuioTime ttime) {
00162 seconds = ttime.getSeconds();
00163 micro_seconds = ttime.getMicroseconds();
00164 };
00165
00172 bool operator==(TuioTime ttime) {
00173 if ((seconds==(long)ttime.getSeconds()) && (micro_seconds==(long)ttime.getMicroseconds())) return true;
00174 else return false;
00175 };
00176
00183 bool operator!=(TuioTime ttime) {
00184 if ((seconds!=(long)ttime.getSeconds()) || (micro_seconds!=(long)ttime.getMicroseconds())) return true;
00185 else return false;
00186 };
00187
00191 void reset() {
00192 seconds = 0;
00193 micro_seconds = 0;
00194 };
00195
00200 long getSeconds() {
00201 return seconds;
00202 };
00203
00208 long getMicroseconds() {
00209 return micro_seconds;
00210 };
00211
00216 long getTotalMilliseconds() {
00217 return seconds*MSEC_SECOND+micro_seconds/MSEC_SECOND;
00218 };
00219
00223 static void initSession();
00224
00229 static TuioTime getSessionTime();
00230
00235 static TuioTime getStartTime();
00236
00241 static TuioTime getSystemTime();
00242 };
00243 };
00244 #endif