Ticket #215: f387d3227f87.patch
File f387d3227f87.patch, 8.0 KB (added by , 16 years ago) |
---|
-
lemon/CMakeLists.txt
# HG changeset patch # User Alpar Juttner <alpar@cs.elte.hu> # Date 1234720828 0 # Node ID f387d3227f87192eec3c7bce8752683185ffce1f # Parent daddd623ac9a2f41ef9bc6d2b083abb2d06e7a4e Wrap around the usages of windows.h diff --git a/lemon/CMakeLists.txt b/lemon/CMakeLists.txt
a b 1 1 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) 2 2 3 ADD_LIBRARY(lemon 3 SET(LEMON_LIB_SOURCES 4 4 arg_parser.cc 5 5 base.cc 6 6 color.cc 7 random.cc) 7 random.cc 8 ) 9 10 IF(WIN32) 11 SET(LEMON_LIB_SOURCES ${LEMON_LIB_SOURCES} bits/windows.cc) 12 ENDIF(WIN32) 13 14 ADD_LIBRARY(lemon 15 ${LEMON_LIB_SOURCES} 16 ) 8 17 9 18 INSTALL( 10 19 TARGETS lemon -
lemon/Makefile.am
diff --git a/lemon/Makefile.am b/lemon/Makefile.am
a b 1 1 EXTRA_DIST += \ 2 2 lemon/lemon.pc.in \ 3 lemon/CMakeLists.txt 3 lemon/CMakeLists.txt \ 4 lemon/bits/windows.h lemon/bits/windows.cc \ 4 5 5 6 pkgconfig_DATA += lemon/lemon.pc 6 7 -
new file lemon/bits/windows.cc
diff --git a/lemon/bits/windows.cc b/lemon/bits/windows.cc new file mode 100644
- + 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 4 * 5 * Copyright (C) 2003-2009 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). 8 * 9 * Permission to use, modify and distribute this software is granted 10 * provided that this copyright notice appears in all copies. For 11 * precise terms see the accompanying LICENSE file. 12 * 13 * This software is provided "AS IS" with no warranty of any kind, 14 * express or implied, and with no claim as to its suitability for any 15 * purpose. 16 * 17 */ 18 19 ///\file 20 ///\brief Some basic non-inline functions and static global data. 21 22 #include<lemon/bits/windows.h> 23 24 #ifndef WIN32_LEAN_AND_MEAN 25 #define WIN32_LEAN_AND_MEAN 26 #endif 27 #ifndef NOMINMAX 28 #define NOMINMAX 29 #endif 30 31 #include <windows.h> 32 #include <cmath> 33 #include <sstream> 34 35 namespace lemon { 36 namespace bits { 37 void getWinProcTimes(double &rtime, 38 double &utime, double &stime, 39 double &cutime, double &cstime) 40 { 41 static const double ch = 4294967296.0e-7; 42 static const double cl = 1.0e-7; 43 44 FILETIME system; 45 GetSystemTimeAsFileTime(&system); 46 rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; 47 48 FILETIME create, exit, kernel, user; 49 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { 50 utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; 51 stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; 52 cutime = 0; 53 cstime = 0; 54 } else { 55 rtime = 0; 56 utime = 0; 57 stime = 0; 58 cutime = 0; 59 cstime = 0; 60 } 61 } 62 63 std::string getWinFormattedDate() 64 { 65 std::ostringstream os; 66 SYSTEMTIME time; 67 GetSystemTime(&time); 68 #if defined(_MSC_VER) && (_MSC_VER < 1500) 69 LPWSTR buf1, buf2, buf3; 70 if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, 71 L"ddd MMM dd", buf1, 11) && 72 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, 73 L"HH':'mm':'ss", buf2, 9) && 74 GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, 75 L"yyyy", buf3, 5)) { 76 os << buf1 << ' ' << buf2 << ' ' << buf3; 77 } 78 #else 79 char buf1[11], buf2[9], buf3[5]; 80 if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, 81 "ddd MMM dd", buf1, 11) && 82 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, 83 "HH':'mm':'ss", buf2, 9) && 84 GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, 85 "yyyy", buf3, 5)) { 86 os << buf1 << ' ' << buf2 << ' ' << buf3; 87 } 88 #endif 89 else os << "unknown"; 90 return os.str(); 91 } 92 } 93 } -
new file lemon/bits/windows.h
diff --git a/lemon/bits/windows.h b/lemon/bits/windows.h new file mode 100644
- + 1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 * 3 * This file is a part of LEMON, a generic C++ optimization library. 4 * 5 * Copyright (C) 2003-2009 6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport 7 * (Egervary Research Group on Combinatorial Optimization, EGRES). 8 * 9 * Permission to use, modify and distribute this software is granted 10 * provided that this copyright notice appears in all copies. For 11 * precise terms see the accompanying LICENSE file. 12 * 13 * This software is provided "AS IS" with no warranty of any kind, 14 * express or implied, and with no claim as to its suitability for any 15 * purpose. 16 * 17 */ 18 19 #ifndef LEMON_WINDOWS_H 20 #define LEMON_WINDOWS_H 21 22 #include <string> 23 24 namespace lemon { 25 namespace bits { 26 void getWinProcTimes(double &rtime, 27 double &utime, double &stime, 28 double &cutime, double &cstime); 29 std::string getWinFormattedDate(); 30 } 31 } 32 33 #endif -
lemon/graph_to_eps.h
diff --git a/lemon/graph_to_eps.h b/lemon/graph_to_eps.h
a b 29 29 #include<sys/time.h> 30 30 #include<ctime> 31 31 #else 32 #ifndef WIN32_LEAN_AND_MEAN 33 #define WIN32_LEAN_AND_MEAN 34 #endif 35 #ifndef NOMINMAX 36 #define NOMINMAX 37 #endif 38 #include<windows.h> 32 #include<lemon/bits/windows.h> 39 33 #endif 40 34 41 35 #include<lemon/math.h> … … 683 677 os << "%%Creator: LEMON, graphToEps()\n"; 684 678 685 679 { 680 os << "%%CreationDate: "; 686 681 #ifndef WIN32 687 682 timeval tv; 688 683 gettimeofday(&tv, 0); 689 684 690 685 char cbuf[26]; 691 686 ctime_r(&tv.tv_sec,cbuf); 692 os << "%%CreationDate: " <<cbuf;687 os << cbuf; 693 688 #else 694 SYSTEMTIME time; 695 GetSystemTime(&time); 696 #if defined(_MSC_VER) && (_MSC_VER < 1500) 697 LPWSTR buf1, buf2, buf3; 698 if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, 699 L"ddd MMM dd", buf1, 11) && 700 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, 701 L"HH':'mm':'ss", buf2, 9) && 702 GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, 703 L"yyyy", buf3, 5)) { 704 os << "%%CreationDate: " << buf1 << ' ' 705 << buf2 << ' ' << buf3 << std::endl; 706 } 707 #else 708 char buf1[11], buf2[9], buf3[5]; 709 if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, 710 "ddd MMM dd", buf1, 11) && 711 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, 712 "HH':'mm':'ss", buf2, 9) && 713 GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, 714 "yyyy", buf3, 5)) { 715 os << "%%CreationDate: " << buf1 << ' ' 716 << buf2 << ' ' << buf3 << std::endl; 717 } 718 #endif 689 os << bits::getWinFormattedDate(); 719 690 #endif 720 691 } 692 os << std::endl; 721 693 722 694 if (_autoArcWidthScale) { 723 695 double max_w=0; -
lemon/time_measure.h
diff --git a/lemon/time_measure.h b/lemon/time_measure.h
a b 24 24 ///\brief Tools for measuring cpu usage 25 25 26 26 #ifdef WIN32 27 #ifndef WIN32_LEAN_AND_MEAN 28 #define WIN32_LEAN_AND_MEAN 29 #endif 30 #ifndef NOMINMAX 31 #define NOMINMAX 32 #endif 33 #include <windows.h> 34 #include <cmath> 27 #include <lemon/bits/windows.h> 35 28 #else 36 29 #include <unistd.h> 37 30 #include <sys/times.h> … … 92 85 cutime=ts.tms_cutime/tck; 93 86 cstime=ts.tms_cstime/tck; 94 87 #else 95 static const double ch = 4294967296.0e-7; 96 static const double cl = 1.0e-7; 97 98 FILETIME system; 99 GetSystemTimeAsFileTime(&system); 100 rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; 101 102 FILETIME create, exit, kernel, user; 103 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { 104 utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; 105 stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; 106 cutime = 0; 107 cstime = 0; 108 } else { 109 rtime = 0; 110 utime = 0; 111 stime = 0; 112 cutime = 0; 113 cstime = 0; 114 } 88 bits::getWinProcTimes(rtime, utime, stime, cutime, cstime); 115 89 #endif 116 90 } 117 91