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
);
57 VOID
_Timer_Stop(Class
*cl
, Object
*o
, Msg msg
)
59 struct TimerData
*data
= INST_DATA(cl
, o
);
60 gettimeofday(&(data
->elapsed_time
), NULL
);
62 SubTime(&(data
->elapsed_time
), &(data
->start_time
));
67 VOID
_Timer_PrintElapsed(Class
*cl
, Object
*o
, Msg msg
)
69 struct TimerData
*data
= INST_DATA(cl
, o
);
71 printf("%d secs and %d micros\n"
72 ,data
->elapsed_time
.tv_sec
73 ,data
->elapsed_time
.tv_usec
);
77 IPTR
_Timer_TestMethod(Class
*cl
, Msg msg
)
83 Class
*MakeTimerClass()
85 struct MethodDescr timerdescr
[] =
87 {_Timer_Start
, M_Timer_Start
},
88 {_Timer_Stop
, M_Timer_Stop
},
89 {_Timer_PrintElapsed
, M_Timer_PrintElapsed
},
90 {_Timer_TestMethod
, M_Timer_TestMethod
},
96 cl
= MakeClass(TIMERCLASS
, ROOTCLASS
, timerdescr
, sizeof (struct TimerData
), NUM_TIMER_METHODS
);
105 VOID
FreeTimerClass(Class
*cl
)