[Lemon-commits] [lemon_svn] deba: r2667 - in hugo/trunk/lemon: . bits

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:54:20 CET 2006


Author: deba
Date: Fri Mar 31 14:51:44 2006
New Revision: 2667

Added:
   hugo/trunk/lemon/bits/mingw32_time.h
Modified:
   hugo/trunk/lemon/graph_to_eps.h
   hugo/trunk/lemon/time_measure.h

Log:
MinGW32 compatibility



Added: hugo/trunk/lemon/bits/mingw32_time.h
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/bits/mingw32_time.h	Fri Mar 31 14:51:44 2006
@@ -0,0 +1,137 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * 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_BITS_MINGW32_TIME_H
+#define LEMON_BITS_MINGW32_TIME_H
+
+#ifdef WIN32
+
+#include <windows.h>
+#include <time.h>
+#include "dos.h"
+
+static const char days[] = 
+"Sun Mon Tue Wed Thu Fri Sat ";
+static const char months[] = 
+"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
+
+inline void num2str(char *c,int i) {
+  c[0]=i/10+'0';
+  c[1]=i%10+'0';
+}
+
+inline char *asctime_r(const struct tm *t, char *buf) {
+  /* "Wed Jun 30 21:49:08 1993\n" */
+  *(int*)buf=*(int*)(days+(t->tm_wday<<2));
+  *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
+  num2str(buf+8,t->tm_mday);
+  if (buf[8]=='0') buf[8]=' ';
+  buf[10]=' ';
+  num2str(buf+11,t->tm_hour);
+  buf[13]=':';
+  num2str(buf+14,t->tm_min);
+  buf[16]=':';
+  num2str(buf+17,t->tm_sec);
+  buf[19]=' ';
+  num2str(buf+20,(t->tm_year+1900)/100);
+  num2str(buf+22,(t->tm_year+1900)%100);
+  buf[24]='\n'; buf[25]='\0';
+  return buf;
+}
+
+inline struct tm * localtime_r (const time_t *t, struct tm *tm) {
+  struct tm *tmp;
+  
+  if ((tmp = localtime(t)) && tm)
+    *tm = *tmp;
+  else
+    return 0;
+  
+  return tm;
+}
+
+inline char *ctime_r(const time_t * tim_p , char * result) {
+  struct tm tm;
+  return asctime_r (localtime_r (tim_p, &tm), result);
+}
+
+
+inline int gettimeofday(struct timeval * tp, struct timezone *) {
+  SYSTEMTIME systime;
+
+  if (tp) {
+    struct tm tmrec;
+    time_t theTime = time(NULL);
+    
+    
+    tmrec = *localtime(&theTime);
+    tp->tv_sec = mktime(&tmrec);
+    GetLocalTime(&systime); /* system time */
+
+    tp->tv_usec = systime.wMilliseconds * 1000;
+  }
+  return 0;
+}
+
+
+struct tms {
+  long	tms_utime;
+  long	tms_stime;
+  long	tms_cutime;
+  long	tms_cstime;
+};
+
+inline long filetime_to_clock(FILETIME *ft)
+{
+  __int64 qw = ft->dwHighDateTime;
+  qw <<= 32;
+  qw |= ft->dwLowDateTime;
+  qw /= 10000;  /* File time ticks at 0.1uS, clock at 1mS */
+  return (long) qw;
+
+}
+
+inline int times(struct tms *tmbuf)
+{
+  FILETIME create, exit, kernel, user;
+  if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
+    tmbuf->tms_utime = filetime_to_clock(&user);
+    tmbuf->tms_stime = filetime_to_clock(&kernel);
+    tmbuf->tms_cutime = 0;
+    tmbuf->tms_cstime = 0;
+  }
+  else {
+    tmbuf->tms_utime = clock();
+    tmbuf->tms_stime = 0;
+    tmbuf->tms_cutime = 0;
+    tmbuf->tms_cstime = 0;
+  }
+  return 0;
+}
+
+#define _SC_CLK_TCK 1
+
+inline int sysconf(int)
+{
+  return 1;
+}
+
+#endif
+
+
+#endif

Modified: hugo/trunk/lemon/graph_to_eps.h
==============================================================================
--- hugo/trunk/lemon/graph_to_eps.h	(original)
+++ hugo/trunk/lemon/graph_to_eps.h	Fri Mar 31 14:51:44 2006
@@ -21,6 +21,10 @@
 
 #include <sys/time.h>
 
+#ifdef WIN32
+#include <lemon/bits/mingw32_time.h>
+#endif
+
 #include<iostream>
 #include<fstream>
 #include<sstream>

Modified: hugo/trunk/lemon/time_measure.h
==============================================================================
--- hugo/trunk/lemon/time_measure.h	(original)
+++ hugo/trunk/lemon/time_measure.h	Fri Mar 31 14:51:44 2006
@@ -25,73 +25,7 @@
 
 
 #ifdef WIN32
-
-#include <windows.h>
-#include <time.h>
-#include "dos.h"
-
-int gettimeofday(struct timeval * tp, struct timezone *) {
-  SYSTEMTIME      systime;
-
-  if (tp) {
-
-    struct tm tmrec;
-    time_t theTime = time(NULL);
-
-    tmrec = *localtime(&theTime);
-    tp->tv_sec = mktime(&tmrec);
-    GetLocalTime(&systime); /* system time */
-
-    tp->tv_usec = systime.wMilliseconds * 1000;
-
-  }
-
-  return 0;
-
-}
-
-struct tms {
-  long	tms_utime;
-  long	tms_stime;
-  long	tms_cutime;
-  long	tms_cstime;
-};
-
-static long filetime_to_clock(FILETIME *ft)
-{
-  __int64 qw = ft->dwHighDateTime;
-  qw <<= 32;
-  qw |= ft->dwLowDateTime;
-  qw /= 10000;  /* File time ticks at 0.1uS, clock at 1mS */
-  return (long) qw;
-
-}
-
-int times(struct tms *tmbuf)
-{
-  FILETIME create, exit, kernel, user;
-  if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
-    tmbuf->tms_utime = filetime_to_clock(&user);
-    tmbuf->tms_stime = filetime_to_clock(&kernel);
-    tmbuf->tms_cutime = 0;
-    tmbuf->tms_cstime = 0;
-  }
-  else {
-    tmbuf->tms_utime = clock();
-    tmbuf->tms_stime = 0;
-    tmbuf->tms_cutime = 0;
-    tmbuf->tms_cstime = 0;
-  }
-  return 0;
-}
-
-#define _SC_CLK_TCK 1
-
-int sysconf(int)
-{
-  return 1;
-}
-
+#include <lemon/bits/mingw32_time.h>
 #else
 #include <sys/times.h>
 #endif
@@ -141,8 +75,10 @@
     rtms &getTms() {return ts;}
     const rtms &getTms() const {return ts;}
 
-    void _reset() 
-    { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
+    void _reset() { 
+      ts.tms_utime = ts.tms_stime = ts.tms_cutime = ts.tms_cstime = 0; 
+      real_time = 0;
+    }
 
   public:
 



More information about the Lemon-commits mailing list