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.

160 lines
4.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: stlsoft/util/trip_bool.hpp
  3. *
  4. * Purpose: Defines the stlsoft::trip_bool class template.
  5. *
  6. * Created: 22nd October 2006
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2006-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 stlsoft/util/trip_bool.hpp
  40. *
  41. * \brief [C++ only] Defines the stlsoft::trip_bool class template
  42. * (\ref group__library__utility "Utility" Library).
  43. */
  44. #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_TRIP_BOOL
  45. #define STLSOFT_INCL_STLSOFT_UTIL_HPP_TRIP_BOOL
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define STLSOFT_VER_STLSOFT_UTIL_HPP_TRIP_BOOL_MAJOR 1
  48. # define STLSOFT_VER_STLSOFT_UTIL_HPP_TRIP_BOOL_MINOR 0
  49. # define STLSOFT_VER_STLSOFT_UTIL_HPP_TRIP_BOOL_REVISION 2
  50. # define STLSOFT_VER_STLSOFT_UTIL_HPP_TRIP_BOOL_EDIT 8
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Auto-generation and compatibility
  54. */
  55. /* /////////////////////////////////////////////////////////////////////////
  56. * Includes
  57. */
  58. #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
  59. # include <stlsoft/stlsoft.h>
  60. #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Namespace
  63. */
  64. #ifndef _STLSOFT_NO_NAMESPACE
  65. namespace stlsoft
  66. {
  67. #endif /* _STLSOFT_NO_NAMESPACE */
  68. /** \brief
  69. *
  70. * \note This template was inspired by Bill Rubin's "Trip Switch Booleans in
  71. * C++" article in August 2006 issue of CVu.
  72. */
  73. template <ss_bool_t V>
  74. class trip_bool
  75. {
  76. /// \name Member Types and Constants
  77. /// @{
  78. public:
  79. /// \brief The value type
  80. typedef ss_bool_t value_type;
  81. /// \brief The current instantiation of the template
  82. typedef trip_bool<V> class_type;
  83. enum { value = V };
  84. /// @}
  85. /// \name Construction
  86. /// @{
  87. public:
  88. /// \brief Constructs an instance of the class
  89. ///
  90. /// \param v The initial value of the trip instance. Defaults to !V
  91. trip_bool(bool v = !V)
  92. : m_v(v)
  93. {}
  94. /// @}
  95. /// \name Accessors
  96. /// @{
  97. public:
  98. /// \brief
  99. operator value_type () const
  100. {
  101. return m_v;
  102. }
  103. /// @}
  104. /// \name Operations
  105. /// @{
  106. public:
  107. /// \brief
  108. void trip()
  109. {
  110. m_v = V;
  111. }
  112. /// @}
  113. /// \name Members
  114. /// @{
  115. private:
  116. value_type m_v;
  117. /// @}
  118. /// \name Not to be implemented
  119. /// @{
  120. private:
  121. class_type& operator =(class_type const&);
  122. /// @}
  123. };
  124. /* /////////////////////////////////////////////////////////////////////////
  125. * Unit-testing
  126. */
  127. #ifdef STLSOFT_UNITTEST
  128. # include "./unittest/trip_bool_unittest_.h"
  129. #endif /* STLSOFT_UNITTEST */
  130. /* ////////////////////////////////////////////////////////////////////// */
  131. #ifndef _STLSOFT_NO_NAMESPACE
  132. } // namespace stlsoft
  133. #endif /* _STLSOFT_NO_NAMESPACE */
  134. /* ////////////////////////////////////////////////////////////////////// */
  135. #endif /* !STLSOFT_INCL_STLSOFT_UTIL_HPP_TRIP_BOOL */
  136. /* ///////////////////////////// end of file //////////////////////////// */