header.htm 4.8 KB

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