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.

363 lines
14 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: platformstl/filesystem/path.hpp
  3. *
  4. * Purpose: Platform header for the path components.
  5. *
  6. * Created: 20th March 2005
  7. * Updated: 21st November 2010
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2005-2010, 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 platformstl/filesystem/path.hpp
  40. *
  41. * \brief [C++ only] Definition of the platformstl::basic_path
  42. * type
  43. * (\ref group__library__filesystem "File System" Library).
  44. */
  45. #ifndef PLATFORMSTL_INCL_PLATFORMSTL_FILESYSTEM_HPP_PATH
  46. #define PLATFORMSTL_INCL_PLATFORMSTL_FILESYSTEM_HPP_PATH
  47. /* File version */
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define PLATFORMSTL_VER_PLATFORMSTL_FILESYSTEM_HPP_PATH_MAJOR 2
  50. # define PLATFORMSTL_VER_PLATFORMSTL_FILESYSTEM_HPP_PATH_MINOR 2
  51. # define PLATFORMSTL_VER_PLATFORMSTL_FILESYSTEM_HPP_PATH_REVISION 1
  52. # define PLATFORMSTL_VER_PLATFORMSTL_FILESYSTEM_HPP_PATH_EDIT 29
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef PLATFORMSTL_INCL_PLATFORMSTL_FILESYSTEM_HPP_PLATFORMSTL
  58. # include <platformstl/platformstl.hpp>
  59. #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_FILESYSTEM_HPP_PLATFORMSTL */
  60. #if defined(PLATFORMSTL_OS_IS_UNIX)
  61. # ifndef UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_PATH
  62. # include <unixstl/filesystem/path.hpp>
  63. # endif /* !UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_PATH */
  64. #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  65. # ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_PATH
  66. # include <winstl/filesystem/path.hpp>
  67. # endif /* !WINSTL_INCL_WINSTL_FILESYSTEM_HPP_PATH */
  68. #else /* ? operating system */
  69. # error Operating system not discriminated
  70. #endif /* operating system */
  71. /* /////////////////////////////////////////////////////////////////////////
  72. * Namespace
  73. */
  74. #if defined(_STLSOFT_NO_NAMESPACE) || \
  75. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  76. /* There is no stlsoft namespace, so must define ::platformstl */
  77. namespace platformstl
  78. {
  79. #else
  80. /* Define stlsoft::platformstl_project */
  81. namespace stlsoft
  82. {
  83. namespace platformstl_project
  84. {
  85. #endif /* _STLSOFT_NO_NAMESPACE */
  86. /* ////////////////////////////////////////////////////////////////////// */
  87. #if defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  88. /** \brief Class used for composing and decomposing file-system paths.
  89. *
  90. * \ingroup group__library__filesystem
  91. *
  92. * The class is not actually defined in the
  93. * \link ::platformstl platformstl\endlink namespace. Rather, it
  94. * resolves to the appropriate type for the given platform, relying on
  95. * \ref section__principle__conformance__intersecting_conformance "Intersecting Conformance"
  96. * of the resolved platform-specific types.
  97. *
  98. * When compiling on UNIX platforms, the platformstl::basic_path
  99. * type resolves to the unixstl::basic_path class. On Windows
  100. * platforms it resolves to the winstl::basic_path class. It
  101. * is not defined for other platforms.
  102. */
  103. template< ss_typename_param_k C
  104. , ss_typename_param_k T = filesystem_traits<C>
  105. , ss_typename_param_k A = ss_typename_type_def_k stlsoft::allocator_selector<C>::allocator_type
  106. >
  107. class basic_path
  108. {};
  109. /// \brief Specialisation of the basic_path template for the ANSI character type \c char
  110. typedef basic_path<char, filesystem_traits<char> > path_a;
  111. /// \brief Specialisation of the basic_path template for the Unicode character type \c wchar_t
  112. typedef basic_path<wchar_t, filesystem_traits<wchar_t> > path_w;
  113. /// \brief Specialisation of the basic_path template for the ANSI character type \c char on UNIX, and for the \c TCHAR type on Windows
  114. typedef basic_path<tchar, filesystem_traits<tchar> > path;
  115. #elif defined(PLATFORMSTL_OS_IS_UNIX)
  116. // Because early incarnations of Visual C++ are pretty stupid, we need to
  117. // work around their inability to introduce a template via using by
  118. // defining and deriving here
  119. //
  120. // This one required an *extra* degree of trickery, by defining a derivation
  121. // of unixstl::basic_path _within_ unixstl, in the form of
  122. // basic_path__, and then deriving from that. If we just try and
  123. // derive from unixstl::basic_path directly, the compiler gets
  124. // confused between the unixstl one and the local one, and fails and says that
  125. // it cannot derive from itself (which happens to be incomplete).
  126. # if defined(STLSOFT_COMPILER_IS_MSVC) && \
  127. _MSC_VER < 1310
  128. template< ss_typename_param_k C
  129. # ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
  130. , ss_typename_param_k T = unixstl_ns_qual(filesystem_traits)<C>
  131. , ss_typename_param_k A = ss_typename_type_def_k stlsoft::allocator_selector<C>::allocator_type
  132. # else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  133. , ss_typename_param_k T /* = filesystem_traits<C> */
  134. , ss_typename_param_k A /* = processheap_allocator<C> */
  135. # endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  136. >
  137. class basic_path
  138. : public unixstl_ns_qual(basic_path__)<C, T, A>
  139. {
  140. private:
  141. typedef unixstl_ns_qual(basic_path__)<C, T, A> parent_class_type;
  142. typedef basic_path<C, T, A> class_type;
  143. public:
  144. typedef ss_typename_type_k parent_class_type::char_type char_type;
  145. typedef ss_typename_type_k parent_class_type::traits_type traits_type;
  146. typedef ss_typename_type_k parent_class_type::allocator_type allocator_type;
  147. typedef ss_typename_type_k parent_class_type::size_type size_type;
  148. public:
  149. basic_path()
  150. : parent_class_type()
  151. {}
  152. ss_explicit_k basic_path(char_type const* path)
  153. : parent_class_type(path)
  154. {}
  155. basic_path(parent_class_type const& s)
  156. : parent_class_type(s)
  157. {}
  158. # ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  159. /// Constructs a path from \c path
  160. template<ss_typename_param_k S>
  161. basic_path(S const& s)
  162. : parent_class_type(s)
  163. {}
  164. # endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  165. basic_path(char_type const* path, size_type cch)
  166. : parent_class_type(path, cch)
  167. {}
  168. basic_path(class_type const& rhs)
  169. : parent_class_type(rhs)
  170. {}
  171. class_type& operator =(class_type const& rhs)
  172. {
  173. parent_class_type::operator =(rhs);
  174. return *this;
  175. }
  176. class_type& operator =(parent_class_type const& rhs)
  177. {
  178. parent_class_type::operator =(rhs);
  179. return *this;
  180. }
  181. class_type& operator =(char_type const* rhs)
  182. {
  183. parent_class_type::operator =(rhs);
  184. return *this;
  185. }
  186. # ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  187. template<ss_typename_param_k S>
  188. class_type& operator =(S const& s)
  189. {
  190. parent_class_type::operator =(s);
  191. return *this;
  192. }
  193. # endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
  194. };
  195. typedef basic_path<ss_char_a_t, unixstl_ns_qual(filesystem_traits)<ss_char_a_t> > path_a;
  196. typedef basic_path<ss_char_w_t, unixstl_ns_qual(filesystem_traits)<ss_char_w_t> > path_w;
  197. typedef basic_path<ss_char_a_t, unixstl_ns_qual(filesystem_traits)<ss_char_a_t> > path;
  198. # else /* ? compiler */
  199. # ifdef _UNIXSTL_NO_NAMESPACE
  200. using ::basic_path;
  201. # else /* ? _UNIXSTL_NO_NAMESPACE */
  202. using ::unixstl::basic_path;
  203. using ::unixstl::path_a;
  204. using ::unixstl::path_w;
  205. using ::unixstl::path;
  206. # endif /* _UNIXSTL_NO_NAMESPACE */
  207. # endif /* compiler */
  208. #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  209. // Because early incarnations of Visual C++ are pretty stupid, we need to
  210. // work around their inability to introduce a template via using by
  211. // defining and deriving here
  212. //
  213. // This one required an *extra* degree of trickery, by defining a derivation
  214. // of winstl::basic_path _within_ winstl, in the form of
  215. // basic_path__, and then deriving from that. If we just try and
  216. // derive from winstl::basic_path directly, the compiler gets
  217. // confused between the winstl one and the local one, and fails and says that
  218. // it cannot derive from itself (which happens to be incomplete).
  219. # if defined(STLSOFT_COMPILER_IS_MSVC) && \
  220. _MSC_VER < 1310
  221. template< ss_typename_param_k C
  222. # ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
  223. , ss_typename_param_k T = winstl_ns_qual(filesystem_traits)<C>
  224. , ss_typename_param_k A = winstl_ns_qual(processheap_allocator)<C>
  225. # else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  226. , ss_typename_param_k T /* = filesystem_traits<C> */
  227. , ss_typename_param_k A /* = processheap_allocator<C> */
  228. # endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  229. >
  230. class basic_path
  231. : public winstl_ns_qual(basic_path__)<C, T, A>
  232. {
  233. private:
  234. typedef winstl_ns_qual(basic_path__)<C, T, A> parent_class_type;
  235. typedef basic_path<C, T, A> class_type;
  236. public:
  237. typedef ss_typename_type_k parent_class_type::char_type char_type;
  238. typedef ss_typename_type_k parent_class_type::traits_type traits_type;
  239. typedef ss_typename_type_k parent_class_type::allocator_type allocator_type;
  240. typedef ss_typename_type_k parent_class_type::size_type size_type;
  241. public:
  242. basic_path()
  243. : parent_class_type()
  244. {}
  245. ss_explicit_k basic_path(char_type const* path)
  246. : parent_class_type(path)
  247. {}
  248. basic_path(parent_class_type const& s)
  249. : parent_class_type(s)
  250. {}
  251. # ifdef STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
  252. /// Constructs a path from \c path
  253. template<ss_typename_param_k S>
  254. basic_path(S const& s)
  255. : parent_class_type(s)
  256. {}
  257. # endif /* STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT */
  258. basic_path(char_type const* path, size_type cch)
  259. : parent_class_type(path, cch)
  260. {}
  261. basic_path(class_type const& rhs)
  262. : parent_class_type(rhs)
  263. {}
  264. class_type& operator =(class_type const& rhs)
  265. {
  266. parent_class_type::operator =(rhs);
  267. return *this;
  268. }
  269. class_type& operator =(parent_class_type const& rhs)
  270. {
  271. parent_class_type::operator =(rhs);
  272. return *this;
  273. }
  274. class_type& operator =(char_type const* rhs)
  275. {
  276. parent_class_type::operator =(rhs);
  277. return *this;
  278. }
  279. # ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
  280. template<ss_typename_param_k S>
  281. class_type& operator =(S const& s)
  282. {
  283. parent_class_type::operator =(s);
  284. return *this;
  285. }
  286. # endif /* STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
  287. };
  288. typedef basic_path<ss_char_a_t, winstl_ns_qual(filesystem_traits)<ss_char_a_t> > path_a;
  289. typedef basic_path<ss_char_w_t, winstl_ns_qual(filesystem_traits)<ss_char_w_t> > path_w;
  290. typedef basic_path<TCHAR, winstl_ns_qual(filesystem_traits)<TCHAR > > path;
  291. # else /* ? compiler */
  292. # ifdef _WINSTL_NO_NAMESPACE
  293. using ::basic_path;
  294. # else /* ? _WINSTL_NO_NAMESPACE */
  295. using ::winstl::basic_path;
  296. using ::winstl::path_a;
  297. using ::winstl::path_w;
  298. using ::winstl::path;
  299. # endif /* _WINSTL_NO_NAMESPACE */
  300. # endif /* compiler */
  301. #else /* ? operating system */
  302. # error Operating system not discriminated
  303. #endif /* operating system */
  304. /* ////////////////////////////////////////////////////////////////////// */
  305. #if defined(_STLSOFT_NO_NAMESPACE) || \
  306. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  307. } // namespace platformstl
  308. #else
  309. } // namespace platformstl_project
  310. } // namespace stlsoft
  311. #endif /* _STLSOFT_NO_NAMESPACE */
  312. /* ////////////////////////////////////////////////////////////////////// */
  313. #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_FILESYSTEM_HPP_PATH */
  314. /* ///////////////////////////// end of file //////////////////////////// */