0021189: Clean up KAS:dev:ros and Products
[occt.git] / samples / qt / VoxelDemo / src / Timer.cpp
1 // Timer.cpp: implementation of the Timer class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include "Timer.h"
6
7 //////////////////////////////////////////////////////////////////////
8 // Construction/Destruction
9 //////////////////////////////////////////////////////////////////////
10
11 Timer::Timer():myWriter(0) {}
12
13 Timer::Timer(const char* filename)
14 {
15         myWriter = fopen(filename, "a");
16 }
17
18 Timer::~Timer()
19 {
20         if (myWriter)
21                 fclose(myWriter);
22 }
23
24 void Timer::Start() {
25         myTimer.Reset();
26         myTimer.Start();
27 }
28
29 void Timer::Stop() {
30         myTimer.Stop();
31 }
32
33 void Timer::Continue() {
34         myTimer.Start();
35 }
36
37 void Timer::Reset() {
38         myTimer.Reset();
39 }
40
41 float Timer::Seconds() {
42   Standard_Real sec, cpu;
43   Standard_Integer minutes, hours;
44   myTimer.Show(sec, minutes, hours, cpu);
45   return (float) sec;
46 }
47
48 int Timer::Minutes() {
49   Standard_Real sec, cpu;
50   Standard_Integer minutes, hours;
51   myTimer.Show(sec, minutes, hours, cpu);
52   return minutes;
53 }
54
55 void Timer::Print(char* label) {
56         Standard_Real seconds, cpu;
57         Standard_Integer minutes, hours;
58         myTimer.Show(seconds, minutes, hours, cpu);
59         if (myWriter)
60         {
61                 fprintf(myWriter, "%s took %d minutes %g seconds\n", label, minutes, seconds);
62         }
63         else
64         {
65                 cout<<label<<" took "<<minutes<<" minutes, "<<seconds<<" seconds"<<endl;
66         }
67 }