Boost logo

Boost :

Subject: Re: [boost] [date_time] Patch for ticket #1740: date_time includes <windows.h>
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-10-14 12:13:52


Jeff Garland <jeff_at_[hidden]> writes:

> joaquin_at_[hidden] wrote:
>> Jeff Garland escribió:
>>> Emil Mieilica wrote:
>>>
>>>> Hello,
>>>> Done. Hope it will be useful to everybody who uses this great library.
>>>>
>>>>
>>>>> Can you attach this patch to the ticket so it doesn't get lost?
>>>>>
>>>
>>> Just a technical comment on the suggested patch. Is it really wise
>>> / legal to
>>> replicate the Windows API declarations in Boost.
>>
>> Isn't that exactly what other libs such as WINE do? See
>>
>> http://source.winehq.org/source/include/
>
> Yeah, I guess they would have to since they are an emulation of the
> Win32 api. AFAIK we've never taken this approach in Boost so I think
> we should talk thru if it's acceptable before putting it in. If it is
> acceptable, I guess the other question might be if it belongs in
> config instead of an individual library.

boost/detail/lwm_win32_cs.hpp does this for CRITICAL_SECTION, and
boost/thread/win32/thread_primitives.hpp does this for some APIs.

In both cases the structures and APIs are redeclared in a nested
namespace in boost, so as not to clash with the declarations in the
global namespace should someone include <windows.h> outside the boost
headers.

I've attached the patch I've been using locally. The "filetime.hpp"
goes in boost/date_time.

Anthony

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL


#ifndef BOOST_DATE_TIME_FILETIME_HPP
#define BOOST_DATE_TIME_FILETIME_HPP

// (C) Copyright 2008 Anthony Williams
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifdef BOOST_HAS_FTIME
#ifdef BOOST_USE_WINDOWS_H
#include <windows.h>
namespace boost
{
    namespace detail
    {
        namespace win32
        {
            typedef FILETIME file_time;
            typedef SYSTEMTIME system_time;
            using ::GetSystemTime;
            using ::GetSystemTimeAsFileTime;
            using ::FileTimeToLocalFileTime;
            using ::SystemTimeToFileTime;
        }
    }
}
#else
namespace boost
{
    namespace detail
    {
        namespace win32
        {
            extern "C"
            {
                struct file_time
                {
                    unsigned long dwLowDateTime;
                    unsigned long dwHighDateTime;
                };

                struct system_time
                {
                    unsigned short wYear;
                    unsigned short wMonth;
                    unsigned short wDayOfWeek;
                    unsigned short wDay;
                    unsigned short wHour;
                    unsigned short wMinute;
                    unsigned short wSecond;
                    unsigned short wMilliseconds;
                };
                
                __declspec(dllimport) void __stdcall GetSystemTimeAsFileTime(file_time*);
                __declspec(dllimport) int __stdcall FileTimeToLocalFileTime(const file_time*,file_time*);
                __declspec(dllimport) void __stdcall GetSystemTime(system_time*);
                __declspec(dllimport) int __stdcall SystemTimeToFileTime(const system_time*,file_time*);
            }
        }
    }
}
#endif
#endif

#endif



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk