Ticket #13545: time.hpp

File time.hpp, 4.6 KB (added by boost@…, 4 years ago)
Line 
1/*
2 * Copyright 2010 Vicente J. Botet Escriba
3 * Copyright (c) Microsoft Corporation 2014
4 * Copyright 2015, 2017 Andrey Semashev
5 *
6 * Distributed under the Boost Software License, Version 1.0.
7 * See http://www.boost.org/LICENSE_1_0.txt
8 */
9
10#ifndef BOOST_WINAPI_TIME_HPP_INCLUDED_
11#define BOOST_WINAPI_TIME_HPP_INCLUDED_
12
13#include <boost/winapi/basic_types.hpp>
14
15#ifdef BOOST_HAS_PRAGMA_ONCE
16#pragma once
17#endif
18# ifndef _WINDOWS_
19# include<windows.h>
20# endif
21#if !defined( BOOST_USE_WINDOWS_H )
22extern "C" {
23struct _FILETIME;
24struct _SYSTEMTIME;
25
26 BOOST_SYMBOL_IMPORT boost::winapi::VOID_ WINAPI GetSystemTime( _Out_::_SYSTEMTIME* lpSystemTime);
27#ifdef BOOST_HAS_GETSYSTEMTIMEASFILETIME // Windows CE does not define GetSystemTimeAsFileTime
28 BOOST_SYMBOL_IMPORT boost::winapi::VOID_ WINAPI GetSystemTimeAsFileTime(_Out_::_FILETIME* lpSystemTimeAsFileTime);
29#endif
30 BOOST_SYMBOL_IMPORT _Success_(return!=FALSE)BOOL
31 WINAPI SystemTimeToFileTime( _In_ const::_SYSTEMTIME*lpSystemTime,_Out_::_FILETIME *lpFileTime);
32 BOOST_SYMBOL_IMPORT _Success_(return!=FALSE)BOOL
33 WINAPI FileTimeToSystemTime( _In_ const::_FILETIME *lpFileTime,_Out_::_SYSTEMTIME*lpSystemTime);
34#if BOOST_WINAPI_PARTITION_APP_SYSTEM
35 BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ WINAPI FileTimeToLocalFileTime(_In_ const::_FILETIME *lpFileTime ,_Out_::_FILETIME*lpLocalFileTime);
36 BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ WINAPI LocalFileTimeToFileTime(_In_ const::_FILETIME*lpLocalFileTime,_Out_::_FILETIME *lpFileTime);
37
38#endif // BOOST_WINAPI_PARTITION_APP_SYSTEM
39
40#if BOOST_WINAPI_PARTITION_DESKTOP_SYSTEM
41 __drv_preferredFunction("GetTickCount64", "GetTickCount overflows roughly every 49 days. Code that does not take that into account can loop indefinitely. GetTickCount64 operates on 64 bit values and does not have that problem")
42 BOOST_SYMBOL_IMPORT boost::winapi::DWORD_ WINAPI GetTickCount(BOOST_WINAPI_DETAIL_VOID);
43#endif // BOOST_WINAPI_PARTITION_DESKTOP_SYSTEM
44
45#if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
46BOOST_SYMBOL_IMPORT boost::winapi::ULONGLONG_ WINAPI
47GetTickCount64(BOOST_WINAPI_DETAIL_VOID);
48#endif
49
50} // extern "C"
51#endif // !defined( BOOST_USE_WINDOWS_H )
52
53namespace boost {
54namespace winapi {
55
56typedef struct BOOST_MAY_ALIAS _FILETIME {
57 DWORD_ dwLowDateTime;
58 DWORD_ dwHighDateTime;
59} FILETIME_, *PFILETIME_, *LPFILETIME_;
60
61typedef struct BOOST_MAY_ALIAS _SYSTEMTIME {
62 WORD_ wYear;
63 WORD_ wMonth;
64 WORD_ wDayOfWeek;
65 WORD_ wDay;
66 WORD_ wHour;
67 WORD_ wMinute;
68 WORD_ wSecond;
69 WORD_ wMilliseconds;
70} SYSTEMTIME_, *PSYSTEMTIME_, *LPSYSTEMTIME_;
71
72#if BOOST_WINAPI_PARTITION_DESKTOP_SYSTEM
73using ::GetTickCount;
74#endif
75#if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
76using ::GetTickCount64;
77#endif
78
79BOOST_FORCEINLINE VOID_ GetSystemTime(LPSYSTEMTIME_ lpSystemTime)
80{
81 ::GetSystemTime(reinterpret_cast< ::_SYSTEMTIME* >(lpSystemTime));
82}
83
84BOOST_FORCEINLINE BOOL_ SystemTimeToFileTime(const SYSTEMTIME_* lpSystemTime, FILETIME_* lpFileTime)
85{
86 return ::SystemTimeToFileTime(reinterpret_cast< const ::_SYSTEMTIME* >(lpSystemTime), reinterpret_cast< ::_FILETIME* >(lpFileTime));
87}
88
89BOOST_FORCEINLINE BOOL_ FileTimeToSystemTime(const FILETIME_* lpFileTime, SYSTEMTIME_* lpSystemTime)
90{
91 return ::FileTimeToSystemTime(reinterpret_cast< const ::_FILETIME* >(lpFileTime), reinterpret_cast< ::_SYSTEMTIME* >(lpSystemTime));
92}
93
94#if BOOST_WINAPI_PARTITION_APP_SYSTEM
95BOOST_FORCEINLINE BOOL_ FileTimeToLocalFileTime(const FILETIME_* lpFileTime, FILETIME_* lpLocalFileTime)
96{
97 return ::FileTimeToLocalFileTime(reinterpret_cast< const ::_FILETIME* >(lpFileTime), reinterpret_cast< ::_FILETIME* >(lpLocalFileTime));
98}
99
100BOOST_FORCEINLINE BOOL_ LocalFileTimeToFileTime(const FILETIME_* lpLocalFileTime, FILETIME_* lpFileTime)
101{
102 return ::LocalFileTimeToFileTime(reinterpret_cast< const ::_FILETIME* >(lpLocalFileTime), reinterpret_cast< ::_FILETIME* >(lpFileTime));
103}
104#endif // BOOST_WINAPI_PARTITION_APP_SYSTEM
105
106#if defined( BOOST_HAS_GETSYSTEMTIMEASFILETIME )
107BOOST_FORCEINLINE VOID_ GetSystemTimeAsFileTime(LPFILETIME_ lpSystemTimeAsFileTime)
108{
109 ::GetSystemTimeAsFileTime(reinterpret_cast< ::_FILETIME* >(lpSystemTimeAsFileTime));
110}
111#else
112// Windows CE does not define GetSystemTimeAsFileTime
113BOOST_FORCEINLINE VOID_ GetSystemTimeAsFileTime(FILETIME_* lpFileTime)
114{
115 boost::winapi::SYSTEMTIME_ st;
116 boost::winapi::GetSystemTime(&st);
117 boost::winapi::SystemTimeToFileTime(&st, lpFileTime);
118}
119#endif
120
121}
122}
123
124#endif // BOOST_WINAPI_TIME_HPP_INCLUDED_