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.

1322 lines
43 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/util/integral_printf_traits.hpp (formerly stlsoft/util/printf_traits.hpp)
  3. *
  4. * Purpose: integral_printf_traits classes.
  5. *
  6. * Created: 16th January 2002
  7. * Updated: 10th July 2012
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2002-2012, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are
  16. * met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice,
  19. * this list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  24. * names of any contributors may be used to endorse or promote products
  25. * derived from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  31. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file stlsoft/util/integral_printf_traits.hpp
  41. *
  42. * \brief [C++ only] Definition of the stlsoft::integral_printf_traits class
  43. * template
  44. * (\ref group__library__utility "Utility" Library).
  45. */
  46. #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_INTEGRAL_PRINTF_TRAITS
  47. #define STLSOFT_INCL_STLSOFT_UTIL_HPP_INTEGRAL_PRINTF_TRAITS
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define STLSOFT_VER_STLSOFT_UTIL_HPP_INTEGRAL_PRINTF_TRAITS_MAJOR 5
  50. # define STLSOFT_VER_STLSOFT_UTIL_HPP_INTEGRAL_PRINTF_TRAITS_MINOR 2
  51. # define STLSOFT_VER_STLSOFT_UTIL_HPP_INTEGRAL_PRINTF_TRAITS_REVISION 3
  52. # define STLSOFT_VER_STLSOFT_UTIL_HPP_INTEGRAL_PRINTF_TRAITS_EDIT 70
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  58. # include <stlsoft/stlsoft.h>
  59. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  60. #ifdef STLSOFT_UNITTEST
  61. # include <stlsoft/util/limit_traits.h>
  62. # include <stlsoft/meta/yesno.hpp>
  63. # include <stlsoft/util/std/stdio_overload_detectors.hpp>
  64. # include <stdarg.h>
  65. # include <stdio.h>
  66. # include <string.h>
  67. # include <wchar.h>
  68. #endif /* STLSOFT_UNITTEST */
  69. /* /////////////////////////////////////////////////////////////////////////
  70. * Namespace
  71. */
  72. #ifndef _STLSOFT_NO_NAMESPACE
  73. namespace stlsoft
  74. {
  75. #endif /* _STLSOFT_NO_NAMESPACE */
  76. /* /////////////////////////////////////////////////////////////////////////
  77. * Constants & definitions
  78. */
  79. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  80. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT8_MIN -128
  81. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT8_MAX 127
  82. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT8_MIN 0
  83. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT8_MAX 255
  84. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MIN -32768
  85. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MAX 32767
  86. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MIN 0
  87. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MAX 65535
  88. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT32_MIN -2147483648
  89. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT32_MAX 2147483647
  90. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT32_MIN 0
  91. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT32_MAX 4294967295
  92. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MIN -9223372036854775808
  93. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MAX 9223372036854775807
  94. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MIN 0
  95. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MAX 18446744073709551615
  96. /* char */
  97. # if _STLSOFT_SIZEOF_CHAR == 1
  98. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SCHAR_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT8_MIN
  99. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SCHAR_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT8_MAX
  100. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UCHAR_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT8_MIN
  101. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UCHAR_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT8_MAX
  102. # ifdef STLSOFT_CF_CHAR_IS_UNSIGNED
  103. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_CHAR_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UCHAR_MIN
  104. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_CHAR_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UCHAR_MAX
  105. # else /* ? STLSOFT_CF_CHAR_IS_UNSIGNED */
  106. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_CHAR_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SCHAR_MIN
  107. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_CHAR_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SCHAR_MAX
  108. # endif /* STLSOFT_CF_CHAR_IS_UNSIGNED */
  109. # else /* ? _STLSOFT_SIZEOF_CHAR */
  110. # error Cannot operate with a compiler for which sizeof(char) != 1
  111. # endif /* _STLSOFT_SIZEOF_CHAR */
  112. /* short */
  113. # if _STLSOFT_SIZEOF_SHORT == 2
  114. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SHORT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MIN
  115. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SHORT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MAX
  116. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_USHORT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MIN
  117. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_USHORT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MAX
  118. # elif _STLSOFT_SIZEOF_SHORT == 4
  119. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SHORT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MIN
  120. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_SHORT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MAX
  121. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_USHORT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MIN
  122. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_USHORT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MAX
  123. # else /* ? _STLSOFT_SIZEOF_SHORT */
  124. # error Cannot operate with a compiler for which sizeof(short) != 2 && sizeof(short) != 4
  125. # endif /* _STLSOFT_SIZEOF_SHORT */
  126. /* int */
  127. # if _STLSOFT_SIZEOF_INT == 2
  128. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_INT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MIN
  129. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_INT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MAX
  130. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MIN
  131. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MAX
  132. # elif _STLSOFT_SIZEOF_INT == 4
  133. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_INT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT32_MIN
  134. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_INT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT32_MAX
  135. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT32_MIN
  136. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT32_MAX
  137. # elif _STLSOFT_SIZEOF_INT == 8
  138. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_INT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MIN
  139. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_INT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MAX
  140. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MIN
  141. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MAX
  142. # else /* ? _STLSOFT_SIZEOF_INT */
  143. # error Cannot operate with a compiler for which sizeof(int) != 2 && sizeof(int) != 4 && sizeof(int) != 8
  144. # endif /* _STLSOFT_SIZEOF_INT */
  145. /* long */
  146. # if _STLSOFT_SIZEOF_LONG == 2
  147. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MIN
  148. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT16_MAX
  149. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MIN
  150. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT16_MAX
  151. # elif _STLSOFT_SIZEOF_LONG == 4
  152. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT32_MIN
  153. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT32_MAX
  154. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT32_MIN
  155. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT32_MAX
  156. # elif _STLSOFT_SIZEOF_LONG == 8
  157. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MIN
  158. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MAX
  159. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MIN
  160. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MAX
  161. # else /* ? _STLSOFT_SIZEOF_LONG */
  162. # error Cannot operate with a compiler for which sizeof(long) != 2 && sizeof(long) != 4 && sizeof(long) != 8
  163. # endif /* _STLSOFT_SIZEOF_LONG */
  164. /* long long */
  165. # ifdef STLSOFT_CF_BUILTIN_long_long_SUPPORT
  166. # if _STLSOFT_SIZEOF_LONG_LONG == 8
  167. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_LONG_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MIN
  168. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_LONG_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MAX
  169. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_LONG_MIN STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MIN
  170. # define STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_LONG_MAX STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MAX
  171. # else /* ? _STLSOFT_SIZEOF_LONG_LONG */
  172. # error Cannot operate with a compiler for which sizeof(long long) != 8
  173. # endif /* _STLSOFT_SIZEOF_LONG_LONG */
  174. # endif /* STLSOFT_CF_BUILTIN_long_long_SUPPORT */
  175. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  176. /* /////////////////////////////////////////////////////////////////////////
  177. * Macros
  178. */
  179. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  180. #ifdef STLSOFT_CF_64_BIT_PRINTF_USES_I64
  181. # undef STLSOFT_CF_64_BIT_PRINTF_USES_I64
  182. #endif /* STLSOFT_CF_64_BIT_PRINTF_USES_I64 */
  183. #ifdef STLSOFT_CF_64_BIT_PRINTF_USES_LL
  184. # undef STLSOFT_CF_64_BIT_PRINTF_USES_LL
  185. #endif /* STLSOFT_CF_64_BIT_PRINTF_USES_LL */
  186. # if defined(STLSOFT_COMPILER_IS_BORLAND) || \
  187. ( defined(STLSOFT_COMPILER_IS_COMO) && \
  188. defined(_MSC_VER)) || \
  189. ( defined(WIN32) && \
  190. ( defined(STLSOFT_COMPILER_IS_GCC)) || \
  191. defined(STLSOFT_COMPILER_IS_INTEL)) || \
  192. ( defined(STLSOFT_COMPILER_IS_MSVC) /* && \
  193. _MSC_VER < 1400 */) || \
  194. defined(STLSOFT_COMPILER_IS_VECTORC) || \
  195. defined(STLSOFT_COMPILER_IS_WATCOM)
  196. # define STLSOFT_CF_64_BIT_PRINTF_USES_I64
  197. # elif defined(STLSOFT_COMPILER_IS_COMO) || \
  198. defined(STLSOFT_COMPILER_IS_DMC) || \
  199. defined(STLSOFT_COMPILER_IS_GCC) || \
  200. defined(STLSOFT_COMPILER_IS_INTEL) || \
  201. ( defined(STLSOFT_COMPILER_IS_MSVC) && \
  202. _MSC_VER >= 1400) || \
  203. defined(STLSOFT_COMPILER_IS_MWERKS) || \
  204. defined(STLSOFT_COMPILER_IS_SUNPRO)
  205. # define STLSOFT_CF_64_BIT_PRINTF_USES_LL
  206. # else /* ? compiler */
  207. # error Further compiler discrimination is required
  208. # endif /* printf-64 */
  209. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  210. /* /////////////////////////////////////////////////////////////////////////
  211. * Classes
  212. */
  213. // struct integral_printf_traits
  214. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  215. /** \brief Traits for determining the size, in printf-ed form, of the minimum and
  216. * maximum values of types
  217. *
  218. * \ingroup group__library__utility
  219. *
  220. * integral_printf_traits is a traits class for acquiring enum values representing the
  221. * lengths, when expressed in string form, of the minimum and maximum values of
  222. * the type, and the maximum of the two. The lengths are inclusive of the
  223. * null terminator.
  224. *
  225. \code
  226. assert(stlsoft::integral_printf_traits<ss_sint16_t>::size_min == 6);
  227. assert(stlsoft::integral_printf_traits<ss_sint16_t>::size_max == 7);
  228. assert(stlsoft::integral_printf_traits<ss_sint16_t>::size == 7);
  229. \endcode
  230. *
  231. * \param T The type
  232. *
  233. */
  234. template <ss_typename_param_k T>
  235. struct integral_printf_traits
  236. {
  237. enum
  238. {
  239. /// [DEPRECATED] The number of decimal characters (+ null) in
  240. /// the minimum decimal value
  241. ///
  242. /// \deprecated This member constant is deprecated, and will be
  243. /// removed in a future version of STLSoft
  244. size_min
  245. /// [DEPRECATED] The number of decimal characters (+ null) in
  246. /// the maximum decimal value
  247. ///
  248. /// \deprecated This member constant is deprecated, and will be
  249. /// removed in a future version of STLSoft
  250. , size_max
  251. /// [DEPRECATED] The maximum of \c size_min and \c size_max
  252. ///
  253. /// \deprecated This member constant is deprecated, and will be
  254. /// removed in a future version of STLSoft
  255. , size
  256. };
  257. /// Returns the appropriate decimal integral printf format for the type
  258. static ss_char_a_t const* decimal_format_a();
  259. /// Returns the appropriate decimal integral wprintf format for the type
  260. static ss_char_w_t const* decimal_format_w();
  261. /// Returns the appropriate hexadecimal integral printf format for the type
  262. static ss_char_a_t const* hexadecimal_format_a(bool upperCase);
  263. /// Returns the appropriate hexadecimal integral wprintf format for the type
  264. static ss_char_w_t const* hexadecimal_format_w(bool upperCase);
  265. /// Returns the appropriate octal integral printf format for the type
  266. static ss_char_a_t const* octal_format_a();
  267. /// Returns the appropriate octal integral wprintf format for the type
  268. static ss_char_w_t const* octal_format_w();
  269. /// Returns the appropriate integral printf format for the type
  270. ///
  271. /// \deprecated This method is deprecated, and may be removed in a
  272. /// future version; use decimal_format_a().
  273. static ss_char_a_t const* format_a();
  274. /// Returns the appropriate integral wprintf format for the type
  275. ///
  276. /// \deprecated This method is deprecated, and may be removed in a
  277. /// future version; use decimal_format_w().
  278. static ss_char_w_t const* format_w();
  279. /// Returns the appropriate hexadecimal printf format for the type
  280. ///
  281. /// \deprecated This method is deprecated, and may be removed in a
  282. /// future version; use hexadecimal_format_a(false).
  283. static ss_char_a_t const* hex_format_a();
  284. /// Returns the appropriate hexadecimal wprintf format for the type
  285. ///
  286. /// \deprecated This method is deprecated, and may be removed in a
  287. /// future version; use hexadecimal_format_w(false).
  288. static ss_char_w_t const* hex_format_w();
  289. };
  290. #else /* ? STLSOFT_DOCUMENTATION_SKIP_SECTION */
  291. template <ss_typename_param_k T>
  292. struct integral_printf_traits;
  293. STLSOFT_OPEN_WORKER_NS_(ximpl_integral_printf_traits)
  294. template <ss_typename_param_k T>
  295. struct integral_printf_traits_base;
  296. /* char */
  297. STLSOFT_TEMPLATE_SPECIALISATION
  298. struct integral_printf_traits_base<void>
  299. {
  300. static ss_char_a_t const* get_hexadecimal_format_pcx_a_(int upperCase)
  301. {
  302. static ss_char_a_t const* const s_strings[] =
  303. {
  304. "%x"
  305. , "%X"
  306. };
  307. return s_strings[0 != upperCase];
  308. }
  309. static ss_char_w_t const* get_hexadecimal_format_pcx_w_(int upperCase)
  310. {
  311. static ss_char_w_t const* const s_strings[] =
  312. {
  313. L"%x"
  314. , L"%X"
  315. };
  316. return s_strings[0 != upperCase];
  317. }
  318. static ss_char_a_t const* get_hexadecimal_format_pclx_a_(int upperCase)
  319. {
  320. static ss_char_a_t const* const s_strings[] =
  321. {
  322. "%lx"
  323. , "%lX"
  324. };
  325. return s_strings[0 != upperCase];
  326. }
  327. static ss_char_w_t const* get_hexadecimal_format_pclx_w_(int upperCase)
  328. {
  329. static ss_char_w_t const* const s_strings[] =
  330. {
  331. L"%lx"
  332. , L"%lX"
  333. };
  334. return s_strings[0 != upperCase];
  335. }
  336. static ss_char_a_t const* get_hexadecimal_format_pci64x_a_(int upperCase)
  337. {
  338. static ss_char_a_t const* const s_strings[] =
  339. {
  340. "%I64x"
  341. , "%I64X"
  342. };
  343. return s_strings[0 != upperCase];
  344. }
  345. static ss_char_w_t const* get_hexadecimal_format_pci64x_w_(int upperCase)
  346. {
  347. static ss_char_w_t const* const s_strings[] =
  348. {
  349. L"%I64x"
  350. , L"%I64X"
  351. };
  352. return s_strings[0 != upperCase];
  353. }
  354. static ss_char_a_t const* get_hexadecimal_format_pcllx_a_(int upperCase)
  355. {
  356. static ss_char_a_t const* const s_strings[] =
  357. {
  358. "%llx"
  359. , "%llX"
  360. };
  361. return s_strings[0 != upperCase];
  362. }
  363. static ss_char_w_t const* get_hexadecimal_format_pcllx_w_(int upperCase)
  364. {
  365. static ss_char_w_t const* const s_strings[] =
  366. {
  367. L"%llx"
  368. , L"%llX"
  369. };
  370. return s_strings[0 != upperCase];
  371. }
  372. };
  373. STLSOFT_TEMPLATE_SPECIALISATION
  374. struct integral_printf_traits_base<char>
  375. {
  376. enum
  377. {
  378. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_CHAR_MIN)))
  379. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_CHAR_MAX)))
  380. , size = (size_min < size_max) ? size_max : size_min
  381. };
  382. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  383. static ss_char_a_t const* format_a()
  384. {
  385. return decimal_format_a();
  386. }
  387. static ss_char_a_t const* decimal_format_a()
  388. {
  389. # ifdef STLSOFT_CF_CHAR_IS_UNSIGNED
  390. return "%u";
  391. # else /* ? STLSOFT_CF_CHAR_IS_UNSIGNED */
  392. return "%d";
  393. # endif /* STLSOFT_CF_CHAR_IS_UNSIGNED */
  394. }
  395. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  396. static ss_char_w_t const* format_w()
  397. {
  398. return decimal_format_w();
  399. }
  400. static ss_char_w_t const* decimal_format_w()
  401. {
  402. # ifdef STLSOFT_CF_CHAR_IS_UNSIGNED
  403. return L"%u";
  404. # else /* ? STLSOFT_CF_CHAR_IS_UNSIGNED */
  405. return L"%d";
  406. # endif /* STLSOFT_CF_CHAR_IS_UNSIGNED */
  407. }
  408. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  409. static ss_char_a_t const* hex_format_a()
  410. {
  411. return hexadecimal_format_a(false);
  412. }
  413. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  414. {
  415. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_a_(upperCase);
  416. }
  417. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  418. static ss_char_w_t const* hex_format_w()
  419. {
  420. return hexadecimal_format_w(false);
  421. }
  422. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  423. {
  424. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_w_(upperCase);
  425. }
  426. static ss_char_a_t const* octal_format_a()
  427. {
  428. return "%o";
  429. }
  430. static ss_char_w_t const* octal_format_w()
  431. {
  432. return L"%o";
  433. }
  434. };
  435. STLSOFT_TEMPLATE_SPECIALISATION
  436. struct integral_printf_traits_base<unsigned char>
  437. {
  438. enum
  439. {
  440. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_UCHAR_MIN)))
  441. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_UCHAR_MAX)))
  442. , size = (size_min < size_max) ? size_max : size_min
  443. };
  444. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  445. static ss_char_a_t const* format_a()
  446. {
  447. return decimal_format_a();
  448. }
  449. static ss_char_a_t const* decimal_format_a()
  450. {
  451. return "%u";
  452. }
  453. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  454. static ss_char_w_t const* format_w()
  455. {
  456. return decimal_format_w();
  457. }
  458. static ss_char_w_t const* decimal_format_w()
  459. {
  460. return L"%u";
  461. }
  462. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  463. static ss_char_a_t const* hex_format_a()
  464. {
  465. return hexadecimal_format_a(false);
  466. }
  467. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  468. {
  469. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_a_(upperCase);
  470. }
  471. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  472. static ss_char_w_t const* hex_format_w()
  473. {
  474. return hexadecimal_format_w(false);
  475. }
  476. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  477. {
  478. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_w_(upperCase);
  479. }
  480. static ss_char_a_t const* octal_format_a()
  481. {
  482. return "%o";
  483. }
  484. static ss_char_w_t const* octal_format_w()
  485. {
  486. return L"%o";
  487. }
  488. };
  489. STLSOFT_TEMPLATE_SPECIALISATION
  490. struct integral_printf_traits_base<signed char>
  491. {
  492. enum
  493. {
  494. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_SCHAR_MIN)))
  495. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_SCHAR_MAX)))
  496. , size = (size_min < size_max) ? size_max : size_min
  497. };
  498. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  499. static ss_char_a_t const* format_a()
  500. {
  501. return decimal_format_a();
  502. }
  503. static ss_char_a_t const* decimal_format_a()
  504. {
  505. return "%d";
  506. }
  507. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  508. static ss_char_w_t const* format_w()
  509. {
  510. return decimal_format_w();
  511. }
  512. static ss_char_w_t const* decimal_format_w()
  513. {
  514. return L"%d";
  515. }
  516. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  517. static ss_char_a_t const* hex_format_a()
  518. {
  519. return hexadecimal_format_a(false);
  520. }
  521. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  522. {
  523. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_a_(upperCase);
  524. }
  525. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  526. static ss_char_w_t const* hex_format_w()
  527. {
  528. return hexadecimal_format_w(false);
  529. }
  530. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  531. {
  532. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_w_(upperCase);
  533. }
  534. static ss_char_a_t const* octal_format_a()
  535. {
  536. return "%o";
  537. }
  538. static ss_char_w_t const* octal_format_w()
  539. {
  540. return L"%o";
  541. }
  542. };
  543. /* short */
  544. STLSOFT_TEMPLATE_SPECIALISATION
  545. struct integral_printf_traits_base<short>
  546. {
  547. enum
  548. {
  549. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_SHORT_MIN)))
  550. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_SHORT_MAX)))
  551. , size = (size_min < size_max) ? size_max : size_min
  552. };
  553. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  554. static ss_char_a_t const* format_a()
  555. {
  556. return decimal_format_a();
  557. }
  558. static ss_char_a_t const* decimal_format_a()
  559. {
  560. return "%d";
  561. }
  562. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  563. static ss_char_w_t const* format_w()
  564. {
  565. return decimal_format_w();
  566. }
  567. static ss_char_w_t const* decimal_format_w()
  568. {
  569. return L"%d";
  570. }
  571. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  572. static ss_char_a_t const* hex_format_a()
  573. {
  574. return hexadecimal_format_a(false);
  575. }
  576. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  577. {
  578. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_a_(upperCase);
  579. }
  580. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  581. static ss_char_w_t const* hex_format_w()
  582. {
  583. return hexadecimal_format_w(false);
  584. }
  585. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  586. {
  587. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_w_(upperCase);
  588. }
  589. static ss_char_a_t const* octal_format_a()
  590. {
  591. return "%o";
  592. }
  593. static ss_char_w_t const* octal_format_w()
  594. {
  595. return L"%o";
  596. }
  597. };
  598. STLSOFT_TEMPLATE_SPECIALISATION
  599. struct integral_printf_traits_base<unsigned short>
  600. {
  601. enum
  602. {
  603. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_USHORT_MIN)))
  604. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_USHORT_MAX)))
  605. , size = (size_min < size_max) ? size_max : size_min
  606. };
  607. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  608. static ss_char_a_t const* format_a()
  609. {
  610. return decimal_format_a();
  611. }
  612. static ss_char_a_t const* decimal_format_a()
  613. {
  614. return "%u";
  615. }
  616. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  617. static ss_char_w_t const* format_w()
  618. {
  619. return decimal_format_w();
  620. }
  621. static ss_char_w_t const* decimal_format_w()
  622. {
  623. return L"%u";
  624. }
  625. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  626. static ss_char_a_t const* hex_format_a()
  627. {
  628. return hexadecimal_format_a(false);
  629. }
  630. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  631. {
  632. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_a_(upperCase);
  633. }
  634. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  635. static ss_char_w_t const* hex_format_w()
  636. {
  637. return hexadecimal_format_w(false);
  638. }
  639. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  640. {
  641. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_w_(upperCase);
  642. }
  643. static ss_char_a_t const* octal_format_a()
  644. {
  645. return "%o";
  646. }
  647. static ss_char_w_t const* octal_format_w()
  648. {
  649. return L"%o";
  650. }
  651. };
  652. /* int */
  653. STLSOFT_TEMPLATE_SPECIALISATION
  654. struct integral_printf_traits_base<int>
  655. {
  656. enum
  657. {
  658. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_INT_MIN)))
  659. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_INT_MAX)))
  660. , size = (size_min < size_max) ? size_max : size_min
  661. };
  662. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  663. static ss_char_a_t const* format_a()
  664. {
  665. return decimal_format_a();
  666. }
  667. static ss_char_a_t const* decimal_format_a()
  668. {
  669. return "%d";
  670. }
  671. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  672. static ss_char_w_t const* format_w()
  673. {
  674. return decimal_format_w();
  675. }
  676. static ss_char_w_t const* decimal_format_w()
  677. {
  678. return L"%d";
  679. }
  680. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  681. static ss_char_a_t const* hex_format_a()
  682. {
  683. return hexadecimal_format_a(false);
  684. }
  685. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  686. {
  687. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_a_(upperCase);
  688. }
  689. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  690. static ss_char_w_t const* hex_format_w()
  691. {
  692. return hexadecimal_format_w(false);
  693. }
  694. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  695. {
  696. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_w_(upperCase);
  697. }
  698. static ss_char_a_t const* octal_format_a()
  699. {
  700. return "%o";
  701. }
  702. static ss_char_w_t const* octal_format_w()
  703. {
  704. return L"%o";
  705. }
  706. };
  707. STLSOFT_TEMPLATE_SPECIALISATION
  708. struct integral_printf_traits_base<unsigned int>
  709. {
  710. enum
  711. {
  712. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT_MIN)))
  713. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT_MAX)))
  714. , size = (size_min < size_max) ? size_max : size_min
  715. };
  716. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  717. static ss_char_a_t const* format_a()
  718. {
  719. return decimal_format_a();
  720. }
  721. static ss_char_a_t const* decimal_format_a()
  722. {
  723. return "%u";
  724. }
  725. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  726. static ss_char_w_t const* format_w()
  727. {
  728. return decimal_format_w();
  729. }
  730. static ss_char_w_t const* decimal_format_w()
  731. {
  732. return L"%u";
  733. }
  734. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  735. static ss_char_a_t const* hex_format_a()
  736. {
  737. return hexadecimal_format_a(false);
  738. }
  739. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  740. {
  741. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_a_(upperCase);
  742. }
  743. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  744. static ss_char_w_t const* hex_format_w()
  745. {
  746. return hexadecimal_format_w(false);
  747. }
  748. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  749. {
  750. return integral_printf_traits_base<void>::get_hexadecimal_format_pcx_w_(upperCase);
  751. }
  752. static ss_char_a_t const* octal_format_a()
  753. {
  754. return "%o";
  755. }
  756. static ss_char_w_t const* octal_format_w()
  757. {
  758. return L"%o";
  759. }
  760. };
  761. /* long */
  762. STLSOFT_TEMPLATE_SPECIALISATION
  763. struct integral_printf_traits_base<long>
  764. {
  765. enum
  766. {
  767. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_MIN)))
  768. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_LONG_MAX)))
  769. , size = (size_min < size_max) ? size_max : size_min
  770. };
  771. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  772. static ss_char_a_t const* format_a()
  773. {
  774. return decimal_format_a();
  775. }
  776. static ss_char_a_t const* decimal_format_a()
  777. {
  778. return "%ld";
  779. }
  780. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  781. static ss_char_w_t const* format_w()
  782. {
  783. return decimal_format_w();
  784. }
  785. static ss_char_w_t const* decimal_format_w()
  786. {
  787. return L"%ld";
  788. }
  789. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  790. static ss_char_a_t const* hex_format_a()
  791. {
  792. return hexadecimal_format_a(false);
  793. }
  794. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  795. {
  796. return integral_printf_traits_base<void>::get_hexadecimal_format_pclx_a_(upperCase);
  797. }
  798. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  799. static ss_char_w_t const* hex_format_w()
  800. {
  801. return hexadecimal_format_w(false);
  802. }
  803. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  804. {
  805. return integral_printf_traits_base<void>::get_hexadecimal_format_pclx_w_(upperCase);
  806. }
  807. static ss_char_a_t const* octal_format_a()
  808. {
  809. return "%lo";
  810. }
  811. static ss_char_w_t const* octal_format_w()
  812. {
  813. return L"%lo";
  814. }
  815. };
  816. STLSOFT_TEMPLATE_SPECIALISATION
  817. struct integral_printf_traits_base<unsigned long>
  818. {
  819. enum
  820. {
  821. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_MIN)))
  822. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_ULONG_MAX)))
  823. , size = (size_min < size_max) ? size_max : size_min
  824. };
  825. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  826. static ss_char_a_t const* format_a()
  827. {
  828. return decimal_format_a();
  829. }
  830. static ss_char_a_t const* decimal_format_a()
  831. {
  832. return "%lu";
  833. }
  834. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  835. static ss_char_w_t const* format_w()
  836. {
  837. return decimal_format_w();
  838. }
  839. static ss_char_w_t const* decimal_format_w()
  840. {
  841. return L"%lu";
  842. }
  843. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  844. static ss_char_a_t const* hex_format_a()
  845. {
  846. return hexadecimal_format_a(false);
  847. }
  848. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  849. {
  850. return integral_printf_traits_base<void>::get_hexadecimal_format_pclx_a_(upperCase);
  851. }
  852. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  853. static ss_char_w_t const* hex_format_w()
  854. {
  855. return hexadecimal_format_w(false);
  856. }
  857. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  858. {
  859. return integral_printf_traits_base<void>::get_hexadecimal_format_pclx_w_(upperCase);
  860. }
  861. static ss_char_a_t const* octal_format_a()
  862. {
  863. return "%lo";
  864. }
  865. static ss_char_w_t const* octal_format_w()
  866. {
  867. return L"%lo";
  868. }
  869. };
  870. /* long long */
  871. #ifdef STLSOFT_CF_64BIT_INT_SUPPORT
  872. STLSOFT_TEMPLATE_SPECIALISATION
  873. struct integral_printf_traits_base<ss_sint64_t>
  874. {
  875. enum
  876. {
  877. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MIN)))
  878. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_SINT64_MAX)))
  879. , size = (size_min < size_max) ? size_max : size_min
  880. };
  881. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  882. static ss_char_a_t const* format_a()
  883. {
  884. return decimal_format_a();
  885. }
  886. static ss_char_a_t const* decimal_format_a()
  887. {
  888. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  889. return "%I64d";
  890. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  891. return "%lld";
  892. #else
  893. # error Further compiler discrimination is required
  894. #endif /* printf-64 */
  895. }
  896. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  897. static ss_char_w_t const* format_w()
  898. {
  899. return decimal_format_w();
  900. }
  901. static ss_char_w_t const* decimal_format_w()
  902. {
  903. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  904. return L"%I64d";
  905. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  906. return L"%lld";
  907. #else
  908. # error Further compiler discrimination is required
  909. #endif /* printf-64 */
  910. }
  911. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  912. static ss_char_a_t const* hex_format_a()
  913. {
  914. return hexadecimal_format_a(false);
  915. }
  916. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  917. {
  918. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  919. return integral_printf_traits_base<void>::get_hexadecimal_format_pci64x_a_(upperCase);
  920. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  921. return integral_printf_traits_base<void>::get_hexadecimal_format_pcllx_a_(upperCase);
  922. #else
  923. # error Further compiler discrimination is required
  924. #endif /* printf-64 */
  925. }
  926. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  927. static ss_char_w_t const* hex_format_w()
  928. {
  929. return hexadecimal_format_w(false);
  930. }
  931. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  932. {
  933. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  934. return integral_printf_traits_base<void>::get_hexadecimal_format_pci64x_w_(upperCase);
  935. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  936. return integral_printf_traits_base<void>::get_hexadecimal_format_pcllx_w_(upperCase);
  937. #else
  938. # error Further compiler discrimination is required
  939. #endif /* printf-64 */
  940. }
  941. static ss_char_a_t const* octal_format_a()
  942. {
  943. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  944. return "%I64o";
  945. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  946. return "%llo";
  947. #else
  948. # error Further compiler discrimination is required
  949. #endif /* printf-64 */
  950. }
  951. static ss_char_w_t const* octal_format_w()
  952. {
  953. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  954. return L"%I64o";
  955. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  956. return L"%llo";
  957. #else
  958. # error Further compiler discrimination is required
  959. #endif /* printf-64 */
  960. }
  961. };
  962. STLSOFT_TEMPLATE_SPECIALISATION
  963. struct integral_printf_traits_base<ss_uint64_t>
  964. {
  965. enum
  966. {
  967. size_min = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MIN)))
  968. , size_max = int(sizeof(STLSOFT_STRINGIZE(STLSOFT_INTEGRAL_PRINTF_TRAITS_UINT64_MAX)))
  969. , size = (size_min < size_max) ? size_max : size_min
  970. };
  971. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_a, decimal_format_a)
  972. static ss_char_a_t const* format_a()
  973. {
  974. return decimal_format_a();
  975. }
  976. static ss_char_a_t const* decimal_format_a()
  977. {
  978. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  979. return "%I64u";
  980. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  981. return "%llu";
  982. #else
  983. # error Further compiler discrimination is required
  984. #endif /* printf-64 */
  985. }
  986. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(format_w, decimal_format_w)
  987. static ss_char_w_t const* format_w()
  988. {
  989. return decimal_format_w();
  990. }
  991. static ss_char_w_t const* decimal_format_w()
  992. {
  993. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  994. return L"%I64u";
  995. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  996. return L"%llu";
  997. #else
  998. # error Further compiler discrimination is required
  999. #endif /* printf-64 */
  1000. }
  1001. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_a, hexadecimal_format_a)
  1002. static ss_char_a_t const* hex_format_a()
  1003. {
  1004. return hexadecimal_format_a(false);
  1005. }
  1006. static ss_char_a_t const* hexadecimal_format_a(bool upperCase)
  1007. {
  1008. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  1009. return integral_printf_traits_base<void>::get_hexadecimal_format_pci64x_a_(upperCase);
  1010. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  1011. return integral_printf_traits_base<void>::get_hexadecimal_format_pcllx_a_(upperCase);
  1012. #else
  1013. # error Further compiler discrimination is required
  1014. #endif /* printf-64 */
  1015. }
  1016. STLSOFT_DECLARE_FUNCTION_DEPRECATION_IN_FAVOUR_OF(hex_format_w, hexadecimal_format_w)
  1017. static ss_char_w_t const* hex_format_w()
  1018. {
  1019. return hexadecimal_format_w(false);
  1020. }
  1021. static ss_char_w_t const* hexadecimal_format_w(bool upperCase)
  1022. {
  1023. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  1024. return integral_printf_traits_base<void>::get_hexadecimal_format_pci64x_w_(upperCase);
  1025. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  1026. return integral_printf_traits_base<void>::get_hexadecimal_format_pcllx_w_(upperCase);
  1027. #else
  1028. # error Further compiler discrimination is required
  1029. #endif /* printf-64 */
  1030. }
  1031. static ss_char_a_t const* octal_format_a()
  1032. {
  1033. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  1034. return "%I64o";
  1035. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  1036. return "%llo";
  1037. #else
  1038. # error Further compiler discrimination is required
  1039. #endif /* printf-64 */
  1040. }
  1041. static ss_char_w_t const* octal_format_w()
  1042. {
  1043. #if defined(STLSOFT_CF_64_BIT_PRINTF_USES_I64)
  1044. return L"%I64o";
  1045. #elif defined(STLSOFT_CF_64_BIT_PRINTF_USES_LL)
  1046. return L"%llo";
  1047. #else
  1048. # error Further compiler discrimination is required
  1049. #endif /* printf-64 */
  1050. }
  1051. };
  1052. #endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
  1053. STLSOFT_CLOSE_WORKER_NS_(ximpl_integral_printf_traits)
  1054. STLSOFT_TEMPLATE_SPECIALISATION
  1055. struct integral_printf_traits<char>
  1056. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<char>
  1057. {};
  1058. STLSOFT_TEMPLATE_SPECIALISATION
  1059. struct integral_printf_traits<signed char>
  1060. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<signed char>
  1061. {};
  1062. STLSOFT_TEMPLATE_SPECIALISATION
  1063. struct integral_printf_traits<unsigned char>
  1064. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<unsigned char>
  1065. {};
  1066. STLSOFT_TEMPLATE_SPECIALISATION
  1067. struct integral_printf_traits<short>
  1068. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<short>
  1069. {};
  1070. STLSOFT_TEMPLATE_SPECIALISATION
  1071. struct integral_printf_traits<unsigned short>
  1072. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<unsigned short>
  1073. {};
  1074. STLSOFT_TEMPLATE_SPECIALISATION
  1075. struct integral_printf_traits<int>
  1076. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<int>
  1077. {};
  1078. STLSOFT_TEMPLATE_SPECIALISATION
  1079. struct integral_printf_traits<unsigned int>
  1080. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<unsigned int>
  1081. {};
  1082. STLSOFT_TEMPLATE_SPECIALISATION
  1083. struct integral_printf_traits<long>
  1084. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<long>
  1085. {};
  1086. STLSOFT_TEMPLATE_SPECIALISATION
  1087. struct integral_printf_traits<unsigned long>
  1088. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<unsigned long>
  1089. {};
  1090. STLSOFT_TEMPLATE_SPECIALISATION
  1091. struct integral_printf_traits<ss_sint64_t>
  1092. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<ss_sint64_t>
  1093. {};
  1094. STLSOFT_TEMPLATE_SPECIALISATION
  1095. struct integral_printf_traits<ss_uint64_t>
  1096. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<ss_uint64_t>
  1097. {};
  1098. #ifdef STLSOFT_CF_CHAR_DISTINCT_INT_TYPE
  1099. # if _STLSOFT_SIZEOF_CHAR == 1
  1100. STLSOFT_TEMPLATE_SPECIALISATION
  1101. struct integral_printf_traits<ss_sint8_t>
  1102. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<signed char>
  1103. {};
  1104. STLSOFT_TEMPLATE_SPECIALISATION
  1105. struct integral_printf_traits<ss_uint8_t>
  1106. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<unsigned char>
  1107. {};
  1108. # endif /* _STLSOFT_SIZEOF_CHAR == 1 */
  1109. #endif /* STLSOFT_CF_CHAR_DISTINCT_INT_TYPE */
  1110. #ifdef STLSOFT_CF_SHORT_DISTINCT_INT_TYPE
  1111. # if _STLSOFT_SIZEOF_SHORT == 2
  1112. STLSOFT_TEMPLATE_SPECIALISATION
  1113. struct integral_printf_traits<ss_sint16_t>
  1114. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<short>
  1115. {};
  1116. STLSOFT_TEMPLATE_SPECIALISATION
  1117. struct integral_printf_traits<ss_uint16_t>
  1118. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<unsigned short>
  1119. {};
  1120. # endif /* _STLSOFT_SIZEOF_SHORT == 2 */
  1121. #endif /* STLSOFT_CF_SHORT_DISTINCT_INT_TYPE */
  1122. #ifdef STLSOFT_CF_INT_DISTINCT_INT_TYPE
  1123. # if _STLSOFT_SIZEOF_INT == 4
  1124. STLSOFT_TEMPLATE_SPECIALISATION
  1125. struct integral_printf_traits<ss_sint32_t>
  1126. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<int>
  1127. {};
  1128. STLSOFT_TEMPLATE_SPECIALISATION
  1129. struct integral_printf_traits<ss_uint32_t>
  1130. : public STLSOFT_WORKER_NS_QUAL_(ximpl_integral_printf_traits, integral_printf_traits_base)<unsigned int>
  1131. {};
  1132. # endif /* _STLSOFT_SIZEOF_INT == 4 */
  1133. #endif /* STLSOFT_CF_INT_DISTINCT_INT_TYPE */
  1134. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  1135. ////////////////////////////////////////////////////////////////////////////
  1136. // Unit-testing
  1137. #ifdef STLSOFT_UNITTEST
  1138. # include "./unittest/integral_printf_traits_unittest_.h"
  1139. #endif /* STLSOFT_UNITTEST */
  1140. /* ////////////////////////////////////////////////////////////////////// */
  1141. #ifndef _STLSOFT_NO_NAMESPACE
  1142. } // namespace stlsoft
  1143. #endif /* _STLSOFT_NO_NAMESPACE */
  1144. /* ////////////////////////////////////////////////////////////////////// */
  1145. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_INTEGRAL_PRINTF_TRAITS */
  1146. /* ///////////////////////////// end of file //////////////////////////// */