structure.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Language" content="en-us">
  5. <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
  6. <link rel="stylesheet" type="text/css" href="../../boost.css">
  7. <title>Writing Documentation for Boost - Documentation Structure</title>
  8. </head>
  9. <body link="#0000FF" vlink="#800080">
  10. <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
  11. "header">
  12. <tr>
  13. <td valign="top" width="300">
  14. <h3><a href="index.html"><img height="86" width="277" alt="C++ Boost"
  15. src="../../boost.png" border="0"></a></h3>
  16. </td>
  17. <td valign="top">
  18. <h1 align="center">Writing Documentation for Boost</h1>
  19. <h2 align="center">Documentation Structure</h2>
  20. </td>
  21. </tr>
  22. </table>
  23. <hr>
  24. <dl class="page-index">
  25. <dt><a href="#introduction">Introduction</a></dt>
  26. <dt><a href="#standards-conforming">Standards Conforming
  27. Documentation</a></dt>
  28. <dd>
  29. <dl class="page-index">
  30. <dt><a href="#elements">Document elements</a></dt>
  31. <dd>
  32. <dl class="page-index">
  33. <dt><a href="#summary">Summary</a></dt>
  34. <dt><a href="#requirements">Requirements</a></dt>
  35. <dt><a href="#detailed-specs">Detailed specifications</a></dt>
  36. <dt><a href="#ref-cpp">References to the Standard C++
  37. library</a></dt>
  38. <dt><a href="#ref-c">References to the Standard C
  39. library</a></dt>
  40. </dl>
  41. </dd>
  42. <dt><a href="#other">Other conventions</a></dt>
  43. <dd>
  44. <dl class="page-index">
  45. <dt><a href="#type-descs">Type descriptions</a></dt>
  46. </dl>
  47. </dd>
  48. </dl>
  49. </dd>
  50. <dt><a href="#more">More Information</a></dt>
  51. <dd>
  52. <dl class="page-index">
  53. <dt><a href="#function-semantic-explanations">Function semantic
  54. element explanations</a></dt>
  55. <dd>
  56. <dl class="page-index">
  57. <dt><a href="#requires">Requires</a></dt>
  58. <dt><a href="#effects">Effects</a></dt>
  59. <dt><a href="#postconditions">Postconditions</a></dt>
  60. <dt><a href="#returns">Returns</a></dt>
  61. <dt><a href="#throws">Throws</a></dt>
  62. <dt><a href="#complexity">Complexity</a></dt>
  63. <dt><a href="#rationale">Rationale</a></dt>
  64. </dl>
  65. </dd>
  66. </dl>
  67. </dd>
  68. <dt><a href="#footnotes">Footnotes</a></dt>
  69. </dl>
  70. <h2><a name="introduction" id="introduction">Introduction</a></h2>
  71. <p>Boost itself does not require any specific documentation structure. The
  72. C++ Standard, however, has very explicit requirements for the description
  73. of library components (Section 17.3). So for Boost libraries likely to be
  74. proposed for inclusion in the standard, it is highly desirable to structure
  75. documentation in a way that meets the requirements of the the standard.
  76. Doing so eliminates the need to rewrite the documentation for
  77. standardization.</p>
  78. <p>Library developers should remember that for a library to be accepted as
  79. part of the C++ Standard Library, the proposal must include full wording.
  80. The committee will not do that work for you.</p>
  81. <p>Beyond that, the documentation structure required for the standard is an
  82. effective way to communicate the technical specifications for a library.
  83. Although terse, it is already familiar to many Boost users, and is far more
  84. precise than most ad hoc documentation structures.</p>
  85. <p>The following description is for the structure of documentation required
  86. by the standard. Boost libraries should also provided additional
  87. documentation, such as introductory, tutorial, example, and rationale
  88. material.</p>
  89. <h2><a name="standards-conforming" id="standards-conforming">Standards
  90. Conforming</a> Documentation</h2>
  91. <h3><a name="elements" id="elements">Document elements</a></h3>
  92. <p>Each document contains the following elements, as applicable<a class=
  93. "footnote" href="#footnote1">(1)</a>:</p>
  94. <ul>
  95. <li><a href="#summary">Summary</a></li>
  96. <li><a href="#requirements">Requirements</a></li>
  97. <li><a href="#detailed-specs">Detailed specifications</a></li>
  98. <li><a href="#ref-cpp">References to the Standard C++ library</a></li>
  99. <li><a href="#ref-c">References to the Standard C library</a></li>
  100. </ul>
  101. <h4><a name="summary" id="summary">Summary</a></h4>
  102. <p>The Summary provides a synopsis of the category, and introduces the
  103. first-level subclauses. Each subclause also provides a summary, listing the
  104. headers specified in the subclause and the library entities provided in
  105. each header.</p>
  106. <p>Paragraphs labeled "Note(s):" or "Example(s):" are informative, other
  107. paragraphs are normative.</p>
  108. <p>The summary and the detailed specifications are presented in the
  109. order:</p>
  110. <ul>
  111. <li>Macros</li>
  112. <li>Values</li>
  113. <li>Types</li>
  114. <li>Classes</li>
  115. <li>Functions</li>
  116. <li>Objects</li>
  117. </ul>
  118. <h4><a name="requirements" id="requirements">Requirements</a></h4>
  119. <p>The library can be extended by a C++ program. Each clause, as
  120. applicable, describes the requirements that such extensions must meet. Such
  121. extensions are generally one of the following:</p>
  122. <ul>
  123. <li>Template arguments</li>
  124. <li>Derived classes</li>
  125. <li>Containers, iterators, and/or algorithms that meet an interface
  126. convention</li>
  127. </ul>
  128. <p>Interface convention requirements are stated as generally as possible.
  129. Instead of stating "<code>class X</code> has to define a member function
  130. <code>operator++()</code>," the interface requires "for any object
  131. <code>x</code> of <code>class X</code>, <code>++x</code> is defined." That
  132. is, whether the operator is a member is unspecified.</p>
  133. <p>Requirements are stated in terms of well-defined expressions, which
  134. define valid terms of the types that satisfy the requirements. For every
  135. set of requirements there is a table that specifies an initial set of the
  136. valid expressions and their semantics. Any generic algorithm that uses the
  137. requirements is described in terms of the valid expressions for its formal
  138. type parameters.</p>
  139. <p>Template argument requirements are sometimes referenced by name.</p>
  140. <p>In some cases the semantic requirements are presented as C++ code. Such
  141. code is intended as a specification of equivalance of a construct to
  142. another construct, not necessarily as the way the construct must be
  143. implemented.<a class="footnote" href="#footnote2">(2)</a></p>
  144. <h4><a name="detailed-specs" id="detailed-specs">Detailed
  145. specification</a></h4>
  146. <p>The detailed specifications each contain the following elements:</p>
  147. <ul>
  148. <li>Name and brief description</li>
  149. <li>Synopsis (class definition or function prototype, as
  150. appropriate)</li>
  151. <li>Restrictions on template arguments, if any</li>
  152. <li>Description of class invariants</li>
  153. <li>Description of function semantics</li>
  154. </ul>
  155. <p>Descriptions of class member functions follow the order (as
  156. appropriate)<a class="footnote" href="#footnote3">(3)</a>:</p>
  157. <ul>
  158. <li>Constructor(s) and destructor</li>
  159. <li>Copying and assignment functions</li>
  160. <li>Comparison functions</li>
  161. <li>Modifier functions</li>
  162. <li>Observer functions</li>
  163. <li>Operators and other non-member functions</li>
  164. </ul>
  165. <p>Descriptions of function semantics contain the following <a name=
  166. "function-elements" id="function-elements">elements</a> (as
  167. appropriate)<a class="footnote" href="#footnote4">(4):</a></p>
  168. <dl class="function-semantics">
  169. <dt><b><a href="#requires">Requires:</a></b> the preconditions for
  170. calling the function</dt>
  171. <dt><b><a href="#effects">Effects:</a></b> the actions performed by the
  172. function</dt>
  173. <dt><b><a href="#postconditions">Postconditions:</a></b> the observable
  174. results established by the function</dt>
  175. <dt><b><a href="#returns">Returns:</a></b> a description of the value(s)
  176. returned by the function</dt>
  177. <dt><b><a href="#throws">Throws:</a></b> any exceptions thrown by the
  178. function, and the conditions that would cause the exception</dt>
  179. <dt><b><a href="#complexity">Complexity:</a></b> the time and/or space
  180. complexity of the function</dt>
  181. <dt><b><a href="#rationale">Rationale:</a></b> the rationale for the
  182. function's design or existence</dt>
  183. </dl>
  184. <p>Complexity requirements specified in the library clauses are upper
  185. bounds, and implementations that provide better complexity guarantees
  186. satisfy the requirements.</p>
  187. <h4><a name="ref-cpp" id="ref-cpp">References to the C++ Standard
  188. library</a></h4>
  189. <h4><a name="ref-c" id="ref-c">References to the C Standard
  190. library</a></h4>
  191. <h3><a name="other" id="other">Other conventions</a></h3>
  192. <p>These conventions are for describing implementation-defined types, and
  193. member functions.</p>
  194. <h4><a name="type-descs" id="type-descs">Type descriptions</a></h4>
  195. <p>The Requirements subclauses may describe names that are used to specify
  196. constraints on template arguments.</p>
  197. <h2><a name="more" id="more">More Information</a></h2>
  198. <h3><a name="function-semantic-explanations" id=
  199. "function-semantic-explanations">Function semantic element
  200. explanations</a></h3>
  201. <p>The function semantic element description <a href=
  202. "#function-elements">above</a> is taken directly from the C++ standard, and
  203. is quite terse. Here is a more detailed explanation of each of the
  204. elements.</p>
  205. <p>Note the use of the <code>&lt;code&gt; ... &lt;/code&gt;</code> font tag
  206. to distinguish actual C++ usage from English prose.</p>
  207. <h4><a name="requires" id="requires">Requires</a></h4>
  208. <p>Preconditions for calling the function, typically expressed as
  209. predicates. The most common preconditions are requirements on the value of
  210. arguments, often in the form of C++ expressions. For example,</p>
  211. <pre>
  212. <code>void limit( int * p, int min, int max );</code>
  213. </pre>
  214. <dl class="function-semantics">
  215. <dt><b>Requires:</b> <code>p != 0 &amp;&amp; min &lt;= max</code></dt>
  216. </dl>
  217. <p>Requirements already enforced by the C++ language rules (such as the
  218. type of arguments) are not repeated in Requires paragraphs.</p>
  219. <h4><a name="effects" id="effects">Effects</a></h4>
  220. <p>The actions performed by the function, described either in prose or in
  221. C++. A description in prose is often less limiting on implementors, but is
  222. often less precise than C++ code.</p>
  223. <p>If an effect is specified in one of the other elements, particularly
  224. <i>postconditions</i>, <i>returns</i>, or <i>throws</i>, it is not also
  225. described in the <i>effects</i> paragraph. Having only a single description
  226. ensures that there is one and only one specification, and thus eliminates
  227. the risk of divergence.</p>
  228. <h4><a name="postconditions" id="postconditions">Postconditions</a></h4>
  229. <p>The observable results of the function, such as the value of variables.
  230. Postconditions are often expressed as predicates that are true after the
  231. function completes, in the form of C++ expressions. For example:</p>
  232. <pre>
  233. void make_zero_if_negative( int &amp; x );
  234. </pre>
  235. <dl class="function-semantics">
  236. <dt><b>Postcondition:</b> <code>x &gt;= 0</code></dt>
  237. </dl>
  238. <h4><a name="returns" id="returns">Returns</a></h4>
  239. <p>The value returned by the function, usually in the form of a C++
  240. expression. For example:</p>
  241. <pre>
  242. int sum( int x, int y );
  243. </pre>
  244. <dl class="function-semantics">
  245. <dt><b>Returns:</b> <code>x + y</code></dt>
  246. </dl>
  247. <p>Only specify the return value; the type is already dictated by C++
  248. language rules.</p>
  249. <h4><a name="throws" id="throws">Throws</a></h4>
  250. <p>Specify both the type of exception thrown, and the condition that causes
  251. the exception to be thrown. For example, the <code>std::basic_string</code>
  252. class specifies:</p>
  253. <pre>
  254. void resize(size_type n, charT c);
  255. </pre>
  256. <dl class="function-semantics">
  257. <dt><b>Throws:</b> <code>length_error</code> if <code>n &gt;
  258. max_size()</code>.</dt>
  259. </dl>
  260. <h4><a name="complexity" id="complexity">Complexity</a></h4>
  261. <p>Specifying the time and/or space complexity of a function is often not
  262. desirable because it over-constrains implementors and is hard to specify
  263. correctly. Complexity is thus often best left as a quality of
  264. implementation issue.</p>
  265. <p>A library component, however, can become effectively non-portable if
  266. there is wide variation in performance between conforming implementations.
  267. Containers are a prime example. In these cases it becomes worthwhile to
  268. specify complexity.</p>
  269. <p>Complexity is often specified in generalized <a href=
  270. "http://hissa.nist.gov/dads/HTML/bigOnotation.html">"Big-O"
  271. notation</a>.</p>
  272. <h4><a name="rationale" id="rationale">Rationale</a></h4>
  273. <p>Specifying the rationale for a function's design or existence can often
  274. give users a lot of insight into why a library is designed the way it is.
  275. More importantly, it can help prevent "fixing" something that wasn't really
  276. broken as the library matures.</p>
  277. <h2><a name="footnotes" id="footnotes">Footnotes</a></h2>
  278. <dl>
  279. <dt><a class="footnote" name="footnote1" id="footnote1">(1)</a> To save
  280. space, items that do not apply to a clause are omitted. For example, if a
  281. clause does not specify any requirements, there will be no "Requirements"
  282. subclause.</dt>
  283. <dt><a class="footnote" name="footnote2" id="footnote2">(2)</a> Although
  284. in some cases the code is unambiguously the optimum implementation.</dt>
  285. <dt><a class="footnote" name="footnote3" id="footnote3">(3)</a> To save
  286. space, items that do not apply to a class are omitted. For example, if a
  287. class does not specify any comparison functions, there will be no
  288. "Comparison functions" subclause.</dt>
  289. <dt><a class="footnote" name="footnote4" id="footnote4">(4)</a> To save
  290. space, items that do not apply to a function are omitted. For example, if
  291. a function does not specify any precondition, there will be no "Requires"
  292. paragraph.</dt>
  293. </dl>
  294. <hr>
  295. <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
  296. "http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
  297. height="31" width="88"></a></p>
  298. <p>Revised
  299. <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->04
  300. December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38514" --></p>
  301. <p><i>Copyright &copy; 2001 <a href=
  302. "mailto:williamkempf@hotmail.com">William E. Kempf</a></i></p>
  303. <p><i>Distributed under the Boost Software License, Version 1.0. (See
  304. accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  305. copy at <a href=
  306. "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
  307. </body>
  308. </html>
粤ICP备19079148号