header.htm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <title>Boost Header policy</title>
  6. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  7. <meta name="ProgId" content="FrontPage.Editor.Document">
  8. <meta name="Microsoft Border" content="none, default">
  9. </head>
  10. <body bgcolor="#FFFFFF" text="#000000">
  11. <table summary="Navigational header"
  12. border="1" bgcolor="#007F7F" cellpadding="2">
  13. <tr>
  14. <td bgcolor="#FFFFFF"><img src="../boost.png" alt="boost.png (6897 bytes)" width="277" height="86"></td>
  15. <td><a href="../index.htm"><font face="Arial" color="#FFFFFF"><big>Home</big></font></a></td>
  16. <td><a href="../libs/libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td>
  17. <td><a href="../people/people.htm"><font face="Arial" color="#FFFFFF"><big>People</big></font></a></td>
  18. <td><a href="faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ</big></font></a></td>
  19. <td><a href="index.htm"><font face="Arial" color="#FFFFFF"><big>More</big></font></a></td>
  20. </tr>
  21. </table>
  22. <h1>Boost Header Policy</h1>
  23. <p>Header files are the place where a library comes into contact with user code
  24. and other libraries.&nbsp; To co-exist peacefully and productively, headers must
  25. be &quot;good neighbors&quot;.</p>
  26. <p>Here are the standards for boost headers.&nbsp;&nbsp;&nbsp; Many of
  27. these are also reasonable guidelines for general use.
  28. <ul>
  29. <li>Header filenames should have a .hpp (lowercase) extension.&nbsp;</li>
  30. <li>Unless multiple inclusion is intended, wrap the header in #ifndef guards.
  31. Use a naming convention that minimizes the chance of clashes
  32. with macro names from other's code.&nbsp; The <a href="#SampleHeader">sample
  33. header</a> uses the Boost convention of all uppercase letters, with the
  34. header name prefixed by the namespace name, and suffixed with HPP, separated
  35. by underscores.</li>
  36. <li>Wrap the header contents in a namespace to prevent global namespace
  37. pollution. The namespace approach to pollution control is strongly preferred
  38. to older approaches such as adding funny prefixes to global names.&nbsp;
  39. Libraries which are designed to work well with other Boost libraries should
  40. be placed in namespace <tt>boost</tt>.</li>
  41. <li>Make sure that a translation unit consisting of just the
  42. contents of the header file will compile successfully.</li>
  43. <li>Place the header file in a sub-directory to prevent conflict with
  44. identically named header files in other libraries.&nbsp; The parent
  45. directory is added to the compiler's include search path.&nbsp; Then both
  46. your code and user code specifies the sub-directory in <tt>#include</tt>
  47. directives.&nbsp; Thus the header <a href="#SampleHeader">sample header</a>&nbsp;
  48. would be included by <tt>#include &lt;boost/furball.hpp&gt;</tt></li>
  49. <li>The preferred ordering for class definitions is public members, protected
  50. members, and finally private members.</li>
  51. <li>Include the boost/config.hpp <a href="../libs/config/config.htm">configuration
  52. header</a> if there is a need to deal with compiler or platform
  53. configuration issues.</li>
  54. </ul>
  55. <h2><a name="SampleHeader"></a>Sample Header</h2>
  56. <pre><tt>//&nbsp; Boost general library furball.hpp header file ---------------------------//
  57. &lt;<i> Copyright and license notice</i>, as indicated in the <a href="license_info.html">license page</a> &gt;
  58. //&nbsp; See http://www.boost.org/ for latest version.
  59. #ifndef BOOST_FURBALL_HPP
  60. #define BOOST_FURBALL_HPP
  61. namespace boost {
  62. //&nbsp; Furball class declaration&nbsp; -----------------------------------------------//
  63. &nbsp; class furball
  64. {
  65. public:
  66. &nbsp; void throw_up();
  67. private:
  68. int whatever;
  69. &nbsp;&nbsp;};&nbsp; // furball
  70. } // namespace
  71. #endif&nbsp; // include guard</tt></pre>
  72. <h2>Coding Style</h2>
  73. <p>The alert reader will have noticed that the <a href="#SampleHeader">sample
  74. header</a> employs a certain coding style for indentation, positioning braces,
  75. commenting ending braces, and similar formatting issues.&nbsp; These stylistic
  76. issues are viewed as personal preferences and are not part of the Boost Header
  77. Policy.</p>
  78. <hr>
  79. <p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02 October, 2003<!--webbot bot="Timestamp" endspan i-checksum="38549" --></p>
  80. <p>&copy; Copyright Beman Dawes 1998</p>
  81. <p>
  82. Distributed under the Boost Software License, Version 1.0. (See
  83. accompanying file <a href="../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
  84. at <a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)
  85. </p>
  86. </body>
  87. </html>
粤ICP备19079148号