v3_design.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  5. <meta name="ProgId" content="FrontPage.Editor.Document">
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <title>Filesystem V3 Design</title>
  8. <link href="styles.css" rel="stylesheet">
  9. </head>
  10. <body>
  11. <table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse"
  12. bordercolor="#111111">
  13. <tr>
  14. <td>
  15. <a href="../../../index.htm">
  16. <img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" border="0"
  17. width="300" height="86"></a></td>
  18. <td align="middle">
  19. <font size="7">Filesystem Version 3<br>
  20. Design</font></td>
  21. </tr>
  22. </table>
  23. <table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse"
  24. bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
  25. <tr>
  26. <td><a href="index.htm">Home</a> &nbsp;&nbsp;
  27. <a href="tutorial.html">Tutorial</a> &nbsp;&nbsp;
  28. <a href="reference.html">Reference</a> &nbsp;&nbsp;
  29. <a href="faq.htm">FAQ</a> &nbsp;&nbsp;
  30. <a href="release_history.html">Releases</a> &nbsp;&nbsp;
  31. <a href="portability_guide.htm">Portability</a> &nbsp;&nbsp;
  32. <a href="v3.html">V3 Intro</a> &nbsp;&nbsp;
  33. <a href="v3_design.html">V3 Design</a> &nbsp;&nbsp;
  34. <a href="deprecated.html">Deprecated</a> &nbsp;&nbsp;
  35. <a href="issue_reporting.html">Bug Reports </a>&nbsp;&nbsp;
  36. </td>
  37. </table>
  38. <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse"
  39. bordercolor="#111111" align="right">
  40. <tr>
  41. <td width="100%" bgcolor="#D7EEFF" align="center">
  42. <i><b>Contents</b></i></td>
  43. </tr>
  44. <tr>
  45. <td width="100%" bgcolor="#E8F5FF">
  46. <a href="#Introduction">Introduction</a><br>
  47. <a href="#Problem">Problem</a><br>
  48. <a href="#Solution">Solution</a><br>
  49. <a href="#Details">Details</a><br>
  50. <a href="#Other-changes">Other changes</a><br>
  51. <a href="#Acknowledgements">Acknowledgements</a></td>
  52. </tr>
  53. </table>
  54. <p><b>Caution:</b> This page documents thinking early in the V3 development
  55. process, and is intended to serve historical purposes. It is not updated to
  56. reflect the current state of the library.</p>
  57. <h2><a name="Introduction">Introduction</a></h2>
  58. <p>During the review of Boost.Filesystem.V2 (Internationalization), Peter Dimov
  59. suggested that the<code> basic_path</code> class template was unwieldy, and that a single
  60. path type that accommodated multiple character types and encodings would be more
  61. flexible. Although I wasn't willing to stop development at that time to
  62. explore how this idea might be implemented, or to break from the pattern for
  63. Internationalization used the C++ standard library, I've often thought about
  64. Peter's suggestion. With the advent of C++0x <code>char16_t</code> and <code>char32_t</code>
  65. character
  66. types, the <code>basic_path</code> class template approach becomes even more unwieldy, so it
  67. is time to revisit the problem in light of Peter's suggestion.</p>
  68. <h2><b><a name="Problem">Problem</a></b></h2>
  69. <p>With Filesystem.V2, a path argument to a user defined function that is to
  70. accommodate multiple character types and encodings must be written as a
  71. template. Do-the-right-thing overloads or template metaprogramming must be
  72. employed to allow arguments to be written as string literals. Here's what it
  73. looks like:</p>
  74. <blockquote>
  75. <pre>template&lt;class Path&gt;
  76. void foo( const Path &amp; p );</pre>
  77. <pre>inline void foo( const path &amp; p )
  78. {
  79. return foo&lt;path&gt;( p );
  80. }
  81. inline void foo( const wpath &amp; p )
  82. {
  83. return foo&lt;wpath&gt;( p );
  84. }</pre>
  85. </blockquote>
  86. <p>That's really ugly for such a simple need, and there would be a combinatorial
  87. explosion if the function took multiple Path arguments and each could be either
  88. narrow or wide. It gets even worse if the C++0x <code>char16_t</code> and <code>
  89. char32_t</code> types are to be supported.</p>
  90. <h2><a name="Solution">Solution</a></h2>
  91. <p>Overview:</p>
  92. <ul>
  93. <li>A single, non-template, <code>class path</code>.</li>
  94. <li>Each member function is a template accommodating the various
  95. applicable character types, including user-defined character types.</li>
  96. <li>Hold the path internally in a string of the type used by the operating
  97. system API; <code>std::string</code> for POSIX, <code>std::wstring</code> for Windows.</li>
  98. </ul>
  99. <p>The signatures presented in <a href="#Problem">Problem</a> collapse to
  100. simply:</p>
  101. <blockquote>
  102. <pre>void foo( const path &amp; p );</pre>
  103. </blockquote>
  104. <p>That's a signification reduction in code complexity. Specification becomes
  105. simpler, too. I believe it will be far easier to teach, and result in much more
  106. flexible user code.</p>
  107. <p>Other benefits:</p>
  108. <ul>
  109. <li>All the polymorphism still occurs at compile time.</li>
  110. <li>Efficiency is increased, in that conversions of the encoding, if required,
  111. only occur once at the time of creation, not each time the path is used.</li>
  112. <li>The size of the implementation code drops approximately in half and
  113. becomes much more readable.</li>
  114. </ul>
  115. <p>Possible problems:</p>
  116. <ul>
  117. <li>The combination of member function templates and implicit constructors can
  118. result in unclear error messages when the user makes simple commonplace coding
  119. errors. This should be much less of a problem with C++ concepts, but in the
  120. meantime work continues to restrict over aggressive templates via enable_if/disable_if.</li>
  121. </ul>
  122. <h2><a name="Details">Details</a></h2>
  123. <table border="1" cellpadding="4" cellspacing="0" style="border-collapse: collapse"
  124. bordercolor="#111111" width="100%">
  125. <tr>
  126. <td width="33%" colspan="3">
  127. <p align="center"><b><i>Encoding </i></b><i><b>Conversions</b></i></td>
  128. </tr>
  129. <tr>
  130. <td width="33%">
  131. <p align="center"><i><b>Host system</b></i></td>
  132. <td width="33%">
  133. <p align="center"><i><b>char string path arguments</b></i></td>
  134. <td width="34%">
  135. <p align="center"><i><b>wide string path arguments</b></i></td>
  136. </tr>
  137. <tr>
  138. <td width="33%">Systems with <code>char</code> as the native API path character type (i.e.
  139. POSIX-like systems)</td>
  140. <td width="33%">No conversion.</td>
  141. <td width="34%">Conversion occurs, performed by the current path locale's
  142. <code>codecvt</code> facet.</td>
  143. </tr>
  144. <tr>
  145. <td width="33%">Systems with <code>wchar_t</code> as the native API path character type
  146. (i.e. Windows-like systems).</td>
  147. <td width="33%">Conversion occurs, performed by the current path locale's
  148. <code>codecvt</code> facet.</td>
  149. <td width="34%">No conversion.</td>
  150. </tr>
  151. </table>
  152. <p>When a class path function argument type matches the operating system's
  153. API argument type for paths, no conversion is performed rather than conversion
  154. to a specified encoding such as one of the Unicode encodings. This avoids
  155. unintended consequences, etc.</p>
  156. <h2><a name="Other-changes">Other changes</a></h2>
  157. <p><b>Uniform hybrid error handling: </b>The hybrid error handling idiom has
  158. been consistently applied to all applicable functions.</p>
  159. <h2><a name="Acknowledgements">Acknowledgements</a></h2>
  160. <p>Peter Dimov suggested the idea of a single path class that could cope with
  161. multiple character types and encodings. Walter Landry contributed both the design
  162. and implementation of the copy_any,
  163. copy_directory, copy_symlink, and read_symlink functions.</p>
  164. <hr>
  165. <p>Revised
  166. <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->29 December, 2014<!--webbot bot="Timestamp" endspan i-checksum="38652" --></p>
  167. <p>&copy; Copyright Beman Dawes, 2008</p>
  168. <p> Use, modification, and distribution are subject to the Boost Software
  169. License, Version 1.0. See <a href="http://www.boost.org/LICENSE_1_0.txt">
  170. www.boost.org/LICENSE_1_0.txt</a></p>
  171. </body>
  172. </html>