DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Clock.h
1 
17 #pragma once
18 
33 #if defined(Clock_RECURSES)
34 #error Recursive header files inclusion detected in Clock.h
35 #else // defined(Clock_RECURSES)
36 
37 #define Clock_RECURSES
38 
39 #if !defined Clock_h
40 
41 #define Clock_h
42 
44 // Inclusions
45 #include <iostream>
46 #include <cstdlib>
47 
48 #if ( (defined(UNIX)||defined(unix)||defined(linux)) )
49 #include <sys/time.h>
50 #include <time.h>
51 #endif
52 
53 #ifdef __MACH__
54 #include <mach/clock.h>
55 #include <mach/mach.h>
56 #endif
57 
58 #if ( (defined(WIN32)) )
59 #include <time.h>
60 #endif
61 
62 
63 
65 
66 namespace DGtal
67 {
68 
70  // class Clock
95  class Clock
96  {
97  // ----------------------- Standard services ------------------------------
98  // -------------------------- timing services -------------------------------
99  public:
103  void startClock();
104 
109  double stopClock();
110 
115  Clock();
116 
120  ~Clock();
121 
122  // ----------------------- Interface --------------------------------------
123  public:
124 
129  void selfDisplay( std::ostream & out ) const;
130 
135  bool isValid() const;
136 
137  // ------------------------- Private Datas --------------------------------
138  private:
139 
141 #if ( (defined(UNIX)||defined(unix)||defined(linux) || defined(__MACH__) ) )
142  struct timespec myTimerStart;
143 #endif
144 
145 #if ( (defined(WIN32)) )
146  clock_t myFirstTick;
147 #endif
148 
149  }; // end of class Clock
150 
151 
158  inline
159  std::ostream&
160  operator<<( std::ostream & out, const Clock & object )
161  {
162  object.selfDisplay( out );
163  return out;
164  }
165 
166 
167 } // namespace DGtal
168 
170 // Inline methods
171 #include "DGtal/base/Clock.ih"
172 
173 #endif // !defined Clock_h
174 
175 #undef Clock_RECURSES
176 #endif // else defined(Clock_RECURSES)