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.

174 lines
6.4 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: unixstl/filesystem/current_directory.hpp
  3. *
  4. * Purpose: Definition of the current_directory class.
  5. *
  6. * Created: 1st November 2003
  7. * Updated: 10th August 2009
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2003-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 unixstl/filesystem/current_directory.hpp
  40. *
  41. * \brief [C++ only] Definition of the unixstl::basic_current_directory
  42. * class template
  43. * (\ref group__library__filesystem "File System" Library).
  44. */
  45. #ifndef UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY
  46. #define UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY
  47. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  48. # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_MAJOR 4
  49. # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_MINOR 1
  50. # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_REVISION 2
  51. # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY_EDIT 52
  52. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  53. /* /////////////////////////////////////////////////////////////////////////
  54. * Includes
  55. */
  56. #ifndef UNIXSTL_INCL_UNIXSTL_H_UNIXSTL
  57. # include <unixstl/unixstl.h>
  58. #endif /* !UNIXSTL_INCL_UNIXSTL_H_UNIXSTL */
  59. #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SPECIAL_STRING_INSTANCE
  60. # include <stlsoft/string/special_string_instance.hpp>
  61. #endif /* !STLSOFT_INCL_STLSOFT_STRING_HPP_SPECIAL_STRING_INSTANCE */
  62. #ifndef UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS
  63. # include <unixstl/filesystem/filesystem_traits.hpp>
  64. #endif /* !UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS */
  65. #ifdef STLSOFT_UNITTEST
  66. # include <unixstl/filesystem/file_path_buffer.hpp>
  67. #endif /* STLSOFT_UNITTEST */
  68. /* /////////////////////////////////////////////////////////////////////////
  69. * Namespace
  70. */
  71. #ifndef _UNIXSTL_NO_NAMESPACE
  72. # if defined(_STLSOFT_NO_NAMESPACE) || \
  73. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  74. /* There is no stlsoft namespace, so must define ::unixstl */
  75. namespace unixstl
  76. {
  77. # else
  78. /* Define stlsoft::unixstl_project */
  79. namespace stlsoft
  80. {
  81. namespace unixstl_project
  82. {
  83. # endif /* _STLSOFT_NO_NAMESPACE */
  84. #endif /* !_UNIXSTL_NO_NAMESPACE */
  85. /* /////////////////////////////////////////////////////////////////////////
  86. * Classes
  87. */
  88. /** \brief \ref group__pattern__special_string_instance "Special String Instance"
  89. * policy template for eliciting the <b>current</b> directory.
  90. *
  91. * \ingroup group__library__system
  92. */
  93. template <ss_typename_param_k C>
  94. struct cwd_policy
  95. {
  96. typedef C char_type;
  97. typedef void allocator_type;
  98. typedef ss_size_t size_type;
  99. typedef size_type (*pfn_type)(char_type *, size_type);
  100. enum { internalBufferSize = 128 };
  101. enum { allowImplicitConversion = 1 };
  102. enum { sharedState = 0 };
  103. static pfn_type get_fn()
  104. {
  105. return unixstl::filesystem_traits<char_type>::get_current_directory;
  106. }
  107. };
  108. /* /////////////////////////////////////////////////////////////////////////
  109. * Typedefs for commonly encountered types
  110. */
  111. /** \brief A \ref group__pattern__special_string_instance "Special String Instance"
  112. * that represents the <b>current</b> directory; ANSI specialisation.
  113. *
  114. * \ingroup group__library__system
  115. */
  116. typedef stlsoft_ns_qual(special_string_instance_0)< cwd_policy<us_char_a_t> > current_directory_a;
  117. /** \brief A \ref group__pattern__special_string_instance "Special String Instance"
  118. * that represents the <b>current</b> directory; 'Unicode' specialisation.
  119. *
  120. * \ingroup group__library__system
  121. */
  122. typedef stlsoft_ns_qual(special_string_instance_0)< cwd_policy<us_char_w_t> > current_directory_w;
  123. /** \brief A \ref group__pattern__special_string_instance "Special String Instance"
  124. * that represents the <b>current</b> directory; char specialisation.
  125. *
  126. * \ingroup group__library__system
  127. */
  128. typedef stlsoft_ns_qual(special_string_instance_0)< cwd_policy<char> > current_directory;
  129. /* /////////////////////////////////////////////////////////////////////////
  130. * Unit-testing
  131. */
  132. #ifdef STLSOFT_UNITTEST
  133. # include "./unittest/current_directory_unittest_.h"
  134. #endif /* STLSOFT_UNITTEST */
  135. /* ////////////////////////////////////////////////////////////////////// */
  136. #ifndef _UNIXSTL_NO_NAMESPACE
  137. # if defined(_STLSOFT_NO_NAMESPACE) || \
  138. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  139. } // namespace unixstl
  140. # else
  141. } // namespace unixstl_project
  142. } // namespace stlsoft
  143. # endif /* _STLSOFT_NO_NAMESPACE */
  144. #endif /* !_UNIXSTL_NO_NAMESPACE */
  145. /* ////////////////////////////////////////////////////////////////////// */
  146. #endif /* UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_CURRENT_DIRECTORY */
  147. /* ///////////////////////////// end of file //////////////////////////// */