[Lemon-commits] Alpar Juttner: Merge

Lemon HG hg at lemon.cs.elte.hu
Fri Nov 20 14:13:00 CET 2009


details:   http://lemon.cs.elte.hu/hg/lemon/rev/b9b3473327e3
changeset: 562:b9b3473327e3
user:      Alpar Juttner <alpar [at] cs.elte.hu>
date:      Mon Feb 16 18:15:52 2009 +0000
description:
	Merge

diffstat:

 lemon/CMakeLists.txt  |    4 +-
 lemon/Makefile.am     |    6 +-
 lemon/bits/windows.cc |  136 +++++++++++++++++++++++++++++++++++++++++++++
 lemon/bits/windows.h  |   34 +++++++++++
 lemon/graph_to_eps.h  |   38 +-----------
 lemon/random.h        |    6 +-
 lemon/time_measure.h  |   30 +---------
 7 files changed, 186 insertions(+), 68 deletions(-)

diffs (truncated from 351 to 300 lines):

diff --git a/lemon/CMakeLists.txt b/lemon/CMakeLists.txt
--- a/lemon/CMakeLists.txt
+++ b/lemon/CMakeLists.txt
@@ -14,7 +14,9 @@
   color.cc
   lp_base.cc
   lp_skeleton.cc
-  random.cc)
+  random.cc
+  bits/windows.cc
+)
 
 IF(HAVE_GLPK)
   SET(LEMON_SOURCES ${LEMON_SOURCES} glpk.cc)
diff --git a/lemon/Makefile.am b/lemon/Makefile.am
--- a/lemon/Makefile.am
+++ b/lemon/Makefile.am
@@ -12,7 +12,8 @@
 	lemon/color.cc \
 	lemon/lp_base.cc \
 	lemon/lp_skeleton.cc \
-	lemon/random.cc
+        lemon/random.cc \
+	lemon/bits/windows.cc
 
 
 lemon_libemon_la_CXXFLAGS = \
@@ -90,7 +91,8 @@
 	lemon/suurballe.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 --git a/lemon/bits/windows.cc b/lemon/bits/windows.cc
new file mode 100644
--- /dev/null
+++ b/lemon/bits/windows.cc
@@ -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<lemon/bits/windows.h>
+
+#ifdef WIN32
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include <windows.h>
+#else
+#include <unistd.h>
+#include <ctime>
+#include <sys/times.h>
+#include <sys/time.h>
+#endif
+
+#include <cmath>
+#include <sstream>
+
+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 --git a/lemon/bits/windows.h b/lemon/bits/windows.h
new file mode 100644
--- /dev/null
+++ b/lemon/bits/windows.h
@@ -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 <string>
+
+namespace lemon {
+  namespace bits {
+    void getWinProcTimes(double &rtime,
+                         double &utime, double &stime,
+                         double &cutime, double &cstime);
+    std::string getWinFormattedDate();
+    int getWinRndSeed();
+  }
+}
+
+#endif
diff --git a/lemon/graph_to_eps.h b/lemon/graph_to_eps.h
--- a/lemon/graph_to_eps.h
+++ b/lemon/graph_to_eps.h
@@ -29,13 +29,7 @@
 #include<sys/time.h>
 #include<ctime>
 #else
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN
-#endif
-#ifndef NOMINMAX
-#define NOMINMAX
-#endif
-#include<windows.h>
+#include<lemon/bits/windows.h>
 #endif
 
 #include<lemon/math.h>
@@ -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 --git a/lemon/random.h b/lemon/random.h
--- a/lemon/random.h
+++ b/lemon/random.h
@@ -77,7 +77,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #else
-#include <windows.h>
+#include <lemon/bits/windows.h>
 #endif
 
 ///\ingroup misc
@@ -662,9 +662,7 @@
       gettimeofday(&tv, 0);
       seed(getpid() + tv.tv_sec + tv.tv_usec);
 #else
-      FILETIME time;
-      GetSystemTimeAsFileTime(&time);
-      seed(GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime);



More information about the Lemon-commits mailing list