File.qbk 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. [/
  2. Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ]
  6. [section:File File]
  7. The [*File] concept abstracts access to files in the underlying file system.
  8. To support other platform interfaces, users may author their own [*File]
  9. types which meet these requirements.
  10. [heading Associated Types]
  11. * [link beast.ref.boost__beast__file_mode `file_mode`]
  12. * [link beast.ref.boost__beast__is_file `is_file`]
  13. [heading Requirements]
  14. In this table:
  15. * `F` is a [*File] type
  16. * `f` is an instance of `F`
  17. * `p` is a value of type `char const*` which points to a null
  18. terminated utf-8 encoded string.
  19. * `m` is an instance of [link beast.ref.boost__beast__file_mode `file_mode`]
  20. * `n` is a number of bytes, convertible to `std::size_t`
  21. * `o` is a byte offset in the file, convertible to `std::uint64_t`
  22. * `b` is any non-const pointer to memory
  23. * `c` is any possibly-const pointer to memory
  24. * `ec` is a reference of type [link beast.ref.boost__beast__error_code `error_code`]
  25. [table Valid expressions
  26. [[Expression] [Type] [Semantics, Pre/Post-conditions]]
  27. [[Operation] [Return Type] [Semantics, Pre/Post-conditions]]
  28. [
  29. [`F()`]
  30. [ ]
  31. [
  32. Default constructable
  33. ]
  34. ]
  35. [
  36. [`f.~F()`]
  37. [ ]
  38. [
  39. Destructible.
  40. If `f` refers to an open file, it is first closed
  41. as if by a call to `close` with the error ignored.
  42. ]
  43. ]
  44. [
  45. [`f.is_open()`]
  46. [`bool`]
  47. [
  48. Returns `true` if `f` refers to an open file, `false` otherwise.
  49. ]
  50. ]
  51. [
  52. [`f.close(ec)`]
  53. []
  54. [
  55. If `f` refers to an open file, this function attempts to
  56. close the file.
  57. Regardless of whether an error occurs or not, a subsequent
  58. call to `f.is_open()` will return `false`.
  59. The function will ensure that `!ec` is `true` if there was
  60. no error or set to the appropriate error code if an error
  61. occurred.
  62. ]
  63. ]
  64. [
  65. [`f.open(p,m,ec)`]
  66. []
  67. [
  68. Attempts to open the file at the path specified by `p`
  69. with the mode specified by `m`.
  70. Upon success, a subsequent call to `f.is_open()` will
  71. return `true`.
  72. If `f` refers to an open file, it is first closed
  73. as if by a call to `close` with the error ignored.
  74. The function will ensure that `!ec` is `true` if there was
  75. no error or set to the appropriate error code if an error
  76. occurred.
  77. ]
  78. ]
  79. [
  80. [`f.size(ec)`]
  81. [`std::uint64_t`]
  82. [
  83. If `f` refers to an open file, this function attempts to
  84. determine the file size and return its value.
  85. If `f` does not refer to an open file, the function will
  86. set `ec` to `errc::invalid_argument` and return 0.
  87. The function will ensure that `!ec` is `true` if there was
  88. no error or set to the appropriate error code if an error
  89. occurred.
  90. ]
  91. ]
  92. [
  93. [`f.pos(ec)`]
  94. [`std::uint64_t`]
  95. [
  96. If `f` refers to an open file, this function attempts to
  97. determine the current file offset and return it.
  98. If `f` does not refer to an open file, the function will
  99. set `ec` to `errc::invalid_argument` and return 0.
  100. The function will ensure that `!ec` is `true` if there was
  101. no error or set to the appropriate error code if an error
  102. occurred.
  103. ]
  104. ]
  105. [
  106. [`f.seek(o,ec)`]
  107. []
  108. [
  109. Attempts to reposition the current file offset to the value
  110. `o`, which represents a byte offset relative to the beginning
  111. of the file.
  112. If `f` does not refer to an open file, the function will
  113. set `ec` to `errc::invalid_argument` and return immediately.
  114. The function will ensure that `!ec` is `true` if there was
  115. no error or set to the appropriate error code if an error
  116. occurred.
  117. ]
  118. ]
  119. [
  120. [`f.read(b,n,ec)`]
  121. [`std::size_t`]
  122. [
  123. Attempts to read `n` bytes starting at the current file offset
  124. from the open file referred to by `f`.
  125. Bytes read are stored in the memory buffer at address `b` which
  126. must be at least `n` bytes in size.
  127. The function advances the file offset by the amount read, and
  128. returns the number of bytes actually read, which may be less
  129. than `n`.
  130. If `f` does not refer to an open file, the function will
  131. set `ec` to `errc::invalid_argument` and return immediately.
  132. The function will ensure that `!ec` is `true` if there was
  133. no error or set to the appropriate error code if an error
  134. occurred.
  135. ]
  136. ]
  137. [
  138. [`f.write(c,n,ec)`]
  139. [`std::size_t`]
  140. [
  141. Attempts to write `n` bytes from the buffer pointed to by `c` to
  142. the current file offset of the open file referred to by `f`.
  143. The memory buffer at `c` must point to storage of at least `n`
  144. bytes meant to be copied to the file.
  145. The function advances the file offset by the amount written,
  146. and returns the number of bytes actually written, which may be
  147. less than `n`.
  148. If `f` does not refer to an open file, the function will
  149. set `ec` to `errc::invalid_argument` and return immediately.
  150. The function will ensure that `!ec` is `true` if there was
  151. no error or set to the appropriate error code if an error
  152. occurred.
  153. ]
  154. ]
  155. ]
  156. [heading Exemplar]
  157. [concept_File]
  158. [heading Models]
  159. * [link beast.ref.boost__beast__file_posix `file_posix`]
  160. * [link beast.ref.boost__beast__file_stdio `file_stdio`]
  161. * [link beast.ref.boost__beast__file_win32 `file_win32`]
  162. [endsect]