gravatar
tapolcai@tmit.bme.hu
tapolcai@tmit.bme.hu
Further fixes to windows.cc (#215)
0 1 0
default
1 file changed with 15 insertions and 19 deletions:
↑ Collapse diff ↑
Show white space 48 line context
... ...
@@ -7,49 +7,57 @@
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
///\file
20 20
///\brief Some basic non-inline functions and static global data.
21 21

	
22 22
#include<lemon/bits/windows.h>
23 23

	
24 24
#ifdef WIN32
25 25
#ifndef WIN32_LEAN_AND_MEAN
26 26
#define WIN32_LEAN_AND_MEAN
27 27
#endif
28 28
#ifndef NOMINMAX
29 29
#define NOMINMAX
30 30
#endif
31
#ifdef UNICODE
32
#undef UNICODE
33
#endif
31 34
#include <windows.h>
35
#ifdef LOCALE_INVARIANT
36
#define MY_LOCALE LOCALE_INVARIANT
37
#else
38
#define MY_LOCALE LOCALE_NEUTRAL
39
#endif
32 40
#else
33 41
#include <unistd.h>
34 42
#include <ctime>
35 43
#include <sys/times.h>
36 44
#include <sys/time.h>
37 45
#endif
38 46

	
39 47
#include <cmath>
40 48
#include <sstream>
41 49

	
42 50
namespace lemon {
43 51
  namespace bits {
44 52
    void getWinProcTimes(double &rtime,
45 53
                         double &utime, double &stime,
46 54
                         double &cutime, double &cstime)
47 55
    {
48 56
#ifdef WIN32
49 57
      static const double ch = 4294967296.0e-7;
50 58
      static const double cl = 1.0e-7;
51 59

	
52 60
      FILETIME system;
53 61
      GetSystemTimeAsFileTime(&system);
54 62
      rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime;
55 63

	
... ...
@@ -66,69 +74,57 @@
66 74
        cutime = 0;
67 75
        cstime = 0;
68 76
      }
69 77
#else
70 78
      timeval tv;
71 79
      gettimeofday(&tv, 0);
72 80
      rtime=tv.tv_sec+double(tv.tv_usec)/1e6;
73 81

	
74 82
      tms ts;
75 83
      double tck=sysconf(_SC_CLK_TCK);
76 84
      times(&ts);
77 85
      utime=ts.tms_utime/tck;
78 86
      stime=ts.tms_stime/tck;
79 87
      cutime=ts.tms_cutime/tck;
80 88
      cstime=ts.tms_cstime/tck;
81 89
#endif
82 90
    }
83 91

	
84 92
    std::string getWinFormattedDate()
85 93
    {
86 94
      std::ostringstream os;
87 95
#ifdef WIN32
88 96
      SYSTEMTIME time;
89 97
      GetSystemTime(&time);
90
#if defined(_MSC_VER) && (_MSC_VER < 1500)
91
      LPWSTR buf1, buf2, buf3;
92
      if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
93
                        L"ddd MMM dd", buf1, 11) &&
94
          GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time,
95
                        L"HH':'mm':'ss", buf2, 9) &&
96
          GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
97
                        L"yyyy", buf3, 5)) {
98
      char buf1[11], buf2[9], buf3[5];
99
	  if (GetDateFormat(MY_LOCALE, 0, &time,
100
                        ("ddd MMM dd"), buf1, 11) &&
101
          GetTimeFormat(MY_LOCALE, 0, &time,
102
                        ("HH':'mm':'ss"), buf2, 9) &&
103
          GetDateFormat(MY_LOCALE, 0, &time,
104
                        ("yyyy"), buf3, 5)) {
98 105
        os << buf1 << ' ' << buf2 << ' ' << buf3;
99 106
      }
100
#else
101
      char buf1[11], buf2[9], buf3[5];
102
      if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
103
                        "ddd MMM dd", buf1, 11) &&
104
          GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time,
105
                        "HH':'mm':'ss", buf2, 9) &&
106
          GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
107
                        "yyyy", buf3, 5)) {
108
        os << buf1 << ' ' << buf2 << ' ' << buf3;
109
      }
110
#endif
111 107
      else os << "unknown";
112 108
#else
113 109
      timeval tv;
114 110
      gettimeofday(&tv, 0);
115 111

	
116 112
      char cbuf[26];
117 113
      ctime_r(&tv.tv_sec,cbuf);
118 114
      os << cbuf;
119 115
#endif
120 116
      return os.str();
121 117
    }
122 118

	
123 119
    int getWinRndSeed()
124 120
    {
125 121
#ifdef WIN32
126 122
      FILETIME time;
127 123
      GetSystemTimeAsFileTime(&time);
128 124
      return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime;
129 125
#else
130 126
      timeval tv;
131 127
      gettimeofday(&tv, 0);
132 128
      return getpid() + tv.tv_sec + tv.tv_usec;
133 129
#endif
134 130
    }
0 comments (0 inline)