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.

213 lines
7.4 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/system/module_filename.hpp (originally MWModFNm.h; ::SynesisWin)
  3. *
  4. * Purpose: Preposterously simple class that gets, and makes accessible, the
  5. * module filename.
  6. *
  7. * Created: 31st March 2002
  8. * Updated: 12th August 2010
  9. *
  10. * Home: http://stlsoft.org/
  11. *
  12. * Copyright (c) 2002-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 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/system/module_filename.hpp
  41. *
  42. * \brief [C++ only] Definition of the winstl::basic_module_filename class
  43. * template
  44. * (\ref group__library__system "System" Library).
  45. */
  46. #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_MODULE_FILENAME
  47. #define WINSTL_INCL_WINSTL_SYSTEM_HPP_MODULE_FILENAME
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define WINSTL_VER_WINSTL_SYSTEM_HPP_MODULE_FILENAME_MAJOR 4
  50. # define WINSTL_VER_WINSTL_SYSTEM_HPP_MODULE_FILENAME_MINOR 2
  51. # define WINSTL_VER_WINSTL_SYSTEM_HPP_MODULE_FILENAME_REVISION 1
  52. # define WINSTL_VER_WINSTL_SYSTEM_HPP_MODULE_FILENAME_EDIT 73
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Compatibility
  56. */
  57. /*
  58. [Incompatibilies-start]
  59. STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1200
  60. [Incompatibilies-end]
  61. */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Includes
  64. */
  65. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  66. # include <winstl/winstl.h>
  67. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  68. #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SPECIAL_STRING_INSTANCE
  69. # include <stlsoft/string/special_string_instance.hpp>
  70. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SPECIAL_STRING_INSTANCE */
  71. #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
  72. # include <winstl/memory/processheap_allocator.hpp>
  73. #endif /* !WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR */
  74. #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS
  75. # include <winstl/system/system_traits.hpp>
  76. #endif /* !WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS */
  77. #if defined(STLSOFT_COMPILER_IS_BORLAND)
  78. // Borland is a bit of a thicky, and requires a (valid) spin_mutex_type
  79. # include <winstl/synch/spin_mutex.hpp>
  80. #endif /* compiler */
  81. /* /////////////////////////////////////////////////////////////////////////
  82. * Namespace
  83. */
  84. #ifndef _WINSTL_NO_NAMESPACE
  85. # if defined(_STLSOFT_NO_NAMESPACE) || \
  86. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  87. /* There is no stlsoft namespace, so must define ::winstl */
  88. namespace winstl
  89. {
  90. # else
  91. /* Define stlsoft::winstl_project */
  92. namespace stlsoft
  93. {
  94. namespace winstl_project
  95. {
  96. # endif /* _STLSOFT_NO_NAMESPACE */
  97. #endif /* !_WINSTL_NO_NAMESPACE */
  98. /* /////////////////////////////////////////////////////////////////////////
  99. * basic_module_filename
  100. *
  101. * This class wraps the GetModuleFilename() API function, and effectively acts
  102. * as an adaptor between HINSTANCE and a C-string to the name.
  103. */
  104. /** \brief Represents a module filename
  105. *
  106. * \ingroup group__library__system
  107. *
  108. * \param C The character type
  109. * \param T The traits type. On translators that support default template arguments, this defaults to filesystem_traits<C>
  110. */
  111. template <ss_typename_param_k C>
  112. struct modfname_policy
  113. {
  114. /// \name Member Types
  115. /// @{
  116. public:
  117. typedef C char_type;
  118. typedef HINSTANCE argument_0_type;
  119. typedef processheap_allocator<C> allocator_type;
  120. typedef ws_size_t size_type;
  121. typedef size_type (*pfn_type)(argument_0_type, char_type *, size_type);
  122. #if defined(STLSOFT_COMPILER_IS_BORLAND)
  123. // Borland is a bit of a thicky, and requires a (valid) spin_mutex_type
  124. typedef winstl::spin_mutex spin_mutex_type;
  125. typedef winstl::atomic_int_t atomic_int_type;
  126. #endif /* compiler */
  127. /// @}
  128. /// \name Member Constants
  129. /// @{
  130. public:
  131. enum { internalBufferSize = 128 };
  132. enum { allowImplicitConversion = 1 };
  133. enum { sharedState = 0 };
  134. /// @}
  135. /// \name Operations
  136. /// @{
  137. public:
  138. static pfn_type get_fn()
  139. {
  140. return winstl::system_traits<char_type>::get_module_filename;
  141. }
  142. /// @}
  143. };
  144. /* /////////////////////////////////////////////////////////////////////////
  145. * Typedefs for commonly encountered types
  146. */
  147. /** \brief A \ref group__pattern__special_string_instance "Special String Instance"
  148. * that represents the <b>module</b> directory; ANSI specialisation.
  149. *
  150. * \ingroup group__library__system
  151. */
  152. typedef stlsoft_ns_qual(special_string_instance_1)<modfname_policy<ws_char_a_t> > module_filename_a;
  153. /** \brief A \ref group__pattern__special_string_instance "Special String Instance"
  154. * that represents the <b>module</b> directory; 'Unicode' specialisation.
  155. *
  156. * \ingroup group__library__system
  157. */
  158. typedef stlsoft_ns_qual(special_string_instance_1)<modfname_policy<ws_char_w_t> > module_filename_w;
  159. /** \brief A \ref group__pattern__special_string_instance "Special String Instance"
  160. * that represents the <b>module</b> directory; TCHAR specialisation.
  161. *
  162. * \ingroup group__library__system
  163. */
  164. typedef stlsoft_ns_qual(special_string_instance_1)<modfname_policy<TCHAR> > module_filename;
  165. /* //////////////////////////////////////////////////////////////////////////
  166. * Unit-testing
  167. */
  168. #ifdef STLSOFT_UNITTEST
  169. # include "./unittest/module_filename_unittest_.h"
  170. #endif /* STLSOFT_UNITTEST */
  171. /* ////////////////////////////////////////////////////////////////////// */
  172. #ifndef _WINSTL_NO_NAMESPACE
  173. # if defined(_STLSOFT_NO_NAMESPACE) || \
  174. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  175. } // namespace winstl
  176. # else
  177. } // namespace winstl_project
  178. } // namespace stlsoft
  179. # endif /* _STLSOFT_NO_NAMESPACE */
  180. #endif /* !_WINSTL_NO_NAMESPACE */
  181. /* ////////////////////////////////////////////////////////////////////// */
  182. #endif /* WINSTL_INCL_WINSTL_SYSTEM_HPP_MODULE_FILENAME */
  183. /* ///////////////////////////// end of file //////////////////////////// */