OSDN Git Service

first
[psychlops/cpp.git] / psychlops / platform / win32 / psychlops_io_clock_Win32.cpp
1 /*
2  *  psychlops_io_clock_Win32.cpp
3  *  Psychlops Standard Library (MacOSX)
4  *
5  *  Last Modified 2005/12/21 by Kenchi HOSOKAWA
6  *  (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
7  */
8
9 #include <stdlib.h>
10 #include <Math.h>
11 #include <time.h>
12 #include <iostream>
13
14 #include <Windows.h>
15
16 #include "../../core/ApplicationInterfaces/psychlops_code.h"
17
18 #include "psychlops_io_clock_Win32.h"
19 #include "../../core/devices/psychlops_io_clock.h"
20
21
22 namespace Psychlops {
23
24         void Clock::initialize() {
25                 if(QueryPerformanceFrequency((_LARGE_INTEGER *)&clocks_per_a_milisecond_)==0) {
26                         throw Exception(typeid(Clock), "HARDWARE NOT SUPPORTED", "This computer does not support high-resolution performance counter.");
27                 }\r
28                 clocks_per_a_milisecond_.QuadPart /= 1000;
29         }
30
31         Clock::Clock() {
32                 update();
33         }
34         Clock::Clock(CLOCK_UNIT native_clock) {
35                 clock_ = native_clock;
36         }
37         Clock::~Clock() {}
38         void Clock::update() {
39                 QueryPerformanceCounter((_LARGE_INTEGER *)&clock_);
40         }
41 //      Clock Clock::operator -() {\r
42 //              return Clock(-clock_);\r
43 //      }\r
44         Clock Clock::operator +(Clock &rhs) {
45                 CLOCK_UNIT tmp;
46                 tmp.QuadPart = clock_.QuadPart + rhs.clock_.QuadPart;
47                 return Clock(tmp);
48         }
49         Clock Clock::operator -(Clock &rhs) {
50                 CLOCK_UNIT tmp;
51                 tmp.QuadPart = clock_.QuadPart - rhs.clock_.QuadPart;
52                 return Clock(tmp);
53         }
54         Clock & Clock::operator +=(Clock &rhs) {
55                 (*this) = (*this) + rhs;
56                 return *this;
57         }
58         Clock & Clock::operator -=(Clock &rhs) {
59                 (*this) = (*this) - rhs;
60                 return *this;
61         }
62         bool Clock::operator ==(Clock &rhs) {
63                 return (clock_.QuadPart==rhs.clock_.QuadPart);
64         }
65
66         bool Clock::operator !=(Clock &rhs) {
67                 return (clock_.QuadPart!=rhs.clock_.QuadPart);
68         }
69         bool Clock::operator >(Clock &rhs) {
70                 return (clock_.QuadPart>rhs.clock_.QuadPart);
71         }
72         bool Clock::operator <(Clock &rhs) {
73                 return (clock_.QuadPart<rhs.clock_.QuadPart);
74         }
75         bool Clock::operator >=(Clock &rhs) {
76                 return (clock_.QuadPart>=rhs.clock_.QuadPart);
77         }
78         bool Clock::operator <=(Clock &rhs) {
79                 return (clock_.QuadPart<=rhs.clock_.QuadPart);
80         }
81         double Clock::at_msec() {
82                 return (double)clock_.QuadPart/(double)clocks_per_a_milisecond_.QuadPart;
83         }
84
85         CLOCK_UNIT Clock::clocks_per_a_milisecond_;
86
87
88         long Gettime_ms() {
89                 Clock tmp;
90                 return tmp.at_msec();
91         }
92
93
94 }       /*      <- namespace Psycholops         */