lemon/bits/mingw32_time.h
author deba
Mon, 03 Apr 2006 09:45:23 +0000
changeset 2031 080d51024ac5
child 2035 e92071fadd3f
permissions -rw-r--r--
Correcting the structure of the graph's and adaptor's map.
The template assign operators and map iterators can be used for adaptors also.

Some bugfix in the adaptors

New class SwapBpUGraphAdaptor which swaps the two nodeset of the graph.
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     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_BITS_MINGW32_TIME_H
    20 #define LEMON_BITS_MINGW32_TIME_H
    21 
    22 #ifdef WIN32
    23 
    24 #include <windows.h>
    25 #include <time.h>
    26 #include "dos.h"
    27 
    28 static const char days[] = 
    29 "Sun Mon Tue Wed Thu Fri Sat ";
    30 static const char months[] = 
    31 "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
    32 
    33 inline void num2str(char *c,int i) {
    34   c[0]=i/10+'0';
    35   c[1]=i%10+'0';
    36 }
    37 
    38 inline char *asctime_r(const struct tm *t, char *buf) {
    39   /* "Wed Jun 30 21:49:08 1993\n" */
    40   *(int*)buf=*(int*)(days+(t->tm_wday<<2));
    41   *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
    42   num2str(buf+8,t->tm_mday);
    43   if (buf[8]=='0') buf[8]=' ';
    44   buf[10]=' ';
    45   num2str(buf+11,t->tm_hour);
    46   buf[13]=':';
    47   num2str(buf+14,t->tm_min);
    48   buf[16]=':';
    49   num2str(buf+17,t->tm_sec);
    50   buf[19]=' ';
    51   num2str(buf+20,(t->tm_year+1900)/100);
    52   num2str(buf+22,(t->tm_year+1900)%100);
    53   buf[24]='\n'; buf[25]='\0';
    54   return buf;
    55 }
    56 
    57 inline struct tm * localtime_r (const time_t *t, struct tm *tm) {
    58   struct tm *tmp;
    59   
    60   if ((tmp = localtime(t)) && tm)
    61     *tm = *tmp;
    62   else
    63     return 0;
    64   
    65   return tm;
    66 }
    67 
    68 inline char *ctime_r(const time_t * tim_p , char * result) {
    69   struct tm tm;
    70   return asctime_r (localtime_r (tim_p, &tm), result);
    71 }
    72 
    73 
    74 inline int gettimeofday(struct timeval * tp, struct timezone *) {
    75   SYSTEMTIME systime;
    76 
    77   if (tp) {
    78     struct tm tmrec;
    79     time_t theTime = time(NULL);
    80     
    81     
    82     tmrec = *localtime(&theTime);
    83     tp->tv_sec = mktime(&tmrec);
    84     GetLocalTime(&systime); /* system time */
    85 
    86     tp->tv_usec = systime.wMilliseconds * 1000;
    87   }
    88   return 0;
    89 }
    90 
    91 
    92 struct tms {
    93   long	tms_utime;
    94   long	tms_stime;
    95   long	tms_cutime;
    96   long	tms_cstime;
    97 };
    98 
    99 inline long filetime_to_clock(FILETIME *ft)
   100 {
   101   __int64 qw = ft->dwHighDateTime;
   102   qw <<= 32;
   103   qw |= ft->dwLowDateTime;
   104   qw /= 10000;  /* File time ticks at 0.1uS, clock at 1mS */
   105   return (long) qw;
   106 
   107 }
   108 
   109 inline int times(struct tms *tmbuf)
   110 {
   111   FILETIME create, exit, kernel, user;
   112   if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
   113     tmbuf->tms_utime = filetime_to_clock(&user);
   114     tmbuf->tms_stime = filetime_to_clock(&kernel);
   115     tmbuf->tms_cutime = 0;
   116     tmbuf->tms_cstime = 0;
   117   }
   118   else {
   119     tmbuf->tms_utime = clock();
   120     tmbuf->tms_stime = 0;
   121     tmbuf->tms_cutime = 0;
   122     tmbuf->tms_cstime = 0;
   123   }
   124   return 0;
   125 }
   126 
   127 #define _SC_CLK_TCK 1
   128 
   129 inline int sysconf(int)
   130 {
   131   return 1;
   132 }
   133 
   134 #endif
   135 
   136 
   137 #endif