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 if (sec<0) { sec=0; usec=0; };
00134
00135 return TuioTime(sec,usec);
00136 };
00137
00144 TuioTime operator-(TuioTime ttime) {
00145 long sec = seconds - ttime.getSeconds();
00146 long usec = micro_seconds - ttime.getMicroseconds();
00147
00148 if (usec<0) {
00149 usec += USEC_SECOND;
00150 sec--;
00151 }
00152 if (sec<0) { sec=0; usec=0; };
00153
00154 return TuioTime(sec,usec);
00155 };
00156
00157
00163 void operator=(TuioTime ttime) {
00164 seconds = ttime.getSeconds();
00165 micro_seconds = ttime.getMicroseconds();
00166 };
00167
00174 bool operator==(TuioTime ttime) {
00175 if ((seconds==(long)ttime.getSeconds()) && (micro_seconds==(long)ttime.getMicroseconds())) return true;
00176 else return false;
00177 };
00178
00185 bool operator!=(TuioTime ttime) {
00186 if ((seconds!=(long)ttime.getSeconds()) || (micro_seconds!=(long)ttime.getMicroseconds())) return true;
00187 else return false;
00188 };
00189
00193 void reset() {
00194 seconds = 0;
00195 micro_seconds = 0;
00196 };
00197
00202 int getSeconds() {
00203 return seconds;
00204 };
00205
00210 int getMicroseconds() {
00211 return micro_seconds;
00212 };
00213
00218 long getTotalMilliseconds() {
00219 return seconds*MSEC_SECOND+micro_seconds/MSEC_SECOND;
00220 };
00221
00225 static void initSession();
00226
00231 static TuioTime getSessionTime();
00232
00237 static TuioTime getStartTime();
00238
00243 static TuioTime getSystemTime();
00244 };
00245 };
00246 #endif