structure.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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="#web">Web Reference Documentation</a></dt>
  69. <dt><a href="#footnotes">Footnotes</a></dt>
  70. </dl>
  71. <h2><a name="introduction" id="introduction">Introduction</a></h2>
  72. <p>Boost does not require any specific documentation structure.
  73. However, there are some important considerations that
  74. influence content and structure. For example, many Boost
  75. libraries wind up being proposed for inclusion in the C++
  76. Standard, so writing them initially with text suitable for
  77. inclusion in the Standard may be helpful. Also, Boost library
  78. documentation is often accessed via the World Wide Web,
  79. including via search engines, so context is often important
  80. for every page. Finally, Boost libraries should provide
  81. additional documentation, such as introductory, tutorial,
  82. example, and rationale content. With those things in mind, we
  83. suggest the following guidelines for Boost library
  84. documentation.</p>
  85. <h2><a name="standards-conforming" id="standards-conforming">Standards
  86. Conforming</a> Documentation</h2>
  87. <p>The documentation structure required for the C++ Standard is
  88. an effective way to describe the technical specifications for
  89. a library. Although terse, that format is familiar to many
  90. Boost users and is far more precise than most ad hoc formats.
  91. The following description is based upon &sect;17.3 of the
  92. Standard. (Note that while final Standard proposals must
  93. include full standardese wording, which the committee will
  94. not do for you, that level of detail is not expected of Boost
  95. library documentation.)</p>
  96. <h3><a name="elements" id="elements">Document elements</a></h3>
  97. <p>Each document contains the following elements, as applicable<a class=
  98. "footnote" href="#footnote1" id="footnote1-location">(1)</a>:</p>
  99. <ul>
  100. <li><a href="#summary">Summary</a></li>
  101. <li><a href="#requirements">Requirements</a></li>
  102. <li><a href="#detailed-specs">Detailed specifications</a></li>
  103. <li><a href="#ref-cpp">References to the Standard C++ library</a></li>
  104. <li><a href="#ref-c">References to the Standard C library</a></li>
  105. </ul>
  106. <h4><a name="summary" id="summary">Summary</a></h4>
  107. <p>The Summary provides a synopsis of the category, and introduces the
  108. first-level subclauses. Each subclause also provides a summary, listing the
  109. headers specified in the subclause and the library entities provided in
  110. each header.</p>
  111. <p>Paragraphs labeled "Note(s):" or "Example(s):" are informative, other
  112. paragraphs are normative.</p>
  113. <p>The summary and the detailed specifications are presented in the
  114. order:</p>
  115. <ul>
  116. <li>Macros</li>
  117. <li>Values</li>
  118. <li>Types</li>
  119. <li>Classes</li>
  120. <li>Functions</li>
  121. <li>Objects</li>
  122. </ul>
  123. <h4><a name="requirements" id="requirements">Requirements</a></h4>
  124. <p>The library can be extended by a C++ program. Each clause, as
  125. applicable, describes the requirements that such extensions must meet. Such
  126. extensions are generally one of the following:</p>
  127. <ul>
  128. <li>Template arguments</li>
  129. <li>Derived classes</li>
  130. <li>Containers, iterators, and/or algorithms that meet an interface
  131. convention</li>
  132. </ul>
  133. <p>Interface convention requirements are stated as generally as possible.
  134. Instead of stating "<code>class X</code> has to define a member function
  135. <code>operator++()</code>," the interface requires "for any object
  136. <code>x</code> of <code>class X</code>, <code>++x</code> is defined." That
  137. is, whether the operator is a member is unspecified.</p>
  138. <p>Requirements are stated in terms of well-defined expressions, which
  139. define valid terms of the types that satisfy the requirements. For every
  140. set of requirements there is a table that specifies an initial set of the
  141. valid expressions and their semantics. Any generic algorithm that uses the
  142. requirements is described in terms of the valid expressions for its formal
  143. type parameters.</p>
  144. <p>Template argument requirements are sometimes referenced by name.</p>
  145. <p>In some cases the semantic requirements are presented as C++ code. Such
  146. code is intended as a specification of equivalance of a construct to
  147. another construct, not necessarily as the way the construct must be
  148. implemented.<a class="footnote" href="#footnote2" id="footnote2-location">(2)</a></p>
  149. <h4><a name="detailed-specs" id="detailed-specs">Detailed
  150. specification</a></h4>
  151. <p>The detailed specifications each contain the following elements:</p>
  152. <ul>
  153. <li>Name and brief description</li>
  154. <li>Synopsis (class definition or function prototype, as
  155. appropriate)</li>
  156. <li>Restrictions on template arguments, if any</li>
  157. <li>Description of class invariants</li>
  158. <li>Description of function semantics</li>
  159. </ul>
  160. <p>Descriptions of class member functions follow the order (as
  161. appropriate)<a class="footnote" href="#footnote3" id="footnote3-location">(3)</a>:</p>
  162. <ul>
  163. <li>Constructor(s) and destructor</li>
  164. <li>Copying and assignment functions</li>
  165. <li>Comparison functions</li>
  166. <li>Modifier functions</li>
  167. <li>Observer functions</li>
  168. <li>Operators and other non-member functions</li>
  169. </ul>
  170. <p>Descriptions of function semantics contain the following <a name=
  171. "function-elements" id="function-elements">elements</a> (as
  172. appropriate)<a class="footnote" href="#footnote4" id="footnote4-location">(4):</a></p>
  173. <dl class="function-semantics">
  174. <dt><b><a href="#requires">Requires:</a></b> the preconditions for
  175. calling the function</dt>
  176. <dt><b><a href="#effects">Effects:</a></b> the actions performed by the
  177. function</dt>
  178. <dt><b><a href="#postconditions">Postconditions:</a></b> the observable
  179. results established by the function</dt>
  180. <dt><b><a href="#returns">Returns:</a></b> a description of the value(s)
  181. returned by the function</dt>
  182. <dt><b><a href="#throws">Throws:</a></b> any exceptions thrown by the
  183. function, and the conditions that would cause the exception</dt>
  184. <dt><b><a href="#complexity">Complexity:</a></b> the time and/or space
  185. complexity of the function</dt>
  186. <dt><b><a href="#rationale">Rationale:</a></b> the rationale for the
  187. function's design or existence</dt>
  188. </dl>
  189. <p>Complexity requirements specified in the library clauses are upper
  190. bounds, and implementations that provide better complexity guarantees
  191. satisfy the requirements.</p>
  192. <h4><a name="ref-cpp" id="ref-cpp">References to the C++ Standard
  193. library</a></h4>
  194. <h4><a name="ref-c" id="ref-c">References to the C Standard
  195. library</a></h4>
  196. <h3><a name="other" id="other">Other conventions</a></h3>
  197. <p>These conventions are for describing implementation-defined types, and
  198. member functions.</p>
  199. <h4><a name="type-descs" id="type-descs">Type descriptions</a></h4>
  200. <p>The Requirements subclauses may describe names that are used to specify
  201. constraints on template arguments.</p>
  202. <h2><a name="more" id="more">More Information</a></h2>
  203. <h3><a name="function-semantic-explanations" id=
  204. "function-semantic-explanations">Function semantic element
  205. explanations</a></h3>
  206. <p>The function semantic element description <a href=
  207. "#function-elements">above</a> is taken directly from the C++ standard, and
  208. is quite terse. Here is a more detailed explanation of each of the
  209. elements.</p>
  210. <p>Note the use of the <code>&lt;code&gt; ... &lt;/code&gt;</code> font tag
  211. to distinguish actual C++ usage from English prose.</p>
  212. <h4><a name="requires" id="requires">Requires</a></h4>
  213. <p>Preconditions for calling the function, typically expressed as
  214. predicates. The most common preconditions are requirements on the value of
  215. arguments, often in the form of C++ expressions. For example,</p>
  216. <pre>
  217. <code>void limit( int * p, int min, int max );</code>
  218. </pre>
  219. <dl class="function-semantics">
  220. <dt><b>Requires:</b> <code>p != 0 &amp;&amp; min &lt;= max</code></dt>
  221. </dl>
  222. <p>Requirements already enforced by the C++ language rules (such as the
  223. type of arguments) are not repeated in Requires paragraphs.</p>
  224. <h4><a name="effects" id="effects">Effects</a></h4>
  225. <p>The actions performed by the function, described either in prose or in
  226. C++. A description in prose is often less limiting on implementors, but is
  227. often less precise than C++ code.</p>
  228. <p>If an effect is specified in one of the other elements, particularly
  229. <i>postconditions</i>, <i>returns</i>, or <i>throws</i>, it is not also
  230. described in the <i>effects</i> paragraph. Having only a single description
  231. ensures that there is one and only one specification, and thus eliminates
  232. the risk of divergence.</p>
  233. <h4><a name="postconditions" id="postconditions">Postconditions</a></h4>
  234. <p>The observable results of the function, such as the value of variables.
  235. Postconditions are often expressed as predicates that are true after the
  236. function completes, in the form of C++ expressions. For example:</p>
  237. <pre>
  238. void make_zero_if_negative( int &amp; x );
  239. </pre>
  240. <dl class="function-semantics">
  241. <dt><b>Postcondition:</b> <code>x &gt;= 0</code></dt>
  242. </dl>
  243. <h4><a name="returns" id="returns">Returns</a></h4>
  244. <p>The value returned by the function, usually in the form of a C++
  245. expression. For example:</p>
  246. <pre>
  247. int sum( int x, int y );
  248. </pre>
  249. <dl class="function-semantics">
  250. <dt><b>Returns:</b> <code>x + y</code></dt>
  251. </dl>
  252. <p>Only specify the return value; the type is already dictated by C++
  253. language rules.</p>
  254. <h4><a name="throws" id="throws">Throws</a></h4>
  255. <p>Specify both the type of exception thrown, and the condition that causes
  256. the exception to be thrown. For example, the <code>std::basic_string</code>
  257. class specifies:</p>
  258. <pre>
  259. void resize(size_type n, charT c);
  260. </pre>
  261. <dl class="function-semantics">
  262. <dt><b>Throws:</b> <code>length_error</code> if <code>n &gt;
  263. max_size()</code>.</dt>
  264. </dl>
  265. <h4><a name="complexity" id="complexity">Complexity</a></h4>
  266. <p>Specifying the time and/or space complexity of a function is often not
  267. desirable because it over-constrains implementors and is hard to specify
  268. correctly. Complexity is thus often best left as a quality of
  269. implementation issue.</p>
  270. <p>A library component, however, can become effectively non-portable if
  271. there is wide variation in performance between conforming implementations.
  272. Containers are a prime example. In these cases it becomes worthwhile to
  273. specify complexity.</p>
  274. <p>Complexity is often specified in generalized <a href=
  275. "http://hissa.nist.gov/dads/HTML/bigOnotation.html">"Big-O"
  276. notation</a>.</p>
  277. <h4><a name="rationale" id="rationale">Rationale</a></h4>
  278. <p>Specifying the rationale for a function's design or existence can often
  279. give users a lot of insight into why a library is designed the way it is.
  280. More importantly, it can help prevent "fixing" something that wasn't really
  281. broken as the library matures.</p>
  282. <h2 id="web">Web Reference Documentation</h2>
  283. <p>Boost library documentation is often accessed via the World
  284. Web. Using search engines, a page deep in the reference
  285. content could be viewed without any further context.
  286. Therefore, it is helpful to add extra context, such as the
  287. following, to each page:</p>
  288. <ul>
  289. <li>Describe the enclosing namespace or use fully scoped
  290. identifiers.
  291. <li>Document required headers for each type or function.
  292. <li>Link to relevant tutorial information.
  293. <li>Link to related example code.
  294. <li>Include the library name.
  295. <li>Include navigation elements to the beginning of the
  296. documentation.
  297. </ul>
  298. <p>It is also useful to consider the effectiveness of a
  299. description in search engines. Terse or cryptic descriptions
  300. are less likely to help the curious find a relevant function
  301. or type.</p>
  302. <h2><a name="footnotes" id="footnotes">Footnotes</a></h2>
  303. <dl>
  304. <dt><a class="footnote" id="footnote1" href="#footnote1-location">(1)</a> To save
  305. space, items that do not apply to a clause are omitted. For example, if a
  306. clause does not specify any requirements, there will be no "Requirements"
  307. subclause.</dt>
  308. <dt><a class="footnote" id="footnote2" href="#footnote2-location">(2)</a> Although
  309. in some cases the code is unambiguously the optimum implementation.</dt>
  310. <dt><a class="footnote" id="footnote3" href="#footnote3-location">(3)</a> To save
  311. space, items that do not apply to a class are omitted. For example, if a
  312. class does not specify any comparison functions, there will be no
  313. "Comparison functions" subclause.</dt>
  314. <dt><a class="footnote" id="footnote4" href="#footnote4-location">(4)</a> To save
  315. space, items that do not apply to a function are omitted. For example, if
  316. a function does not specify any precondition, there will be no "Requires"
  317. paragraph.</dt>
  318. </dl>
  319. <hr>
  320. <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
  321. "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
  322. height="31" width="88"></a></p>
  323. <p>Revised
  324. <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->04
  325. December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38514" --></p>
  326. <p><i>Copyright &copy; 2001 <a href=
  327. "mailto:williamkempf@hotmail.com">William E. Kempf</a></i></p>
  328. <p><i>Distributed under the Boost Software License, Version 1.0. (See
  329. accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  330. copy at <a href=
  331. "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
  332. </body>
  333. </html>
粤ICP备19079148号