You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

925 lines
30 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/shims/access/string/time.hpp
  3. *
  4. * Purpose: Helper functions for the SYSTEMTIME and FILETIME structures.
  5. *
  6. * Created: 2nd December 2004
  7. * Updated: 10th March 2011
  8. *
  9. * Thanks to: David Wang, for spotting an error in one of the shim
  10. * functions.
  11. *
  12. * Home: http://stlsoft.org/
  13. *
  14. * Copyright (c) 2004-2011, Matthew Wilson and Synesis Software
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without
  18. * modification, are permitted provided that the following conditions are met:
  19. *
  20. * - Redistributions of source code must retain the above copyright notice, this
  21. * list of conditions and the following disclaimer.
  22. * - Redistributions in binary form must reproduce the above copyright notice,
  23. * this list of conditions and the following disclaimer in the documentation
  24. * and/or other materials provided with the distribution.
  25. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  26. * any contributors may be used to endorse or promote products derived from
  27. * this software without specific prior written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  30. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  33. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  34. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  36. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  37. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  38. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. * ////////////////////////////////////////////////////////////////////// */
  42. /** \file winstl/shims/access/string/time.hpp
  43. *
  44. * \brief [C++] Definition of the string access shims for
  45. * <code>FILETIME</code> and <code>SYSTEMTIME</code>
  46. * (\ref group__concept__shim__string_access "String Access Shims" Concept).
  47. */
  48. #ifndef WINSTL_INCL_WINSTL_SHIMS_ACCESS_STRING_HPP_TIME
  49. #define WINSTL_INCL_WINSTL_SHIMS_ACCESS_STRING_HPP_TIME
  50. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  51. # define WINSTL_VER_WINSTL_SHIMS_ACCESS_STRING_HPP_TIME_MAJOR 2
  52. # define WINSTL_VER_WINSTL_SHIMS_ACCESS_STRING_HPP_TIME_MINOR 3
  53. # define WINSTL_VER_WINSTL_SHIMS_ACCESS_STRING_HPP_TIME_REVISION 8
  54. # define WINSTL_VER_WINSTL_SHIMS_ACCESS_STRING_HPP_TIME_EDIT 55
  55. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  56. /* /////////////////////////////////////////////////////////////////////////
  57. * Includes
  58. */
  59. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  60. # include <winstl/winstl.h>
  61. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  62. #ifndef WINSTL_INCL_WINSTL_ERROR_HPP_CONVERSION_ERROR
  63. # include <winstl/error/conversion_error.hpp>
  64. #endif /* !WINSTL_INCL_WINSTL_ERROR_HPP_CONVERSION_ERROR */
  65. #ifndef WINSTL_INCL_WINSTL_SHIMS_CONVERSION_TO_SYSTEMTIME_HPP_FILETIME
  66. # include <winstl/shims/conversion/to_SYSTEMTIME/FILETIME.hpp>
  67. #endif /* !WINSTL_INCL_WINSTL_SHIMS_CONVERSION_TO_SYSTEMTIME_HPP_FILETIME */
  68. #ifndef WINSTL_INCL_WINSTL_TIME_HPP_FORMAT_FUNCTIONS
  69. # include <winstl/time/format_functions.hpp>
  70. #endif /* !WINSTL_INCL_WINSTL_TIME_HPP_FORMAT_FUNCTIONS */
  71. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_STD_H_C_STRING
  72. # include <stlsoft/shims/access/string/std/c_string.h>
  73. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_STD_H_C_STRING */
  74. #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SHIM_STRING
  75. # include <stlsoft/string/shim_string.hpp>
  76. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SHIM_STRING */
  77. #ifdef WINSTL_UDATE_DEFINED
  78. # include <objbase.h>
  79. # include <oleauto.h>
  80. #endif /* WINSTL_UDATE_DEFINED */
  81. /* /////////////////////////////////////////////////////////////////////////
  82. * Namespace
  83. */
  84. #ifndef _WINSTL_NO_NAMESPACE
  85. # if defined(_STLSOFT_NO_NAMESPACE) || \
  86. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  87. /* There is no stlsoft namespace, so must define ::winstl */
  88. namespace winstl
  89. {
  90. # else
  91. /* Define stlsoft::winstl_project */
  92. namespace stlsoft
  93. {
  94. namespace winstl_project
  95. {
  96. # endif /* _STLSOFT_NO_NAMESPACE */
  97. #endif /* !_WINSTL_NO_NAMESPACE */
  98. /* /////////////////////////////////////////////////////////////////////////
  99. * Helper Classes
  100. */
  101. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  102. struct winstl_shims_access_string_time_impl
  103. {
  104. typedef int (STLSOFT_STDCALL *pfnGetDateTimeFmtA_t)(LCID Locale // locale
  105. , DWORD dwFlags // options
  106. , CONST SYSTEMTIME *lpTime // time
  107. , ws_char_a_t const *lpFormat // time format string
  108. , ws_char_a_t *lpTimeStr // formatted string buffer
  109. , int cchTime); // size of string buffer
  110. typedef int (STLSOFT_STDCALL *pfnGetDateTimeFmtW_t)(LCID Locale // locale
  111. , DWORD dwFlags // options
  112. , CONST SYSTEMTIME *lpTime // time
  113. , ws_char_w_t const *lpFormat // time format string
  114. , ws_char_w_t *lpTimeStr // formatted string buffer
  115. , int cchTime); // size of string buffer
  116. //
  117. static ws_size_t calc_sizes(SYSTEMTIME const& t
  118. , pfnGetDateTimeFmtA_t pfnGetDateFmtA
  119. , pfnGetDateTimeFmtA_t pfnGetTimeFmtA
  120. , ws_size_t& cchDate
  121. , ws_size_t& cchTime)
  122. {
  123. cchDate = static_cast<ws_size_t>(pfnGetDateFmtA(LOCALE_USER_DEFAULT, 0, &t, NULL, NULL, 0));
  124. if(0 != cchDate)
  125. {
  126. cchTime = static_cast<ws_size_t>(pfnGetTimeFmtA(LOCALE_USER_DEFAULT, 0, &t, NULL, NULL, 0));
  127. if(0 != cchTime)
  128. {
  129. return (cchDate - 1) + 1 + (cchTime - 1);
  130. }
  131. }
  132. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  133. STLSOFT_THROW_X(conversion_error("failed to convert date/time", ::GetLastError()));
  134. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  135. return 0;
  136. }
  137. //
  138. static ws_size_t calc_sizes(SYSTEMTIME const& t
  139. , pfnGetDateTimeFmtW_t pfnGetDateFmtW
  140. , pfnGetDateTimeFmtW_t pfnGetTimeFmtW
  141. , ws_size_t& cchDate
  142. , ws_size_t& cchTime)
  143. {
  144. cchDate = static_cast<ws_size_t>(pfnGetDateFmtW(LOCALE_USER_DEFAULT, 0, &t, NULL, NULL, 0));
  145. if(0 != cchDate)
  146. {
  147. cchTime = static_cast<ws_size_t>(pfnGetTimeFmtW(LOCALE_USER_DEFAULT, 0, &t, NULL, NULL, 0));
  148. if(0 != cchTime)
  149. {
  150. return (cchDate - 1) + 1 + (cchTime - 1);
  151. }
  152. }
  153. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  154. STLSOFT_THROW_X(conversion_error("failed to convert date/time", ::GetLastError()));
  155. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  156. return 0;
  157. }
  158. };
  159. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  160. /* /////////////////////////////////////////////////////////////////////////
  161. * Helper Functions
  162. */
  163. /** \brief [DEPRECATED] Converts a <code>FILETIME</code> value to a
  164. * <code>SYSTEMTIME</code> value.
  165. *
  166. * \deprecated Instead use winstl::to_SYSTEMTIME(FILETIME const&)
  167. *
  168. * \ingroup group__library__shims__string_access
  169. *
  170. * \param ft The <code>FILETIME</code> instance whose value is to be converted
  171. *
  172. * \note If <code>ft</code> does not represent a valid time value, the
  173. * return value is undefined. The caller may check
  174. * <code>GetLastError()</code> to determine whether the conversion has been
  175. * successful.
  176. */
  177. inline SYSTEMTIME FILETIME2SYSTEMTIME(FILETIME const& ft)
  178. {
  179. return winstl_ns_qual(to_SYSTEMTIME)(ft);
  180. }
  181. template <ss_typename_param_k S>
  182. inline void stream_insert(S &stm, SYSTEMTIME const& t)
  183. {
  184. typedef stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> string_t;
  185. typedef winstl_shims_access_string_time_impl impl_t;
  186. ws_size_t cchDate = 0;
  187. ws_size_t cchTime = 0;
  188. const ws_size_t cchTotal = impl_t::calc_sizes(t, ::GetDateFormatA, ::GetTimeFormatA, cchDate, cchTime);
  189. #ifdef STLSOFT_CD_EXCEPTION_SUPPORT
  190. WINSTL_ASSERT(0 != cchTotal);
  191. #else /* ? STLSOFT_CD_EXCEPTION_SUPPORT */
  192. if(0 != cchTotal)
  193. #endif /* STLSOFT_CD_EXCEPTION_SUPPORT */
  194. {
  195. string_t s(cchTotal);
  196. if(cchTotal == s.size())
  197. {
  198. ::GetDateFormatA(LOCALE_USER_DEFAULT, 0, &t, NULL, &s.data()[0], static_cast<int>(cchDate));
  199. s.data()[cchDate - 1] = ' ';
  200. ::GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &t, NULL, &s.data()[0] + cchDate, static_cast<int>(cchTime));
  201. // Because it's possible for external action to change the date
  202. // and/or time pictures between the call to calc_sizes and the
  203. // two preceeding calls, we guard against an unterminated
  204. // C-style string by forcibly appending the nul-terminator that
  205. // GetTimeFormat() will do for us normally.
  206. s.data()[cchTotal] = '\0';
  207. }
  208. stm << s.data();
  209. }
  210. }
  211. template <ss_typename_param_k S>
  212. inline void stream_insert(S &stm, FILETIME const& ft)
  213. {
  214. stream_insert(stm, FILETIME2SYSTEMTIME(ft));
  215. }
  216. #ifdef WINSTL_UDATE_DEFINED
  217. template <ss_typename_param_k S>
  218. inline void stream_insert(S &stm, UDATE const& ud)
  219. {
  220. stream_insert(stm, ud.st);
  221. }
  222. #endif /* WINSTL_UDATE_DEFINED */
  223. /* /////////////////////////////////////////////////////////////////////////
  224. * Shims
  225. */
  226. /* /////////////////////////////////////////////////////////////////////////
  227. * c_str_ptr
  228. */
  229. // SYSTEMTIME
  230. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_a(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  231. {
  232. typedef stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> string_t;
  233. typedef winstl_shims_access_string_time_impl impl_t;
  234. int (STLSOFT_STDCALL *pfnGetTimeFormatA)( LCID Locale // locale
  235. , DWORD dwFlags // options
  236. , CONST SYSTEMTIME *lpTime // time
  237. , ws_char_a_t const *lpFormat // time format string
  238. , ws_char_a_t *lpTimeStr // formatted string buffer
  239. , int cchTime) // size of string buffer
  240. = bMilliseconds ? GetTimeFormat_msA : ::GetTimeFormatA;
  241. ws_size_t cchDate = 0;
  242. ws_size_t cchTime = 0;
  243. const ws_size_t cchTotal = impl_t::calc_sizes(t, ::GetDateFormatA, pfnGetTimeFormatA, cchDate, cchTime);
  244. string_t s(cchTotal);
  245. if( 0 != cchTotal &&
  246. cchTotal == s.size())
  247. {
  248. ::GetDateFormatA(LOCALE_USER_DEFAULT, 0, &t, NULL, &s.data()[0], static_cast<int>(cchDate));
  249. s.data()[cchDate - 1] = ' ';
  250. pfnGetTimeFormatA(LOCALE_USER_DEFAULT, 0, &t, NULL, &s.data()[0] + cchDate, static_cast<int>(cchTime));
  251. // Because it's possible for external action to change the date
  252. // and/or time pictures between the call to calc_sizes and the
  253. // two preceeding calls, we guard against an unterminated
  254. // C-style string by forcibly appending the nul-terminator that
  255. // GetTimeFormat() will do for us normally.
  256. s.data()[cchTotal] = '\0';
  257. }
  258. return s;
  259. }
  260. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_a(SYSTEMTIME const& t)
  261. {
  262. return c_str_ptr_a(t, ws_false_v);
  263. }
  264. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_w(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  265. {
  266. typedef stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> string_t;
  267. typedef winstl_shims_access_string_time_impl impl_t;
  268. int (STLSOFT_STDCALL *pfnGetTimeFormatW)( LCID Locale // locale
  269. , DWORD dwFlags // options
  270. , CONST SYSTEMTIME *lpTime // time
  271. , ws_char_w_t const *lpFormat // time format string
  272. , ws_char_w_t *lpTimeStr // formatted string buffer
  273. , int cchTime) // size of string buffer
  274. = bMilliseconds ? GetTimeFormat_msW : ::GetTimeFormatW;
  275. ws_size_t cchDate = 0;
  276. ws_size_t cchTime = 0;
  277. const ws_size_t cchTotal = impl_t::calc_sizes(t, ::GetDateFormatW, pfnGetTimeFormatW, cchDate, cchTime);
  278. string_t s(cchTotal);
  279. if( 0 != cchTotal &&
  280. cchTotal == s.size())
  281. {
  282. ::GetDateFormatW(LOCALE_USER_DEFAULT, 0, &t, NULL, &s.data()[0], static_cast<int>(cchDate));
  283. s.data()[cchDate - 1] = ' ';
  284. pfnGetTimeFormatW(LOCALE_USER_DEFAULT, 0, &t, NULL, &s.data()[0] + cchDate, static_cast<int>(cchTime));
  285. // Because it's possible for external action to change the date
  286. // and/or time pictures between the call to calc_sizes and the
  287. // two preceeding calls, we guard against an unterminated
  288. // C-style string by forcibly appending the nul-terminator that
  289. // GetTimeFormat() will do for us normally.
  290. s.data()[cchTotal] = '\0';
  291. }
  292. return s;
  293. }
  294. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_w(SYSTEMTIME const& t)
  295. {
  296. return c_str_ptr_w(t, ws_false_v);
  297. }
  298. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  299. {
  300. #ifdef UNICODE
  301. return c_str_ptr_w(t, bMilliseconds);
  302. #else /* ? UNICODD */
  303. return c_str_ptr_a(t, bMilliseconds);
  304. #endif /* UNICODD */
  305. }
  306. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr(SYSTEMTIME const& t)
  307. {
  308. return c_str_ptr(t, ws_false_v);
  309. }
  310. // FILETIME
  311. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_a(FILETIME const& t, ws_bool_t bMilliseconds)
  312. {
  313. return c_str_ptr_a(FILETIME2SYSTEMTIME(t), bMilliseconds);
  314. }
  315. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_a(FILETIME const& t)
  316. {
  317. return c_str_ptr_a(t, ws_false_v);
  318. }
  319. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_w(FILETIME const& t, ws_bool_t bMilliseconds)
  320. {
  321. return c_str_ptr_w(FILETIME2SYSTEMTIME(t), bMilliseconds);
  322. }
  323. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_w(FILETIME const& t)
  324. {
  325. return c_str_ptr_w(t, ws_false_v);
  326. }
  327. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr(FILETIME const& t, ws_bool_t bMilliseconds)
  328. {
  329. return c_str_ptr(FILETIME2SYSTEMTIME(t), bMilliseconds);
  330. }
  331. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr(FILETIME const& t)
  332. {
  333. return c_str_ptr(t, ws_false_v);
  334. }
  335. #ifdef WINSTL_UDATE_DEFINED
  336. // UDATE
  337. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_a(UDATE const& ud, ws_bool_t bMilliseconds)
  338. {
  339. return c_str_ptr_a(ud.st, bMilliseconds);
  340. }
  341. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_a(UDATE const& ud)
  342. {
  343. return c_str_ptr_a(ud.st);
  344. }
  345. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_w(UDATE const& ud, ws_bool_t bMilliseconds)
  346. {
  347. return c_str_ptr_w(ud.st, bMilliseconds);
  348. }
  349. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_w(UDATE const& ud)
  350. {
  351. return c_str_ptr_w(ud.st);
  352. }
  353. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr(UDATE const& ud, ws_bool_t bMilliseconds)
  354. {
  355. return c_str_ptr(ud.st, bMilliseconds);
  356. }
  357. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr(UDATE const& ud)
  358. {
  359. return c_str_ptr(ud.st);
  360. }
  361. #endif /* WINSTL_UDATE_DEFINED */
  362. /* /////////////////////////////////////////////////////////////////////////
  363. * c_str_data
  364. */
  365. // SYSTEMTIME
  366. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_data_a(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  367. {
  368. return c_str_ptr_a(t, bMilliseconds);
  369. }
  370. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_data_a(SYSTEMTIME const& t)
  371. {
  372. return c_str_data_a(t, ws_false_v);
  373. }
  374. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_data_w(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  375. {
  376. return c_str_ptr_w(t, bMilliseconds);
  377. }
  378. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_data_w(SYSTEMTIME const& t)
  379. {
  380. return c_str_data_w(t, ws_false_v);
  381. }
  382. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_data(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  383. {
  384. #ifdef UNICODE
  385. return c_str_data_w(t, bMilliseconds);
  386. #else /* ? UNICODD */
  387. return c_str_data_a(t, bMilliseconds);
  388. #endif /* UNICODD */
  389. }
  390. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_data(SYSTEMTIME const& t)
  391. {
  392. return c_str_data(t, ws_false_v);
  393. }
  394. // FILETIME
  395. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_data_a(FILETIME const& t, ws_bool_t bMilliseconds)
  396. {
  397. return c_str_ptr_a(FILETIME2SYSTEMTIME(t), bMilliseconds);
  398. }
  399. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_data_a(FILETIME const& t)
  400. {
  401. return c_str_data_a(FILETIME2SYSTEMTIME(t), ws_false_v);
  402. }
  403. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_data_w(FILETIME const& t, ws_bool_t bMilliseconds)
  404. {
  405. return c_str_ptr_w(FILETIME2SYSTEMTIME(t), bMilliseconds);
  406. }
  407. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_data_w(FILETIME const& t)
  408. {
  409. return c_str_data_w(FILETIME2SYSTEMTIME(t), ws_false_v);
  410. }
  411. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_data(FILETIME const& t, ws_bool_t bMilliseconds)
  412. {
  413. return c_str_ptr(FILETIME2SYSTEMTIME(t), bMilliseconds);
  414. }
  415. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_data(FILETIME const& t)
  416. {
  417. return c_str_data(FILETIME2SYSTEMTIME(t), ws_false_v);
  418. }
  419. // UDATE
  420. #ifdef WINSTL_UDATE_DEFINED
  421. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_data_a(UDATE const& t, ws_bool_t bMilliseconds)
  422. {
  423. return c_str_ptr_a(t.st, bMilliseconds);
  424. }
  425. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_data_a(UDATE const& t)
  426. {
  427. return c_str_data_a(t.st, ws_false_v);
  428. }
  429. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_data_w(UDATE const& t, ws_bool_t bMilliseconds)
  430. {
  431. return c_str_ptr_w(t.st, bMilliseconds);
  432. }
  433. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_data_w(UDATE const& t)
  434. {
  435. return c_str_data_w(t.st, ws_false_v);
  436. }
  437. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_data(UDATE const& t, ws_bool_t bMilliseconds)
  438. {
  439. return c_str_ptr(t.st, bMilliseconds);
  440. }
  441. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_data(UDATE const& t)
  442. {
  443. return c_str_data(t.st, ws_false_v);
  444. }
  445. #endif /* WINSTL_UDATE_DEFINED */
  446. /* /////////////////////////////////////////////////////////////////////////
  447. * c_str_ptr_null
  448. */
  449. // SYSTEMTIME
  450. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_null_a(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  451. {
  452. return c_str_ptr_a(t, bMilliseconds);
  453. }
  454. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_null_a(SYSTEMTIME const& t)
  455. {
  456. return c_str_ptr_null_a(t, ws_false_v);
  457. }
  458. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_null_w(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  459. {
  460. return c_str_ptr_w(t, bMilliseconds);
  461. }
  462. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_null_w(SYSTEMTIME const& t)
  463. {
  464. return c_str_ptr_null_w(t, ws_false_v);
  465. }
  466. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr_null(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  467. {
  468. return c_str_ptr(t, bMilliseconds);
  469. }
  470. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr_null(SYSTEMTIME const& t)
  471. {
  472. return c_str_ptr_null(t, ws_false_v);
  473. }
  474. // FILETIME
  475. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_null_a(FILETIME const& t, ws_bool_t bMilliseconds)
  476. {
  477. return c_str_ptr_null_a(FILETIME2SYSTEMTIME(t), bMilliseconds);
  478. }
  479. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_null_a(FILETIME const& t)
  480. {
  481. return c_str_ptr_null_a(FILETIME2SYSTEMTIME(t), ws_false_v);
  482. }
  483. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_null_w(FILETIME const& t, ws_bool_t bMilliseconds)
  484. {
  485. return c_str_ptr_null_w(FILETIME2SYSTEMTIME(t), bMilliseconds);
  486. }
  487. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_null_w(FILETIME const& t)
  488. {
  489. return c_str_ptr_null_w(FILETIME2SYSTEMTIME(t), ws_false_v);
  490. }
  491. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr_null(FILETIME const& t, ws_bool_t bMilliseconds)
  492. {
  493. return c_str_ptr_null(FILETIME2SYSTEMTIME(t), bMilliseconds);
  494. }
  495. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr_null(FILETIME const& t)
  496. {
  497. return c_str_ptr_null(FILETIME2SYSTEMTIME(t), ws_false_v);
  498. }
  499. // UDATE
  500. #ifdef WINSTL_UDATE_DEFINED
  501. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_null_a(UDATE const& t, ws_bool_t bMilliseconds)
  502. {
  503. return c_str_ptr_null_a(t.st, bMilliseconds);
  504. }
  505. inline stlsoft_ns_qual(basic_shim_string)<ws_char_a_t> c_str_ptr_null_a(UDATE const& t)
  506. {
  507. return c_str_ptr_null_a(t.st, ws_false_v);
  508. }
  509. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_null_w(UDATE const& t, ws_bool_t bMilliseconds)
  510. {
  511. return c_str_ptr_null_w(t.st, bMilliseconds);
  512. }
  513. inline stlsoft_ns_qual(basic_shim_string)<ws_char_w_t> c_str_ptr_null_w(UDATE const& t)
  514. {
  515. return c_str_ptr_null_w(t.st, ws_false_v);
  516. }
  517. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr_null(UDATE const& t, ws_bool_t bMilliseconds)
  518. {
  519. return c_str_ptr_null(t.st, bMilliseconds);
  520. }
  521. inline stlsoft_ns_qual(basic_shim_string)<TCHAR> c_str_ptr_null(UDATE const& t)
  522. {
  523. return c_str_ptr_null(t.st, ws_false_v);
  524. }
  525. #endif /* WINSTL_UDATE_DEFINED */
  526. /* /////////////////////////////////////////////////////////////////////////
  527. * c_str_len
  528. *
  529. * NOTE: The following are provided as function overloads, rather than, as
  530. * originally implemented, with defaulted bMilliseconds argument, because
  531. * DMC++ gives "ambiguous reference to symbol" errors. (And I didn't have
  532. * time to investigate further.)
  533. */
  534. // SYSTEMTIME
  535. inline ws_size_t c_str_len_a(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  536. {
  537. typedef winstl_shims_access_string_time_impl impl_t;
  538. int (STLSOFT_STDCALL *pfnGetTimeFormatA)( LCID Locale // locale
  539. , DWORD dwFlags // options
  540. , CONST SYSTEMTIME *lpTime // time
  541. , ws_char_a_t const *lpFormat // time format string
  542. , ws_char_a_t *lpTimeStr // formatted string buffer
  543. , int cchTime) // size of string buffer
  544. = bMilliseconds ? GetTimeFormat_msA : ::GetTimeFormatA;
  545. ws_size_t cchDate = 0;
  546. ws_size_t cchTime = 0;
  547. return impl_t::calc_sizes(t, ::GetDateFormatA, pfnGetTimeFormatA, cchDate, cchTime);
  548. }
  549. inline ws_size_t c_str_len_a(SYSTEMTIME const& t)
  550. {
  551. return c_str_len_a(t, ws_false_v);
  552. }
  553. inline ws_size_t c_str_len_w(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  554. {
  555. typedef winstl_shims_access_string_time_impl impl_t;
  556. int (STLSOFT_STDCALL *pfnGetTimeFormatW)( LCID Locale // locale
  557. , DWORD dwFlags // options
  558. , CONST SYSTEMTIME *lpTime // time
  559. , ws_char_w_t const *lpFormat // time format string
  560. , ws_char_w_t *lpTimeStr // formatted string buffer
  561. , int cchTime) // size of string buffer
  562. = bMilliseconds ? GetTimeFormat_msW : ::GetTimeFormatW;
  563. ws_size_t cchDate = 0;
  564. ws_size_t cchTime = 0;
  565. return impl_t::calc_sizes(t, ::GetDateFormatW, pfnGetTimeFormatW, cchDate, cchTime);
  566. }
  567. inline ws_size_t c_str_len_w(SYSTEMTIME const& t)
  568. {
  569. return c_str_len_w(t, ws_false_v);
  570. }
  571. inline ws_size_t c_str_len(SYSTEMTIME const& t, ws_bool_t bMilliseconds)
  572. {
  573. #ifdef UNICODE
  574. return c_str_len_w(t, bMilliseconds);
  575. #else /* ? UNICODD */
  576. return c_str_len_a(t, bMilliseconds);
  577. #endif /* UNICODD */
  578. }
  579. inline ws_size_t c_str_len(SYSTEMTIME const& t)
  580. {
  581. return c_str_len(t, ws_false_v);
  582. }
  583. // FILETIME
  584. inline ws_size_t c_str_len_a(FILETIME const& t, ws_bool_t bMilliseconds)
  585. {
  586. return c_str_len_a(FILETIME2SYSTEMTIME(t), bMilliseconds);
  587. }
  588. inline ws_size_t c_str_len_a(FILETIME const& t)
  589. {
  590. return c_str_len_a(FILETIME2SYSTEMTIME(t), ws_false_v);
  591. }
  592. inline ws_size_t c_str_len_w(FILETIME const& t, ws_bool_t bMilliseconds)
  593. {
  594. return c_str_len_w(FILETIME2SYSTEMTIME(t), bMilliseconds);
  595. }
  596. inline ws_size_t c_str_len_w(FILETIME const& t)
  597. {
  598. return c_str_len_w(FILETIME2SYSTEMTIME(t), ws_false_v);
  599. }
  600. inline ws_size_t c_str_len(FILETIME const& t, ws_bool_t bMilliseconds)
  601. {
  602. return c_str_len(FILETIME2SYSTEMTIME(t), bMilliseconds);
  603. }
  604. inline ws_size_t c_str_len(FILETIME const& t)
  605. {
  606. return c_str_len(FILETIME2SYSTEMTIME(t), ws_false_v);
  607. }
  608. // UDATE
  609. #ifdef WINSTL_UDATE_DEFINED
  610. inline ws_size_t c_str_len_a(UDATE const& t, ws_bool_t bMilliseconds)
  611. {
  612. return c_str_len_a(t.st, bMilliseconds);
  613. }
  614. inline ws_size_t c_str_len_a(UDATE const& t)
  615. {
  616. return c_str_len_a(t.st, ws_false_v);
  617. }
  618. inline ws_size_t c_str_len_w(UDATE const& t, ws_bool_t bMilliseconds)
  619. {
  620. return c_str_len_w(t.st, bMilliseconds);
  621. }
  622. inline ws_size_t c_str_len_w(UDATE const& t)
  623. {
  624. return c_str_len_w(t.st, ws_false_v);
  625. }
  626. inline ws_size_t c_str_len(UDATE const& t, ws_bool_t bMilliseconds)
  627. {
  628. return c_str_len(t.st, bMilliseconds);
  629. }
  630. inline ws_size_t c_str_len(UDATE const& t)
  631. {
  632. return c_str_len(t.st, ws_false_v);
  633. }
  634. #endif /* WINSTL_UDATE_DEFINED */
  635. /* /////////////////////////////////////////////////////////////////////////
  636. * Stream inserter
  637. */
  638. /** \brief An inserter function for SYSTEMTIME into output streams
  639. *
  640. * \ingroup group__library__shims__string_access
  641. *
  642. */
  643. template <ss_typename_param_k S>
  644. inline S& operator <<(S& s, SYSTEMTIME const& st)
  645. {
  646. stream_insert(s, st);
  647. return s;
  648. }
  649. /** \brief An inserter function for FILETIME into output streams
  650. *
  651. * \ingroup group__library__shims__string_access
  652. *
  653. */
  654. template <ss_typename_param_k S>
  655. inline S& operator <<(S& s, FILETIME const& ft)
  656. {
  657. stream_insert(s, ft);
  658. return s;
  659. }
  660. #ifdef WINSTL_UDATE_DEFINED
  661. /** \brief An inserter function for UDATE into output streams
  662. *
  663. * \ingroup group__library__shims__string_access
  664. *
  665. */
  666. template <ss_typename_param_k S>
  667. inline S& operator <<(S& s, UDATE const& ud)
  668. {
  669. stream_insert(s, ud);
  670. return s;
  671. }
  672. #endif /* WINSTL_UDATE_DEFINED */
  673. /* ////////////////////////////////////////////////////////////////////// */
  674. #ifndef _WINSTL_NO_NAMESPACE
  675. # if defined(_STLSOFT_NO_NAMESPACE) || \
  676. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  677. } // namespace winstl
  678. # else
  679. } // namespace winstl_project
  680. } // namespace stlsoft
  681. # endif /* _STLSOFT_NO_NAMESPACE */
  682. /** \brief An inserter function for SYSTEMTIME into output streams
  683. *
  684. * \ingroup group__library__shims__string_access
  685. *
  686. */
  687. template <ss_typename_param_k S>
  688. inline S& operator <<(S& s, SYSTEMTIME const& st)
  689. {
  690. ::winstl::stream_insert(s, st);
  691. return s;
  692. }
  693. /** \brief An inserter function for FILETIME into output streams
  694. *
  695. * \ingroup group__library__shims__string_access
  696. *
  697. */
  698. template <ss_typename_param_k S>
  699. inline S& operator <<(S& s, FILETIME const& st)
  700. {
  701. ::winstl::stream_insert(s, st);
  702. return s;
  703. }
  704. namespace stlsoft
  705. {
  706. using ::winstl::c_str_ptr_null;
  707. using ::winstl::c_str_ptr_null_a;
  708. using ::winstl::c_str_ptr_null_w;
  709. using ::winstl::c_str_ptr;
  710. using ::winstl::c_str_ptr_a;
  711. using ::winstl::c_str_ptr_w;
  712. using ::winstl::c_str_data;
  713. using ::winstl::c_str_data_a;
  714. using ::winstl::c_str_data_w;
  715. using ::winstl::c_str_len;
  716. using ::winstl::c_str_len_a;
  717. using ::winstl::c_str_len_w;
  718. } // namespace stlsoft
  719. #endif /* !_WINSTL_NO_NAMESPACE */
  720. /* /////////////////////////////////////////////////////////////////////////
  721. * Namespace
  722. */
  723. #ifndef _WINSTL_NO_NAMESPACE
  724. # if defined(_STLSOFT_NO_NAMESPACE) || \
  725. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  726. /* There is no stlsoft namespace, so must define ::winstl */
  727. namespace winstl
  728. {
  729. # else
  730. /* Define stlsoft::winstl_project */
  731. namespace stlsoft
  732. {
  733. namespace winstl_project
  734. {
  735. # endif /* _STLSOFT_NO_NAMESPACE */
  736. #endif /* !_WINSTL_NO_NAMESPACE */
  737. ////////////////////////////////////////////////////////////////////////////
  738. // Unit-testing
  739. #ifdef STLSOFT_UNITTEST
  740. # include "./unittest/time_unittest_.h"
  741. #endif /* STLSOFT_UNITTEST */
  742. /* ////////////////////////////////////////////////////////////////////// */
  743. #ifndef _WINSTL_NO_NAMESPACE
  744. # if defined(_STLSOFT_NO_NAMESPACE) || \
  745. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  746. } // namespace winstl
  747. # else
  748. } // namespace winstl_project
  749. } // namespace stlsoft
  750. # endif /* _STLSOFT_NO_NAMESPACE */
  751. #endif /* !_WINSTL_NO_NAMESPACE */
  752. /* ////////////////////////////////////////////////////////////////////// */
  753. #endif /* !WINSTL_INCL_WINSTL_SHIMS_ACCESS_STRING_HPP_TIME */
  754. /* ///////////////////////////// end of file //////////////////////////// */