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.

177 lines
6.3 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/inserters/hex_ptr.hpp
  3. *
  4. * Purpose: String inserters for pointers in Hexadecimal notation.
  5. *
  6. * Created: 11th October 2006
  7. * Updated: 20th December 2012
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2006-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 names of Matthew Wilson and Synesis Software nor the names
  24. * of any contributors may be used to endorse or promote products derived
  25. * 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 pantheios/inserters/hex_ptr.hpp
  41. *
  42. * [C++ only] String inserters for pointers in Hexadecimal notation.
  43. */
  44. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_HEX_PTR
  45. #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_HEX_PTR
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Version information
  48. */
  49. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  50. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_HEX_PTR_MAJOR 1
  51. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_HEX_PTR_MINOR 3
  52. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_HEX_PTR_REVISION 1
  53. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_HEX_PTR_EDIT 17
  54. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  55. /* /////////////////////////////////////////////////////////////////////////
  56. * Includes
  57. */
  58. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  59. # include <pantheios/pantheios.h>
  60. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  61. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_POINTER
  62. # include <pantheios/inserters/pointer.hpp> // for pantheios::pointer
  63. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_POINTER */
  64. /* /////////////////////////////////////////////////////////////////////////
  65. * Namespace
  66. */
  67. #if !defined(PANTHEIOS_NO_NAMESPACE)
  68. namespace pantheios
  69. {
  70. #endif /* !PANTHEIOS_NO_NAMESPACE */
  71. /* /////////////////////////////////////////////////////////////////////////
  72. * Classes
  73. */
  74. /** [DEPRECATED] Class for inserting pointers into Pantheios diagnostic
  75. * logging statements.
  76. *
  77. * \ingroup group__application_layer_interface__inserters
  78. *
  79. * This class acts as a syntactic shorthand for the pantheios::pointer
  80. * inserter class, by supplying the common width/format values in a
  81. * defaulted constructor argument. Just as does pantheios::pointer, it
  82. * converts a pointer variable into a string, thereby enabling it to be
  83. * inserted into a logging statement.
  84. *
  85. * Consider the following statement:
  86. *
  87. * \code
  88. void* p = reinterpret_cast<void*>(0x01234567);
  89. char s[] = "abc";
  90. std::string str("def");
  91. pantheios::log(pantheios::notice, "s=", s, ", p=", pantheios::hex_ptr(p), ", str=", str);
  92. * \endcode
  93. *
  94. * On a 32-bit system, this will produce the output:
  95. *
  96. * &nbsp;&nbsp;&nbsp;&nbsp;<b>s=abc, p=0x01234567, str=def</b>
  97. *
  98. * On a 64-bit system, this will produce the output:
  99. *
  100. * &nbsp;&nbsp;&nbsp;&nbsp;<b>s=abc, p=0x0000000001234567, str=def</b>
  101. *
  102. * \deprecated This class is now obsolete, and will be removed from a future
  103. * version of Pantheios; instead use the pantheios::xp inserter class.
  104. */
  105. class hex_ptr
  106. : public pointer
  107. {
  108. public: // Member Constants
  109. enum
  110. {
  111. pointerHexWidth = sizeof(void*) * 2 /*!< The maximum number of characters required to express any pointer value as a hex string */
  112. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  113. , bitSize = pointerHexWidth
  114. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  115. };
  116. public: // Construction
  117. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  118. hex_ptr(void const volatile *p, int flags)
  119. : pointer(p, flags)
  120. {}
  121. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  122. /// Construct from a pointer, using the ambient pointer width and
  123. /// pantheios::fmt::fullHex format
  124. ///
  125. /// \param p The pointer whose value will be represented as a string
  126. explicit hex_ptr(void const volatile *p)
  127. : pointer(p, pointerHexWidth, fmt::fullHex)
  128. {}
  129. /// Construct from a pointer, with width/format specifier
  130. ///
  131. /// \param p The pointer whose value will be represented as a string
  132. /// \param minWidth The minimum width of the field. Must be in the range
  133. /// [-20, 20]
  134. /// \param format Combination of \link pantheios::fmt format\endlink flags
  135. hex_ptr(void const volatile *p, int minWidth, int format)
  136. : pointer(p, minWidth, format)
  137. {}
  138. };
  139. /* /////////////////////////////////////////////////////////////////////////
  140. * Namespace
  141. */
  142. #if !defined(PANTHEIOS_NO_NAMESPACE)
  143. } /* namespace pantheios */
  144. #endif /* !PANTHEIOS_NO_NAMESPACE */
  145. /* /////////////////////////////////////////////////////////////////////////
  146. * Inclusion
  147. */
  148. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  149. # pragma once
  150. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  151. /* ////////////////////////////////////////////////////////////////////// */
  152. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_HEX_PTR */
  153. /* ///////////////////////////// end of file //////////////////////////// */