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.

193 lines
7.1 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/filesystem/current_directory.hpp
  3. *
  4. * Purpose: Simple class that gets, and makes accessible, the current
  5. * directory.
  6. *
  7. * Created: 10th December 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/filesystem/current_directory.hpp
  41. *
  42. * \brief [C++ only] Definition of the winstl::basic_current_directory class template
  43. * (\ref group__library__filesystem "File System" Library).
  44. */
  45. #ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY
  46. #define WINSTL_INCL_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_MAJOR 4
  49. # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_MINOR 2
  50. # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_REVISION 1
  51. # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_EDIT 68
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Compatibility
  55. */
  56. /*
  57. [Incompatibilies-start]
  58. STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1200
  59. [Incompatibilies-end]
  60. */
  61. /* /////////////////////////////////////////////////////////////////////////
  62. * Includes
  63. */
  64. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  65. # include <winstl/winstl.h>
  66. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  67. #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SPECIAL_STRING_INSTANCE
  68. # include <stlsoft/string/special_string_instance.hpp>
  69. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SPECIAL_STRING_INSTANCE */
  70. #ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS
  71. # include <winstl/filesystem/filesystem_traits.hpp>
  72. #endif /* !WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS */
  73. #ifndef WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR
  74. # include <winstl/memory/processheap_allocator.hpp>
  75. #endif /* !WINSTL_INCL_WINSTL_MEMORY_HPP_PROCESSHEAP_ALLOCATOR */
  76. #if defined(STLSOFT_COMPILER_IS_BORLAND)
  77. // Borland is a bit of a thicky, and requires a (valid) spin_mutex_type
  78. # include <winstl/synch/spin_mutex.hpp>
  79. #endif /* compiler */
  80. /* /////////////////////////////////////////////////////////////////////////
  81. * Namespace
  82. */
  83. #ifndef _WINSTL_NO_NAMESPACE
  84. # if defined(_STLSOFT_NO_NAMESPACE) || \
  85. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  86. /* There is no stlsoft namespace, so must define ::winstl */
  87. namespace winstl
  88. {
  89. # else
  90. /* Define stlsoft::winstl_project */
  91. namespace stlsoft
  92. {
  93. namespace winstl_project
  94. {
  95. # endif /* _STLSOFT_NO_NAMESPACE */
  96. #endif /* !_WINSTL_NO_NAMESPACE */
  97. /* /////////////////////////////////////////////////////////////////////////
  98. * Classes
  99. */
  100. /** \brief \ref group__pattern__special_string_instance "Special String Instance"
  101. * policy template for eliciting the <b>current</b> directory.
  102. *
  103. * \ingroup group__library__system
  104. */
  105. template <ss_typename_param_k C>
  106. struct cwd_policy
  107. {
  108. typedef C char_type;
  109. typedef processheap_allocator<C> allocator_type;
  110. typedef ss_size_t size_type;
  111. typedef size_type (*pfn_type)(char_type *, size_type);
  112. #if defined(STLSOFT_COMPILER_IS_BORLAND)
  113. // Borland is a bit of a thicky, and requires a (valid) spin_mutex_type
  114. typedef winstl::spin_mutex spin_mutex_type;
  115. typedef winstl::atomic_int_t atomic_int_type;
  116. #endif /* compiler */
  117. enum { internalBufferSize = 128 };
  118. enum { allowImplicitConversion = 1 };
  119. enum { sharedState = 0 };
  120. static pfn_type get_fn()
  121. {
  122. return winstl::filesystem_traits<char_type>::get_current_directory;
  123. }
  124. };
  125. /* /////////////////////////////////////////////////////////////////////////
  126. * Typedefs for commonly encountered types
  127. */
  128. /** \brief A \ref group__pattern__special_string_instance "Special String Instance"
  129. * that represents the <b>current</b> directory; ANSI specialisation.
  130. *
  131. * \ingroup group__library__system
  132. */
  133. typedef stlsoft_ns_qual(special_string_instance_0)< cwd_policy<ws_char_a_t> > current_directory_a;
  134. /** \brief A \ref group__pattern__special_string_instance "Special String Instance"
  135. * that represents the <b>current</b> directory; 'Unicode' specialisation.
  136. *
  137. * \ingroup group__library__system
  138. */
  139. typedef stlsoft_ns_qual(special_string_instance_0)< cwd_policy<ws_char_w_t> > current_directory_w;
  140. /** \brief A \ref group__pattern__special_string_instance "Special String Instance"
  141. * that represents the <b>current</b> directory; TCHAR specialisation.
  142. *
  143. * \ingroup group__library__system
  144. */
  145. typedef stlsoft_ns_qual(special_string_instance_0)< cwd_policy<TCHAR> > current_directory;
  146. /* /////////////////////////////////////////////////////////////////////////
  147. * Unit-testing
  148. */
  149. #ifdef STLSOFT_UNITTEST
  150. # include "./unittest/current_directory_unittest_.h"
  151. #endif /* STLSOFT_UNITTEST */
  152. /* ////////////////////////////////////////////////////////////////////// */
  153. #ifndef _WINSTL_NO_NAMESPACE
  154. # if defined(_STLSOFT_NO_NAMESPACE) || \
  155. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  156. } // namespace winstl
  157. # else
  158. } // namespace winstl_project
  159. } // namespace stlsoft
  160. # endif /* _STLSOFT_NO_NAMESPACE */
  161. #endif /* !_WINSTL_NO_NAMESPACE */
  162. /* ////////////////////////////////////////////////////////////////////// */
  163. #endif /* WINSTL_INCL_WINSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY */
  164. /* ///////////////////////////// end of file //////////////////////////// */