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.

166 lines
5.5 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/inserters/variant_bool.hpp
  3. *
  4. * Purpose: String inserter for booleans.
  5. *
  6. * Created: 18th June 2012
  7. * Updated: 18th June 2012
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 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/variant_bool.hpp
  41. *
  42. * [C++ only] String inserter for booleans.
  43. */
  44. #ifndef PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_VARIANT_BOOL
  45. #define PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_VARIANT_BOOL
  46. /* /////////////////////////////////////////////////////////////////////////
  47. * Version information
  48. */
  49. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  50. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_VARIANT_BOOL_MAJOR 1
  51. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_VARIANT_BOOL_MINOR 0
  52. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_VARIANT_BOOL_REVISION 1
  53. # define PANTHEIOS_VER_PANTHEIOS_INSERTERS_HPP_VARIANT_BOOL_EDIT 1
  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_BOOLEAN
  62. # include <pantheios/inserters/boolean.hpp>
  63. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_BOOLEAN */
  64. /* /////////////////////////////////////////////////////////////////////////
  65. * Namespace
  66. */
  67. #if !defined(PANTHEIOS_NO_NAMESPACE)
  68. namespace pantheios
  69. {
  70. #else /* ? !PANTHEIOS_NO_NAMESPACE */
  71. # if defined(__RPCNDR_H__)
  72. # error pantheios::variant_bool may not be used with Windows when namespace is suspended. If you are including pantheios/inserters.hpp, try including only those specific inserter files that you need
  73. # endif /* rpcndr.h */
  74. #endif /* !PANTHEIOS_NO_NAMESPACE */
  75. /* /////////////////////////////////////////////////////////////////////////
  76. * Classes
  77. */
  78. /** Class for inserting VARIANT_BOOL variables into Pantheios diagnostic
  79. * logging statements.
  80. *
  81. * \ingroup group__application_layer_interface__inserters
  82. *
  83. * Consider the following statement:
  84. *
  85. * \code
  86. char s[] = "abc";
  87. std::string str("def");
  88. VARIANT_BOOL b = VARIANT_FALSE;
  89. pantheios::log(pantheios::notice, "s=", s, ", b=", pantheios::variant_bool(b), ", str=", str);
  90. * \endcode
  91. *
  92. * This will produce the output:
  93. *
  94. * &nbsp;&nbsp;&nbsp;&nbsp;<b>s=abc, b=false, str=def</b>
  95. *
  96. * \note The class provides the static method set_value_strings() for
  97. * assigning user-defined strings to represent true and false values.
  98. */
  99. class variant_bool
  100. : public boolean
  101. {
  102. /// \name Member Types
  103. /// @{
  104. public:
  105. typedef boolean parent_class_type;
  106. typedef variant_bool class_type;
  107. /// @}
  108. /// \name Construction
  109. /// @{
  110. public:
  111. /// Construct from a variant_bool value
  112. ///
  113. /// \param value The variant_bool whose value will be represented as a string
  114. explicit variant_bool(VARIANT_BOOL value)
  115. : parent_class_type(VARIANT_FALSE != value)
  116. {}
  117. private:
  118. class_type& operator =(class_type const&);
  119. /// @}
  120. /// \name Implementation
  121. /// @{
  122. public:
  123. virtual
  124. pan_slice_t const* get_slice_(bool value) const
  125. {
  126. return boolean::get_slice_(1, value);
  127. }
  128. /// @}
  129. };
  130. /* /////////////////////////////////////////////////////////////////////////
  131. * Namespace
  132. */
  133. #if !defined(PANTHEIOS_NO_NAMESPACE)
  134. } /* namespace pantheios */
  135. #endif /* !PANTHEIOS_NO_NAMESPACE */
  136. /* /////////////////////////////////////////////////////////////////////////
  137. * Inclusion
  138. */
  139. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  140. # pragma once
  141. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  142. /* ////////////////////////////////////////////////////////////////////// */
  143. #endif /* !PANTHEIOS_INCL_PANTHEIOS_INSERTERS_HPP_VARIANT_BOOL */
  144. /* ///////////////////////////// end of file //////////////////////////// */