COIN-OR::LEMON - Graph Library

Ticket #215: df730c6c1298.patch

File df730c6c1298.patch, 8.8 KB (added by Alpar Juttner, 16 years ago)
  • lemon/CMakeLists.txt

    # HG changeset patch
    # User Alpar Juttner <alpar@cs.elte.hu>
    # Date 1234771802 0
    # Node ID df730c6c12989e7a87794adeaf37067a1934d5dd
    # Parent  daddd623ac9a2f41ef9bc6d2b083abb2d06e7a4e
    Wrap around the usages of windows.h
    
    diff --git a/lemon/CMakeLists.txt b/lemon/CMakeLists.txt
    a b  
    44  arg_parser.cc
    55  base.cc
    66  color.cc
    7   random.cc)
     7  random.cc
     8  bits/windows.cc
     9)
    810
    911INSTALL(
    1012  TARGETS lemon
  • lemon/Makefile.am

    diff --git a/lemon/Makefile.am b/lemon/Makefile.am
    a b  
    1010        lemon/arg_parser.cc \
    1111        lemon/base.cc \
    1212        lemon/color.cc \
    13         lemon/random.cc
     13        lemon/random.cc \
     14        lemon/bits/windows.cc
    1415
    1516#lemon_libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS) $(SOPLEX_CXXFLAGS)
    1617#lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS) $(SOPLEX_LIBS)
     
    4041        lemon/smart_graph.h \
    4142        lemon/time_measure.h \
    4243        lemon/tolerance.h \
    43         lemon/unionfind.h
     44        lemon/unionfind.h \
     45        lemon/bits/windows.h
    4446
    4547bits_HEADERS += \
    4648        lemon/bits/alteration_notifier.h \
  • 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#ifdef WIN32
     25#ifndef WIN32_LEAN_AND_MEAN
     26#define WIN32_LEAN_AND_MEAN
     27#endif
     28#ifndef NOMINMAX
     29#define NOMINMAX
     30#endif
     31#include <windows.h>
     32#else
     33#include <unistd.h>
     34#include <sys/times.h>
     35#include <sys/time.h>
     36#endif
     37
     38#include <cmath>
     39#include <sstream>
     40
     41namespace lemon {
     42  namespace bits {
     43    void getWinProcTimes(double &rtime,
     44                         double &utime, double &stime,
     45                         double &cutime, double &cstime)
     46    {
     47#ifdef WIN32
     48      static const double ch = 4294967296.0e-7;
     49      static const double cl = 1.0e-7;
     50
     51      FILETIME system;
     52      GetSystemTimeAsFileTime(&system);
     53      rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime;
     54
     55      FILETIME create, exit, kernel, user;
     56      if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
     57        utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
     58        stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
     59        cutime = 0;
     60        cstime = 0;
     61      } else {
     62        rtime = 0;
     63        utime = 0;
     64        stime = 0;
     65        cutime = 0;
     66        cstime = 0;
     67      }
     68#else
     69      timeval tv;
     70      gettimeofday(&tv, 0);
     71      rtime=tv.tv_sec+double(tv.tv_usec)/1e6;
     72
     73      tms ts;
     74      double tck=sysconf(_SC_CLK_TCK);
     75      times(&ts);
     76      utime=ts.tms_utime/tck;
     77      stime=ts.tms_stime/tck;
     78      cutime=ts.tms_cutime/tck;
     79      cstime=ts.tms_cstime/tck;
     80#endif
     81    }
     82
     83    std::string getWinFormattedDate()
     84    {
     85      std::ostringstream os;
     86#ifdef WIN32
     87      SYSTEMTIME time;
     88      GetSystemTime(&time);
     89#if defined(_MSC_VER) && (_MSC_VER < 1500)
     90      LPWSTR buf1, buf2, buf3;
     91      if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
     92                        L"ddd MMM dd", buf1, 11) &&
     93          GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time,
     94                        L"HH':'mm':'ss", buf2, 9) &&
     95          GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
     96                        L"yyyy", buf3, 5)) {
     97        os << buf1 << ' ' << buf2 << ' ' << buf3;
     98      }
     99#else
     100      char buf1[11], buf2[9], buf3[5];
     101      if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
     102                        "ddd MMM dd", buf1, 11) &&
     103          GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time,
     104                        "HH':'mm':'ss", buf2, 9) &&
     105          GetDateFormat(LOCALE_USER_DEFAULT, 0, &time,
     106                        "yyyy", buf3, 5)) {
     107        os << buf1 << ' ' << buf2 << ' ' << buf3;
     108      }
     109#endif
     110      else os << "unknown";
     111#else
     112      timeval tv;
     113      gettimeofday(&tv, 0);
     114
     115      char cbuf[26];
     116      ctime_r(&tv.tv_sec,cbuf);
     117      os << cbuf;
     118#endif
     119      return os.str();
     120    }
     121  }
     122}
  • 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
     24namespace 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  
    2929#include<sys/time.h>
    3030#include<ctime>
    3131#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>
    3933#endif
    4034
    4135#include<lemon/math.h>
     
    683677    os << "%%Creator: LEMON, graphToEps()\n";
    684678
    685679    {
     680      os << "%%CreationDate: ";
    686681#ifndef WIN32
    687682      timeval tv;
    688683      gettimeofday(&tv, 0);
    689684
    690685      char cbuf[26];
    691686      ctime_r(&tv.tv_sec,cbuf);
    692       os << "%%CreationDate: " << cbuf;
     687      os << cbuf;
    693688#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();
    719690#endif
    720691    }
     692    os << std::endl;
    721693
    722694    if (_autoArcWidthScale) {
    723695      double max_w=0;
  • lemon/time_measure.h

    diff --git a/lemon/time_measure.h b/lemon/time_measure.h
    a b  
    2424///\brief Tools for measuring cpu usage
    2525
    2626#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>
    3528#else
    3629#include <unistd.h>
    3730#include <sys/times.h>
     
    9285      cutime=ts.tms_cutime/tck;
    9386      cstime=ts.tms_cstime/tck;
    9487#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);
    11589#endif
    11690    }
    11791