# HG changeset patch # User Alpar Juttner # Date 1234796612 0 # Node ID 879c55700cd4bf2903772de56606fc0aa6e99710 # Parent daddd623ac9a2f41ef9bc6d2b083abb2d06e7a4e Wrap around the usages of windows.h diff -r daddd623ac9a -r 879c55700cd4 lemon/CMakeLists.txt --- a/lemon/CMakeLists.txt Tue Feb 10 17:21:26 2009 +0000 +++ b/lemon/CMakeLists.txt Mon Feb 16 15:03:32 2009 +0000 @@ -4,7 +4,9 @@ arg_parser.cc base.cc color.cc - random.cc) + random.cc + bits/windows.cc +) INSTALL( TARGETS lemon diff -r daddd623ac9a -r 879c55700cd4 lemon/Makefile.am --- a/lemon/Makefile.am Tue Feb 10 17:21:26 2009 +0000 +++ b/lemon/Makefile.am Mon Feb 16 15:03:32 2009 +0000 @@ -10,7 +10,8 @@ lemon/arg_parser.cc \ lemon/base.cc \ lemon/color.cc \ - lemon/random.cc + lemon/random.cc \ + lemon/bits/windows.cc #lemon_libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS) $(SOPLEX_CXXFLAGS) #lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS) $(SOPLEX_LIBS) @@ -40,7 +41,8 @@ lemon/smart_graph.h \ lemon/time_measure.h \ lemon/tolerance.h \ - lemon/unionfind.h + lemon/unionfind.h \ + lemon/bits/windows.h bits_HEADERS += \ lemon/bits/alteration_notifier.h \ diff -r daddd623ac9a -r 879c55700cd4 lemon/bits/windows.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/bits/windows.cc Mon Feb 16 15:03:32 2009 +0000 @@ -0,0 +1,136 @@ +/* -*- mode: C++; indent-tabs-mode: nil; -*- + * + * This file is a part of LEMON, a generic C++ optimization library. + * + * Copyright (C) 2003-2009 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +///\file +///\brief Some basic non-inline functions and static global data. + +#include + +#ifdef WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#else +#include +#include +#include +#include +#endif + +#include +#include + +namespace lemon { + namespace bits { + void getWinProcTimes(double &rtime, + double &utime, double &stime, + double &cutime, double &cstime) + { +#ifdef WIN32 + static const double ch = 4294967296.0e-7; + static const double cl = 1.0e-7; + + FILETIME system; + GetSystemTimeAsFileTime(&system); + rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; + + FILETIME create, exit, kernel, user; + if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { + utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; + stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; + cutime = 0; + cstime = 0; + } else { + rtime = 0; + utime = 0; + stime = 0; + cutime = 0; + cstime = 0; + } +#else + timeval tv; + gettimeofday(&tv, 0); + rtime=tv.tv_sec+double(tv.tv_usec)/1e6; + + tms ts; + double tck=sysconf(_SC_CLK_TCK); + times(&ts); + utime=ts.tms_utime/tck; + stime=ts.tms_stime/tck; + cutime=ts.tms_cutime/tck; + cstime=ts.tms_cstime/tck; +#endif + } + + std::string getWinFormattedDate() + { + std::ostringstream os; +#ifdef WIN32 + SYSTEMTIME time; + GetSystemTime(&time); +#if defined(_MSC_VER) && (_MSC_VER < 1500) + LPWSTR buf1, buf2, buf3; + if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, + L"ddd MMM dd", buf1, 11) && + GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, + L"HH':'mm':'ss", buf2, 9) && + GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, + L"yyyy", buf3, 5)) { + os << buf1 << ' ' << buf2 << ' ' << buf3; + } +#else + char buf1[11], buf2[9], buf3[5]; + if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, + "ddd MMM dd", buf1, 11) && + GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, + "HH':'mm':'ss", buf2, 9) && + GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, + "yyyy", buf3, 5)) { + os << buf1 << ' ' << buf2 << ' ' << buf3; + } +#endif + else os << "unknown"; +#else + timeval tv; + gettimeofday(&tv, 0); + + char cbuf[26]; + ctime_r(&tv.tv_sec,cbuf); + os << cbuf; +#endif + return os.str(); + } + + int getWinRndSeed() + { +#ifdef WIN32 + FILETIME time; + GetSystemTimeAsFileTime(&time); + return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime; +#else + timeval tv; + gettimeofday(&tv, 0); + return getpid() + tv.tv_sec + tv.tv_usec; +#endif + } + } +} diff -r daddd623ac9a -r 879c55700cd4 lemon/bits/windows.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/bits/windows.h Mon Feb 16 15:03:32 2009 +0000 @@ -0,0 +1,34 @@ +/* -*- mode: C++; indent-tabs-mode: nil; -*- + * + * This file is a part of LEMON, a generic C++ optimization library. + * + * Copyright (C) 2003-2009 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_WINDOWS_H +#define LEMON_WINDOWS_H + +#include + +namespace lemon { + namespace bits { + void getWinProcTimes(double &rtime, + double &utime, double &stime, + double &cutime, double &cstime); + std::string getWinFormattedDate(); + int getWinRndSeed(); + } +} + +#endif diff -r daddd623ac9a -r 879c55700cd4 lemon/graph_to_eps.h --- a/lemon/graph_to_eps.h Tue Feb 10 17:21:26 2009 +0000 +++ b/lemon/graph_to_eps.h Mon Feb 16 15:03:32 2009 +0000 @@ -29,13 +29,7 @@ #include #include #else -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include +#include #endif #include @@ -683,41 +677,19 @@ os << "%%Creator: LEMON, graphToEps()\n"; { + os << "%%CreationDate: "; #ifndef WIN32 timeval tv; gettimeofday(&tv, 0); char cbuf[26]; ctime_r(&tv.tv_sec,cbuf); - os << "%%CreationDate: " << cbuf; + os << cbuf; #else - SYSTEMTIME time; - GetSystemTime(&time); -#if defined(_MSC_VER) && (_MSC_VER < 1500) - LPWSTR buf1, buf2, buf3; - if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - L"ddd MMM dd", buf1, 11) && - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, - L"HH':'mm':'ss", buf2, 9) && - GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - L"yyyy", buf3, 5)) { - os << "%%CreationDate: " << buf1 << ' ' - << buf2 << ' ' << buf3 << std::endl; - } -#else - char buf1[11], buf2[9], buf3[5]; - if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - "ddd MMM dd", buf1, 11) && - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, - "HH':'mm':'ss", buf2, 9) && - GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, - "yyyy", buf3, 5)) { - os << "%%CreationDate: " << buf1 << ' ' - << buf2 << ' ' << buf3 << std::endl; - } -#endif + os << bits::getWinFormattedDate(); #endif } + os << std::endl; if (_autoArcWidthScale) { double max_w=0; diff -r daddd623ac9a -r 879c55700cd4 lemon/random.h --- a/lemon/random.h Tue Feb 10 17:21:26 2009 +0000 +++ b/lemon/random.h Mon Feb 16 15:03:32 2009 +0000 @@ -77,7 +77,7 @@ #include #include #else -#include +#include #endif ///\ingroup misc @@ -666,9 +666,7 @@ gettimeofday(&tv, 0); seed(getpid() + tv.tv_sec + tv.tv_usec); #else - FILETIME time; - GetSystemTimeAsFileTime(&time); - seed(GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime); + seed(bits::getWinRndSeed()); #endif return true; } diff -r daddd623ac9a -r 879c55700cd4 lemon/time_measure.h --- a/lemon/time_measure.h Tue Feb 10 17:21:26 2009 +0000 +++ b/lemon/time_measure.h Mon Feb 16 15:03:32 2009 +0000 @@ -24,14 +24,7 @@ ///\brief Tools for measuring cpu usage #ifdef WIN32 -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include -#include +#include #else #include #include @@ -92,26 +85,7 @@ cutime=ts.tms_cutime/tck; cstime=ts.tms_cstime/tck; #else - static const double ch = 4294967296.0e-7; - static const double cl = 1.0e-7; - - FILETIME system; - GetSystemTimeAsFileTime(&system); - rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; - - FILETIME create, exit, kernel, user; - if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { - utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; - stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; - cutime = 0; - cstime = 0; - } else { - rtime = 0; - utime = 0; - stime = 0; - cutime = 0; - cstime = 0; - } + bits::getWinProcTimes(rtime, utime, stime, cutime, cstime); #endif }