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.

191 lines
7.4 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/inserters/xi.hpp
  3. *
  4. * Purpose: Defines shorthand name for pantheios::integer inserter
  5. * class for inserting integers in hexadecimal format.
  6. *
  7. * Created: 12th March 2010
  8. * Updated: 26th November 2010
  9. *
  10. * Home: http://www.pantheios.org/
  11. *
  12. * Copyright (c) 2010, Matthew Wilson and Synesis Software
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are
  17. * met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  25. * names of any contributors may be used to endorse or promote products
  26. * derived from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  32. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  37. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file pantheios/inserters/xi.hpp
  42. *
  43. * [C++ only] Defines shorthand name for pantheios::integer inserter class
  44. * for inserting integers in hexadecimal format.
  45. */
  46. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_XI
  47. #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_XI
  48. /* /////////////////////////////////////////////////////////////////////////
  49. * Version information
  50. */
  51. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  52. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_XI_MAJOR 1
  53. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_XI_MINOR 0
  54. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_XI_REVISION 4
  55. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_XI_EDIT 6
  56. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  57. /* /////////////////////////////////////////////////////////////////////////
  58. * Includes
  59. */
  60. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  61. # include <pantheios/pantheios.h>
  62. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  63. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_INTEGER
  64. # include <pantheios/inserters/integer.hpp>
  65. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_INTEGER */
  66. /* /////////////////////////////////////////////////////////////////////////
  67. * Namespace
  68. */
  69. #if !defined(PANTHEIOS_NO_NAMESPACE)
  70. namespace pantheios
  71. {
  72. #endif /* !PANTHEIOS_NO_NAMESPACE */
  73. /* /////////////////////////////////////////////////////////////////////////
  74. * Classes
  75. */
  76. /** Shortcut inserter class for inserting integers in a hexadecimal format.
  77. */
  78. class xi
  79. : public integer
  80. {
  81. public:
  82. /// The parent class type
  83. typedef integer parent_class_type;
  84. /// This type
  85. typedef xi class_type;
  86. private:
  87. // These helpers have to be here, otherwise CodeWarrior doesn't see them
  88. static int get_default_width_(size_t numBytes)
  89. {
  90. return 2 + int(2 * numBytes);
  91. }
  92. static int validate_width_(int width)
  93. {
  94. return width;
  95. }
  96. public:
  97. #ifdef STLSOFT_CF_8BIT_INT_EXTENDED_TYPE_IS_DISTINCT
  98. /// Construct from an 8-bit signed integer
  99. explicit xi(::stlsoft::sint8_t i, int width = get_default_width_(1))
  100. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  101. {}
  102. /// Construct from an 8-bit unsigned integer
  103. explicit xi(::stlsoft::uint8_t i, int width = get_default_width_(1))
  104. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  105. {}
  106. #endif // STLSOFT_CF_8BIT_INT_EXTENDED_TYPE_IS_DISTINCT
  107. #ifdef STLSOFT_CF_16BIT_INT_EXTENDED_TYPE_IS_DISTINCT
  108. /// Construct from a 16-bit signed integer
  109. explicit xi(::stlsoft::sint16_t i, int width = get_default_width_(2))
  110. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  111. {}
  112. /// Construct from a 16-bit unsigned integer
  113. explicit xi(::stlsoft::uint16_t i, int width = get_default_width_(2))
  114. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  115. {}
  116. #endif // STLSOFT_CF_16BIT_INT_EXTENDED_TYPE_IS_DISTINCT
  117. #if defined(STLSOFT_CF_32BIT_INT_EXTENDED_TYPE_IS_DISTINCT) || \
  118. ( defined(STLSOFT_COMPILER_IS_MSVC) && \
  119. _MSC_VER == 1200) /* NOTE: This is a hack, and should be updated when STLSoft 1.10 is released */
  120. /// Construct from a 32-bit signed integer
  121. explicit xi(::stlsoft::sint32_t i, int width = get_default_width_(4))
  122. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  123. {}
  124. /// Construct from a 32-bit unsigned integer
  125. explicit xi(::stlsoft::uint32_t i, int width = get_default_width_(4))
  126. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  127. {}
  128. #endif // STLSOFT_CF_32BIT_INT_EXTENDED_TYPE_IS_DISTINCT
  129. #ifdef STLSOFT_CF_64BIT_INT_SUPPORT
  130. /// Construct from a 64-bit signed integer
  131. explicit xi(::stlsoft::sint64_t i, int width = get_default_width_(8))
  132. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  133. {}
  134. /// Construct from a 64-bit unsigned integer
  135. explicit xi(::stlsoft::uint64_t i, int width = get_default_width_(8))
  136. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  137. {}
  138. #endif /* STLSOFT_CF_64BIT_INT_SUPPORT */
  139. /// Construct from an int
  140. explicit xi(int i, int width = get_default_width_(sizeof(int)))
  141. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  142. {}
  143. /// Construct from an unsigned int
  144. explicit xi(unsigned int i, int width = get_default_width_(sizeof(unsigned int)))
  145. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  146. {}
  147. /// Construct from a long
  148. explicit xi(long i, int width = get_default_width_(sizeof(long)))
  149. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  150. {}
  151. /// Construct from an unsigned long
  152. explicit xi(unsigned long i, int width = get_default_width_(sizeof(unsigned long)))
  153. : parent_class_type(i, validate_width_(width), int(fmt::fullHex))
  154. {}
  155. };
  156. /* /////////////////////////////////////////////////////////////////////////
  157. * Namespace
  158. */
  159. #if !defined(PANTHEIOS_NO_NAMESPACE)
  160. } /* namespace pantheios */
  161. #endif /* !PANTHEIOS_NO_NAMESPACE */
  162. /* /////////////////////////////////////////////////////////////////////////
  163. * Inclusion
  164. */
  165. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  166. # pragma once
  167. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  168. /* ////////////////////////////////////////////////////////////////////// */
  169. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_XI */
  170. /* ///////////////////////////// end of file //////////////////////////// */