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.

175 lines
5.4 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/conversion/resource_id.hpp
  3. *
  4. * Purpose: Shim type for conversion between integer and c-string resource
  5. * identifiers.
  6. *
  7. * Created: 11th April 2005
  8. * Updated: 10th August 2009
  9. *
  10. * Home: http://stlsoft.org/
  11. *
  12. * Copyright (c) 2005-2009, 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 met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice, this
  19. * list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  24. * any contributors may be used to endorse or promote products derived from
  25. * this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file winstl/conversion/resource_id.hpp
  41. *
  42. * \brief [C++ only] Definition of the winstl::resource_id class
  43. * (\ref group__library__conversion "Conversion" Library).
  44. */
  45. #ifndef WINSTL_INCL_WINSTL_CONVERSION_HPP_RESOURCE_ID
  46. #define WINSTL_INCL_WINSTL_CONVERSION_HPP_RESOURCE_ID
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define WINSTL_VER_WINSTL_CONVERSION_HPP_RESOURCE_ID_MAJOR 2
  49. # define WINSTL_VER_WINSTL_CONVERSION_HPP_RESOURCE_ID_MINOR 0
  50. # define WINSTL_VER_WINSTL_CONVERSION_HPP_RESOURCE_ID_REVISION 1
  51. # define WINSTL_VER_WINSTL_CONVERSION_HPP_RESOURCE_ID_EDIT 15
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  57. # include <winstl/winstl.h>
  58. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  59. /* /////////////////////////////////////////////////////////////////////////
  60. * Namespace
  61. */
  62. #ifndef _WINSTL_NO_NAMESPACE
  63. # if defined(_STLSOFT_NO_NAMESPACE) || \
  64. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  65. /* There is no stlsoft namespace, so must define ::winstl */
  66. namespace winstl
  67. {
  68. # else
  69. /* Define stlsoft::winstl_project */
  70. namespace stlsoft
  71. {
  72. namespace winstl_project
  73. {
  74. # endif /* _STLSOFT_NO_NAMESPACE */
  75. #endif /* !_WINSTL_NO_NAMESPACE */
  76. /* /////////////////////////////////////////////////////////////////////////
  77. * Classes
  78. */
  79. /** \brief Shim type for conversion between integer and c-string resource
  80. * identifiers.
  81. *
  82. * \ingroup group__library__conversion
  83. */
  84. template <ss_typename_param_k C>
  85. union basic_resource_id
  86. {
  87. /// \name Member Types
  88. /// @{
  89. public:
  90. typedef C char_type;
  91. typedef basic_resource_id<C> class_type;
  92. /// @}
  93. /// \name Construction
  94. /// @{
  95. public:
  96. /// \brief Construct from a resource Id
  97. ss_explicit_k basic_resource_id(int id)
  98. : m_id(id)
  99. {}
  100. /// \brief Constructs from a resource name
  101. ss_explicit_k basic_resource_id(C const* name)
  102. : m_name(name)
  103. {}
  104. /// @}
  105. /// \name Operators
  106. /// @{
  107. public:
  108. operator int() const
  109. {
  110. return m_id;
  111. }
  112. operator char_type const* () const
  113. {
  114. return m_name;
  115. }
  116. /// @}
  117. /// \name Members
  118. /// @{
  119. private:
  120. int m_id;
  121. char_type const* m_name;
  122. /// @}
  123. };
  124. /* ////////////////////////////////////////////////////////////////////// */
  125. /** \brief Specialisation for use with the ANSI \c char type.
  126. *
  127. * \ingroup group__library__conversion
  128. */
  129. typedef basic_resource_id<ws_char_a_t> resource_id_a;
  130. /** \brief Specialisation for use with the Unicode \c wchar_t type.
  131. *
  132. * \ingroup group__library__conversion
  133. */
  134. typedef basic_resource_id<ws_char_w_t> resource_id_w;
  135. /** \brief Specialisation for use with the Windows \c TCHAR type.
  136. *
  137. * \ingroup group__library__conversion
  138. */
  139. typedef basic_resource_id<TCHAR> resource_id;
  140. /* ////////////////////////////////////////////////////////////////////// */
  141. #ifndef _WINSTL_NO_NAMESPACE
  142. # if defined(_STLSOFT_NO_NAMESPACE) || \
  143. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  144. } // namespace winstl
  145. # else
  146. } // namespace winstl_project
  147. } // namespace stlsoft
  148. # endif /* _STLSOFT_NO_NAMESPACE */
  149. #endif /* !_WINSTL_NO_NAMESPACE */
  150. /* ////////////////////////////////////////////////////////////////////// */
  151. #endif /* WINSTL_INCL_WINSTL_CONVERSION_HPP_RESOURCE_ID */
  152. /* ///////////////////////////// end of file //////////////////////////// */