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.

138 lines
4.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/inserters/xp.hpp
  3. *
  4. * Purpose: Defines shorthand name for pantheios::pointer inserter
  5. * class for inserting pointers in hexadecimal format.
  6. *
  7. * Created: 23rd 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/xp.hpp
  42. *
  43. * [C++ only] Defines shorthand name for pantheios::pointer inserter class
  44. * for inserting pointers in hexadecimal format.
  45. */
  46. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_XP
  47. #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_XP
  48. /* /////////////////////////////////////////////////////////////////////////
  49. * Version information
  50. */
  51. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  52. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_XP_MAJOR 1
  53. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_XP_MINOR 1
  54. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_XP_REVISION 1
  55. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_XP_EDIT 4
  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_POINTER
  64. # include <pantheios/inserters/pointer.hpp>
  65. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_POINTER */
  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 pointers in a hexadecimal format.
  77. */
  78. class xp
  79. : public pointer
  80. {
  81. public:
  82. /// The parent class type
  83. typedef pointer parent_class_type;
  84. /// This type
  85. typedef xp 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. // TODO: Add the 2 back in when pointer writing adjusted as integer was done in 1.0.1b197
  91. return /* 2 + */ int(2 * numBytes);
  92. }
  93. static int validate_width_(int width)
  94. {
  95. return width;
  96. }
  97. public:
  98. /// Construct from an unsigned long
  99. explicit xp(void const volatile* pv, int width = get_default_width_(sizeof(void*)))
  100. : parent_class_type(pv, validate_width_(width), int(fmt::fullHex))
  101. {}
  102. };
  103. /* /////////////////////////////////////////////////////////////////////////
  104. * Namespace
  105. */
  106. #if !defined(PANTHEIOS_NO_NAMESPACE)
  107. } /* namespace pantheios */
  108. #endif /* !PANTHEIOS_NO_NAMESPACE */
  109. /* /////////////////////////////////////////////////////////////////////////
  110. * Inclusion
  111. */
  112. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  113. # pragma once
  114. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  115. /* ////////////////////////////////////////////////////////////////////// */
  116. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_XP */
  117. /* ///////////////////////////// end of file //////////////////////////// */