0029152: Coding Rules - eliminate GCC compiler warnings -Wmisleading-indentation...
[occt.git] / src / OSD / OSD_Timer.hxx
1 // Created on: 2018-03-15
2 // Created by: Stephan GARNAUD (ARM)
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _OSD_Timer_HeaderFile
18 #define _OSD_Timer_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Real.hxx>
25 #include <OSD_Chronometer.hxx>
26 #include <Standard_OStream.hxx>
27 #include <Standard_Integer.hxx>
28
29
30 //! Working on heterogeneous platforms
31 //! we need to use the system call gettimeofday.
32 //! This function is portable and it measures ELAPSED
33 //! time and CPU time in seconds and microseconds.
34 //! Example: OSD_Timer aTimer;
35 //! aTimer.Start();   // Start  the timers (t1).
36 //! .....            // Do something.
37 //! aTimer.Stop();    // Stop the timers (t2).
38 //! aTimer.Show();    // Give the elapsed time between t1 and t2.
39 //! // Give also the process CPU time between
40 //! // t1 and t2.
41 class OSD_Timer  : public OSD_Chronometer
42 {
43 public:
44
45   DEFINE_STANDARD_ALLOC
46
47   //! Builds a Chronometer initialized and stopped.
48   Standard_EXPORT OSD_Timer();
49
50   //! Stops and reinitializes the timer with specified elapsed time.
51   Standard_EXPORT void Reset (const Standard_Real theTimeElapsedSec);
52
53   //! Stops and reinitializes the timer with zero elapsed time.
54   Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
55
56   //! Restarts the Timer.
57   Standard_EXPORT virtual void Restart() Standard_OVERRIDE;
58
59   //! Shows both the elapsed time and CPU time on the standard output
60   //! stream <cout>.The chronometer can be running (Lap Time) or
61   //! stopped.
62   Standard_EXPORT virtual void Show() const Standard_OVERRIDE;
63   
64   //! Shows both the elapsed time and CPU  time on the
65   //! output stream <OS>.
66   Standard_EXPORT virtual void Show (Standard_OStream& os) const Standard_OVERRIDE;
67   
68   //! returns both the elapsed time(seconds,minutes,hours)
69   //! and CPU  time.
70   Standard_EXPORT void Show (Standard_Real& theSeconds, Standard_Integer& theMinutes, Standard_Integer& theHours, Standard_Real& theCPUtime) const;
71   
72   //! Stops the Timer.
73   Standard_EXPORT virtual void Stop() Standard_OVERRIDE;
74   
75   //! Starts (after Create or Reset) or restarts (after Stop)
76   //! the Timer.
77   Standard_EXPORT virtual void Start() Standard_OVERRIDE;
78   
79   //! Returns elapsed time in seconds.
80   Standard_EXPORT Standard_Real ElapsedTime() const;
81
82 private:
83
84   Standard_Real TimeStart;
85   Standard_Real TimeCumul;
86
87 };
88
89 #endif // _OSD_Timer_HeaderFile