2 Copyright © 1997-98, The AROS Development Team. All rights reserved.
5 Desc: Demo of new OOP system
14 #include "timerclass.h"
18 struct timeval start_time
;
19 struct timeval elapsed_time
;
22 /* Does dest - src => dest */
23 VOID
SubTime(struct timeval
*dest
, struct timeval
*src
)
25 /* Normalize the terms */
26 while(src
->tv_usec
> 999999)
29 src
->tv_usec
-= 1000000;
31 while(dest
->tv_usec
> 999999)
34 dest
->tv_usec
-= 1000000;
37 dest
->tv_usec
-= src
->tv_usec
;
38 dest
->tv_sec
-= src
->tv_sec
;
42 dest
->tv_usec
+= 1000000;
49 VOID
_Timer_Start(Class
*cl
, Object
*o
, Msg msg
)
51 struct TimerData
*data
= INST_DATA(cl
, o
);
52 gettimeofday(&(data
->start_time
), NULL
);
56 VOID
_Timer_Stop(Class
*cl
, Object
*o
, Msg msg
)
58 struct TimerData
*data
= INST_DATA(cl
, o
);
59 gettimeofday(&(data
->elapsed_time
), NULL
);
61 SubTime(&(data
->elapsed_time
), &(data
->start_time
));
66 VOID
_Timer_PrintElapsed(Class
*cl
, Object
*o
, Msg msg
)
68 struct TimerData
*data
= INST_DATA(cl
, o
);
70 printf("%d secs and %d micros\n"
71 ,data
->elapsed_time
.tv_sec
72 ,data
->elapsed_time
.tv_usec
);
76 IPTR
_Timer_TestMethod(Class
*cl
, Msg msg
)
82 Class
*MakeTimerClass()
95 cl
= MakeClass(TIMERCLASS
, ROOTCLASS
, methods
, sizeof (struct TimerData
), NUM_TIMER_METHODS
);
104 VOID
FreeTimerClass(Class
*cl
)