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.

190 lines
7.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/conversion/number/grouping_functions.hpp
  3. *
  4. * Purpose: Number formatting functions.
  5. *
  6. * Created: 28th August 2005
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2005-2009, 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 met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////////// */
  39. /** \file winstl/conversion/number/grouping_functions.hpp
  40. *
  41. * \brief [C++ only] Definition of the stlsoft::format_thousands() formatting
  42. * function
  43. * (\ref group__library__conversion "Conversion" Library).
  44. */
  45. #ifndef WINSTL_INCL_WINSTL_CONVERSION_NUMBER_HPP_GROUPING_FUNCTIONS
  46. #define WINSTL_INCL_WINSTL_CONVERSION_NUMBER_HPP_GROUPING_FUNCTIONS
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define WINSTL_VER_WINSTL_CONVERSION_NUMBER_HPP_GROUPING_FUNCTIONS_MAJOR 1
  49. # define WINSTL_VER_WINSTL_CONVERSION_NUMBER_HPP_GROUPING_FUNCTIONS_MINOR 0
  50. # define WINSTL_VER_WINSTL_CONVERSION_NUMBER_HPP_GROUPING_FUNCTIONS_REVISION 4
  51. # define WINSTL_VER_WINSTL_CONVERSION_NUMBER_HPP_GROUPING_FUNCTIONS_EDIT 11
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  57. # include <winstl/winstl.h>
  58. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  59. #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS
  60. # include <winstl/system/system_traits.hpp>
  61. #endif /* !WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS */
  62. #ifndef STLSOFT_INCL_STLSOFT_CONVERSION_NUMBER_HPP_GROUPING_FUNCTIONS
  63. # include <stlsoft/conversion/number/grouping_functions.hpp>
  64. #endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_NUMBER_HPP_GROUPING_FUNCTIONS */
  65. #ifndef STLSOFT_INCL_STLSOFT_META_HPP_YESNO
  66. # include <stlsoft/meta/yesno.hpp>
  67. #endif /* !STLSOFT_INCL_STLSOFT_META_HPP_YESNO */
  68. #ifndef STLSOFT_INCL_STLSOFT_META_HPP_IS_INTEGRAL_TYPE
  69. # include <stlsoft/meta/is_integral_type.hpp>
  70. #endif /* !STLSOFT_INCL_STLSOFT_META_HPP_IS_INTEGRAL_TYPE */
  71. /* /////////////////////////////////////////////////////////////////////////
  72. * Namespace
  73. */
  74. #ifndef _WINSTL_NO_NAMESPACE
  75. # if defined(_STLSOFT_NO_NAMESPACE) || \
  76. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  77. /* There is no stlsoft namespace, so must define ::winstl */
  78. namespace winstl
  79. {
  80. # else
  81. /* Define stlsoft::winstl_project */
  82. namespace stlsoft
  83. {
  84. namespace winstl_project
  85. {
  86. # endif /* _STLSOFT_NO_NAMESPACE */
  87. #endif /* !_WINSTL_NO_NAMESPACE */
  88. /* /////////////////////////////////////////////////////////////////////////
  89. * Functions
  90. */
  91. #if 0
  92. template< typename C
  93. , typename N
  94. >
  95. ws_size_t format_thousands( C *dest
  96. , ws_size_t cchDest
  97. , N const& number
  98. );
  99. #endif /* 0 */
  100. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  101. template< typename C
  102. , typename I
  103. >
  104. inline ws_size_t format_thousands_3_impl( C *dest
  105. , ws_size_t cchDest
  106. , I const &number
  107. , stlsoft::yes_type
  108. )
  109. {
  110. typedef system_traits<C> traits_t;
  111. int cch = traits_t::get_locale_info(LOCALE_USER_DEFAULT, LOCALE_SGROUPING, NULL, 0);
  112. stlsoft::auto_buffer<C> picture(1 + cch);
  113. cch = traits_t::get_locale_info(LOCALE_USER_DEFAULT, LOCALE_SGROUPING, &picture[0], picture.size());
  114. return stlsoft::format_thousands(dest, cchDest, picture.data(), number);
  115. }
  116. template<typename C>
  117. inline ws_size_t format_thousands_3_impl( C *dest
  118. , ws_size_t cchDest
  119. , C const *number
  120. , stlsoft::no_type
  121. )
  122. {
  123. typedef system_traits<C> traits_t;
  124. int cch = traits_t::get_locale_info(LOCALE_USER_DEFAULT, LOCALE_SGROUPING, NULL, 0);
  125. stlsoft::auto_buffer<C> picture(1 + cch);
  126. cch = traits_t::get_locale_info(LOCALE_USER_DEFAULT, LOCALE_SGROUPING, &picture[0], picture.size());
  127. return stlsoft::translate_thousands(dest, cchDest, picture.data(), number);
  128. }
  129. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  130. template< typename C
  131. , typename N
  132. >
  133. inline ws_size_t format_thousands( C *dest
  134. , ws_size_t cchDest
  135. , N const& number
  136. )
  137. {
  138. typedef ss_typename_type_k stlsoft::is_integral_type<N>::type yesno_type;
  139. return format_thousands_3_impl(dest, cchDest, number, yesno_type());
  140. }
  141. ////////////////////////////////////////////////////////////////////////////
  142. // Unit-testing
  143. #ifdef STLSOFT_UNITTEST
  144. //# include "./unittest/grouping_functions_unittest_.h"
  145. #endif /* STLSOFT_UNITTEST */
  146. /* ////////////////////////////////////////////////////////////////////// */
  147. #ifndef _WINSTL_NO_NAMESPACE
  148. # if defined(_STLSOFT_NO_NAMESPACE) || \
  149. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  150. } // namespace winstl
  151. # else
  152. } // namespace winstl_project
  153. } // namespace stlsoft
  154. # endif /* _STLSOFT_NO_NAMESPACE */
  155. #endif /* !_WINSTL_NO_NAMESPACE */
  156. /* ////////////////////////////////////////////////////////////////////// */
  157. #endif /* WINSTL_INCL_WINSTL_CONVERSION_NUMBER_HPP_GROUPING_FUNCTIONS */
  158. /* ///////////////////////////// end of file //////////////////////////// */