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.

400 lines
12 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: unixstl/shims/access/string/dirent.hpp
  3. *
  4. * Purpose: Support for the STLSoft string access shims for UNIX types.
  5. *
  6. * Created: 11th January 2003
  7. * Updated: 10th August 2009
  8. *
  9. * Thanks: To Carlos Santander Bernal, for providing feedback for Mac
  10. * builds
  11. *
  12. * Home: http://stlsoft.org/
  13. *
  14. * Copyright (c) 2003-2009, Matthew Wilson and Synesis Software
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without
  18. * modification, are permitted provided that the following conditions are met:
  19. *
  20. * - Redistributions of source code must retain the above copyright notice, this
  21. * list of conditions and the following disclaimer.
  22. * - Redistributions in binary form must reproduce the above copyright notice,
  23. * this list of conditions and the following disclaimer in the documentation
  24. * and/or other materials provided with the distribution.
  25. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  26. * any contributors may be used to endorse or promote products derived from
  27. * this software without specific prior written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  30. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  33. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  34. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  36. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  37. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  38. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. * ////////////////////////////////////////////////////////////////////// */
  42. /** \file unixstl/shims/access/string/dirent.hpp
  43. *
  44. * \brief [C++] Definition of the string access shims for
  45. * <code>struct dirent</code>
  46. * (\ref group__concept__shim__string_access "String Access Shims" Concept).
  47. */
  48. #ifndef UNIXSTL_INCL_UNIXSTL_SHIMS_ACCESS_STRING_HPP_DIRENT
  49. #define UNIXSTL_INCL_UNIXSTL_SHIMS_ACCESS_STRING_HPP_DIRENT
  50. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  51. # define UNIXSTL_VER_UNIXSTL_SHIMS_ACCESS_STRING_HPP_DIRENT_MAJOR 4
  52. # define UNIXSTL_VER_UNIXSTL_SHIMS_ACCESS_STRING_HPP_DIRENT_MINOR 0
  53. # define UNIXSTL_VER_UNIXSTL_SHIMS_ACCESS_STRING_HPP_DIRENT_REVISION 2
  54. # define UNIXSTL_VER_UNIXSTL_SHIMS_ACCESS_STRING_HPP_DIRENT_EDIT 56
  55. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  56. /* /////////////////////////////////////////////////////////////////////////
  57. * Includes
  58. */
  59. #ifndef UNIXSTL_INCL_UNIXSTL_H_UNIXSTL
  60. # include <unixstl/unixstl.h>
  61. #endif /* !UNIXSTL_INCL_UNIXSTL_H_UNIXSTL */
  62. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD
  63. # include <stlsoft/shims/access/string/fwd.h>
  64. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_H_FWD */
  65. #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_STD_H_C_STRING
  66. # include <stlsoft/shims/access/string/std/c_string.h>
  67. #endif /* !STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_STRING_STD_H_C_STRING */
  68. #ifndef STLSOFT_INCL_H_DIRENT
  69. # define STLSOFT_INCL_H_DIRENT
  70. # include <dirent.h>
  71. #endif /* !STLSOFT_INCL_H_DIRENT */
  72. /* /////////////////////////////////////////////////////////////////////////
  73. * Namespace
  74. */
  75. #ifndef _UNIXSTL_NO_NAMESPACE
  76. # if defined(_STLSOFT_NO_NAMESPACE) || \
  77. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  78. /* There is no stlsoft namespace, so must define ::unixstl */
  79. namespace unixstl
  80. {
  81. # else
  82. /* Define stlsoft::unixstl_project */
  83. namespace stlsoft
  84. {
  85. namespace unixstl_project
  86. {
  87. # endif /* _STLSOFT_NO_NAMESPACE */
  88. #endif /* !_UNIXSTL_NO_NAMESPACE */
  89. /* /////////////////////////////////////////////////////////////////////////
  90. * c_str_data
  91. *
  92. * This can be applied to an expression, and the return value is either a
  93. * pointer to the character string or to an empty string.
  94. */
  95. /** \brief \ref group__concept__shim__string_access__c_str_data for
  96. * <code>struct dirent</code>.
  97. *
  98. * \ingroup group__concept__shim__string_access
  99. *
  100. * \return None-NULL, non-mutating pointer to a C-style
  101. * string of <code>char</code>.
  102. */
  103. inline us_char_a_t const* c_str_data_a(struct dirent const* d)
  104. {
  105. return (NULL == d) ? "" : d->d_name;
  106. }
  107. /** \brief \ref group__concept__shim__string_access__c_str_data for
  108. * <code>struct dirent</code>.
  109. *
  110. * \ingroup group__concept__shim__string_access
  111. *
  112. * \return None-NULL, non-mutating pointer to a C-style string.
  113. */
  114. inline us_char_a_t const* c_str_data(struct dirent const* d)
  115. {
  116. return (NULL == d) ? "" : d->d_name;
  117. }
  118. /** \brief \ref group__concept__shim__string_access__c_str_data for
  119. * <code>struct dirent</code>.
  120. *
  121. * \ingroup group__concept__shim__string_access
  122. *
  123. * \return None-NULL, non-mutating pointer to a C-style
  124. * string of <code>char</code>.
  125. */
  126. inline us_char_a_t const* c_str_data_a(struct dirent const& d)
  127. {
  128. return d.d_name;
  129. }
  130. /** \brief \ref group__concept__shim__string_access__c_str_data for
  131. * <code>struct dirent</code>.
  132. *
  133. * \ingroup group__concept__shim__string_access
  134. *
  135. * \return None-NULL, non-mutating pointer to a C-style string.
  136. */
  137. inline us_char_a_t const* c_str_data(struct dirent const& d)
  138. {
  139. return d.d_name;
  140. }
  141. /* /////////////////////////////////////////////////////////////////////////
  142. * c_str_len
  143. *
  144. * This can be applied to an expression, and the return value is the number of
  145. * characters in the character string in the expression.
  146. */
  147. /** \brief \ref group__concept__shim__string_access__c_str_len function
  148. * for <code>struct dirent</code>.
  149. *
  150. * \ingroup group__concept__shim__string_access
  151. *
  152. * \return Length (in bytes) of the string form of <code>d</code>.
  153. */
  154. inline us_size_t c_str_len_a(struct dirent const* d)
  155. {
  156. return stlsoft_ns_qual(c_str_len)(c_str_data(d));
  157. }
  158. /** \brief \ref group__concept__shim__string_access__c_str_len function
  159. * for <code>struct dirent</code>.
  160. *
  161. * \ingroup group__concept__shim__string_access
  162. *
  163. * \return Length of the string form of <code>d</code>.
  164. */
  165. inline us_size_t c_str_len(struct dirent const* d)
  166. {
  167. return c_str_len_a(d);
  168. }
  169. /** \brief \ref group__concept__shim__string_access__c_str_len function
  170. * for <code>struct dirent</code>.
  171. *
  172. * \ingroup group__concept__shim__string_access
  173. *
  174. * \return Length (in bytes) of the string form of <code>d</code>.
  175. */
  176. inline us_size_t c_str_len_a(struct dirent const& d)
  177. {
  178. return c_str_len_a(&d);
  179. }
  180. /** \brief \ref group__concept__shim__string_access__c_str_len function
  181. * for <code>struct dirent</code>.
  182. *
  183. * \ingroup group__concept__shim__string_access
  184. *
  185. * \return Length of the string form of <code>d</code>.
  186. */
  187. inline us_size_t c_str_len(struct dirent const& d)
  188. {
  189. return c_str_len(&d);
  190. }
  191. /* /////////////////////////////////////////////////////////////////////////
  192. * c_str_ptr
  193. *
  194. * This can be applied to an expression, and the return value is either a
  195. * pointer to the character string or to an empty string.
  196. */
  197. /** \brief \ref group__concept__shim__string_access__c_str_ptr function
  198. * for <code>struct dirent</code>.
  199. *
  200. * \ingroup group__concept__shim__string_access
  201. *
  202. * \return None-NULL, non-mutating pointer to a nul-terminated C-style
  203. * string of <code>char</code>.
  204. */
  205. inline us_char_a_t const* c_str_ptr_a(struct dirent const* d)
  206. {
  207. return (NULL == d) ? "" : d->d_name;
  208. }
  209. /** \brief \ref group__concept__shim__string_access__c_str_ptr function
  210. * for <code>struct dirent</code>.
  211. *
  212. * \ingroup group__concept__shim__string_access
  213. *
  214. * \return None-NULL, non-mutating pointer to a nul-terminated C-style
  215. * string.
  216. */
  217. inline us_char_a_t const* c_str_ptr(struct dirent const* d)
  218. {
  219. return (NULL == d) ? "" : d->d_name;
  220. }
  221. /** \brief \ref group__concept__shim__string_access__c_str_ptr function
  222. * for <code>struct dirent</code>.
  223. *
  224. * \ingroup group__concept__shim__string_access
  225. *
  226. * \return None-NULL, non-mutating pointer to a nul-terminated C-style
  227. * string of <code>char</code>.
  228. */
  229. inline us_char_a_t const* c_str_ptr_a(struct dirent const& d)
  230. {
  231. return d.d_name;
  232. }
  233. /** \brief \ref group__concept__shim__string_access__c_str_ptr function
  234. * for <code>struct dirent</code>.
  235. *
  236. * \ingroup group__concept__shim__string_access
  237. *
  238. * \return None-NULL, non-mutating pointer to a nul-terminated C-style
  239. * string.
  240. */
  241. inline us_char_a_t const* c_str_ptr(struct dirent const& d)
  242. {
  243. return d.d_name;
  244. }
  245. /* /////////////////////////////////////////////////////////////////////////
  246. * c_str_ptr_null
  247. *
  248. * This can be applied to an expression, and the return value is either a
  249. * pointer to the character string or NULL.
  250. */
  251. /** \brief \ref group__concept__shim__string_access__c_str_ptr_null function
  252. * for <code>struct dirent</code>.
  253. *
  254. * \ingroup group__concept__shim__string_access
  255. *
  256. * \return Possibly NULL, non-mutating pointer to a nul-terminated C-style
  257. * string of <code>char</code>.
  258. */
  259. inline us_char_a_t const* c_str_ptr_null_a(struct dirent const* d)
  260. {
  261. return (NULL == d || 0 == d->d_name[0]) ? static_cast<us_char_a_t const*>(NULL) : d->d_name;
  262. }
  263. /** \brief \ref group__concept__shim__string_access__c_str_ptr_null function
  264. * for <code>struct dirent</code>.
  265. *
  266. * \ingroup group__concept__shim__string_access
  267. *
  268. * \return Possibly NULL, non-mutating pointer to a nul-terminated C-style
  269. * string.
  270. */
  271. inline us_char_a_t const* c_str_ptr_null(struct dirent const* d)
  272. {
  273. return (NULL == d || 0 == d->d_name[0]) ? static_cast<us_char_a_t const*>(NULL) : d->d_name;
  274. }
  275. /** \brief \ref group__concept__shim__string_access__c_str_ptr_null function
  276. * for <code>struct dirent</code>.
  277. *
  278. * \ingroup group__concept__shim__string_access
  279. *
  280. * \return Possibly NULL, non-mutating pointer to a nul-terminated C-style
  281. * string.
  282. */
  283. inline us_char_a_t const* c_str_ptr_null_a(struct dirent const& d)
  284. {
  285. return 0 == d.d_name[0] ? static_cast<us_char_a_t const*>(NULL) : d.d_name;
  286. }
  287. /** \brief \ref group__concept__shim__string_access__c_str_ptr_null function
  288. * for <code>struct dirent</code>.
  289. *
  290. * \ingroup group__concept__shim__string_access
  291. *
  292. * \return Possibly NULL, non-mutating pointer to a nul-terminated C-style
  293. * string.
  294. */
  295. inline us_char_a_t const* c_str_ptr_null(struct dirent const& d)
  296. {
  297. return 0 == d.d_name[0] ? static_cast<us_char_a_t const*>(NULL) : d.d_name;
  298. }
  299. ////////////////////////////////////////////////////////////////////////////
  300. // Unit-testing
  301. #ifdef STLSOFT_UNITTEST
  302. # include "./unittest/dirent_unittest_.h"
  303. #endif /* STLSOFT_UNITTEST */
  304. /* ////////////////////////////////////////////////////////////////////// */
  305. #ifndef _UNIXSTL_NO_NAMESPACE
  306. # if defined(_STLSOFT_NO_NAMESPACE) || \
  307. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  308. } // namespace unixstl
  309. # else
  310. } // namespace stlsoft::unixstl_project
  311. } // namespace stlsoft
  312. # endif /* _STLSOFT_NO_NAMESPACE */
  313. #endif /* !_UNIXSTL_NO_NAMESPACE */
  314. /* /////////////////////////////////////////////////////////////////////////
  315. * Namespace
  316. *
  317. * The string access shims exist either in the stlsoft namespace, or in the
  318. * global namespace. This is required by the lookup rules.
  319. *
  320. */
  321. #ifndef _UNIXSTL_NO_NAMESPACE
  322. # if !defined(_STLSOFT_NO_NAMESPACE) && \
  323. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  324. namespace stlsoft
  325. {
  326. # else /* ? _STLSOFT_NO_NAMESPACE */
  327. /* There is no stlsoft namespace, so must define in the global namespace */
  328. # endif /* !_STLSOFT_NO_NAMESPACE */
  329. using ::unixstl::c_str_data;
  330. using ::unixstl::c_str_data_a;
  331. //using ::unixstl::c_str_data_w;
  332. using ::unixstl::c_str_len;
  333. using ::unixstl::c_str_len_a;
  334. //using ::unixstl::c_str_len_w;
  335. using ::unixstl::c_str_ptr;
  336. using ::unixstl::c_str_ptr_a;
  337. //using ::unixstl::c_str_ptr_w;
  338. using ::unixstl::c_str_ptr_null;
  339. using ::unixstl::c_str_ptr_null_a;
  340. //using ::unixstl::c_str_ptr_null_w;
  341. # if !defined(_STLSOFT_NO_NAMESPACE) && \
  342. !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  343. } // namespace stlsoft
  344. # else /* ? _STLSOFT_NO_NAMESPACE */
  345. /* There is no stlsoft namespace, so must define in the global namespace */
  346. # endif /* !_STLSOFT_NO_NAMESPACE */
  347. #endif /* !_UNIXSTL_NO_NAMESPACE */
  348. /* ////////////////////////////////////////////////////////////////////// */
  349. #endif /* !UNIXSTL_INCL_UNIXSTL_SHIMS_ACCESS_STRING_HPP_DIRENT */
  350. /* ///////////////////////////// end of file //////////////////////////// */