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
5.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/severity/levels.hpp
  3. *
  4. * Purpose: Definition of the pantheios::level class template, which may
  5. * be used to generate levels pseudo-constants.
  6. *
  7. * Created: 22nd July 2006
  8. * Updated: 23rd July 2010
  9. *
  10. * Home: http://www.pantheios.org/
  11. *
  12. * Copyright (c) 2006-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/severity/levels.hpp
  42. *
  43. * [C++ only] Definition of the pantheios::level class template, which can
  44. * be used to generate levels pseudo-constants.
  45. */
  46. #ifndef PANTHEIOS_INCL_PANTHEIOS_SEVERITY_HPP_LEVELS
  47. #define PANTHEIOS_INCL_PANTHEIOS_SEVERITY_HPP_LEVELS
  48. /* /////////////////////////////////////////////////////////////////////////
  49. * Version information
  50. */
  51. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  52. # define PANTHEIOS_VER_PANTHEIOS_SEVERITY_HPP_LEVELS_MAJOR 2
  53. # define PANTHEIOS_VER_PANTHEIOS_SEVERITY_HPP_LEVELS_MINOR 0
  54. # define PANTHEIOS_VER_PANTHEIOS_SEVERITY_HPP_LEVELS_REVISION 2
  55. # define PANTHEIOS_VER_PANTHEIOS_SEVERITY_HPP_LEVELS_EDIT 23
  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_QUALITY_H_CONTRACT
  64. # include <pantheios/quality/contract.h>
  65. #endif /* !PANTHEIOS_INCL_PANTHEIOS_QUALITY_H_CONTRACT */
  66. /* /////////////////////////////////////////////////////////////////////////
  67. * Namespace
  68. */
  69. #if !defined(PANTHEIOS_NO_NAMESPACE)
  70. namespace pantheios
  71. {
  72. #endif /* !PANTHEIOS_NO_NAMESPACE */
  73. /* /////////////////////////////////////////////////////////////////////////
  74. * Classes
  75. */
  76. /** Class that acts as an integer value - indicating a severity
  77. * level - but which also facilitates the provision of 28-bits of
  78. * extended severity information.
  79. *
  80. * In normal use, the levels instances - pantheios::debug,
  81. * pantheios::informational ... pantheios::emergency - can be used in the
  82. * place of the pan_severity_t enumerators.
  83. *
  84. * \warning The levels values must not be used in the definition of a
  85. * front-end or back-end. This is because the levels values are static
  86. * instances, and will likely be in a race with the API Schwarz counter
  87. * (static) initialiser instances. It is likely that using one of the
  88. * levels values in that case will yield the value 0.
  89. */
  90. template <int Level>
  91. class level
  92. {
  93. /// \name Member Types
  94. /// @{
  95. public:
  96. typedef level<Level> class_type;
  97. /// @}
  98. /// \name Construction
  99. /// @{
  100. public:
  101. level()
  102. {}
  103. /// @}
  104. /// \name Operators
  105. /// @{
  106. public:
  107. /// Implicit conversion to the underlying level value
  108. operator pan_sev_t () const
  109. {
  110. return Level;
  111. }
  112. /// Function-call operator that allows extended severity information
  113. /// to be provided to the front-/back-ends
  114. ///
  115. /// \param extendedSeverityInformation28 28-bits of extended
  116. /// information to be included in the
  117. ///
  118. /// \pre 0 == (extendedSeverityInformation28 & ~0xf0000000)
  119. pan_sev_t operator ()(pan_sev_t extendedSeverityInformation28) const
  120. {
  121. PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_APPL_LAYER(extendedSeverityInformation28 < 0x10000000, "Extended severity information is limited to 28-bits");
  122. return (Level & 0x0f) | ((extendedSeverityInformation28 << 4) & ~0x0f);
  123. }
  124. /// @}
  125. /// \name Not to be implemented
  126. /// @{
  127. private:
  128. class_type& operator =(class_type const&);
  129. /// @}
  130. };
  131. /* /////////////////////////////////////////////////////////////////////////
  132. * Namespace
  133. */
  134. #if !defined(PANTHEIOS_NO_NAMESPACE)
  135. } /* namespace pantheios */
  136. #endif /* !PANTHEIOS_NO_NAMESPACE */
  137. /* ////////////////////////////////////////////////////////////////////// */
  138. #endif /* !PANTHEIOS_INCL_PANTHEIOS_SEVERITY_HPP_LEVELS */
  139. /* ///////////////////////////// end of file //////////////////////////// */