header.htm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <title>Header policy</title>
  5. <meta name="GENERATOR" content="Microsoft FrontPage 4.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="../c++boost.gif" alt="c++boost.gif (8819 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="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td>
  15. <td><a href="../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>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>Identify the file with an initial comment line.&nbsp; The sample header
  29. identifies both the name of the header and the library it is a part of.</li>
  30. <li>Specify copyright ownership and any restrictions on use.&nbsp; If you
  31. don't want to retain ownership, say something like &quot;Written by Jane
  32. Programmer and placed in the public domain&quot;.</li>
  33. <li>Supply version information, possibly generated automatically by your
  34. version control system.</li>
  35. <li>Macro names should be all uppercase, and begin with the namespace
  36. name.&nbsp; Underscores separate words.</li>
  37. <li>Wrap the header in #ifndef guards so that multiple inclusion is
  38. benign.&nbsp; Use a naming convention that minimizes the chance of clashes
  39. with macro names from other's code.&nbsp; The <a href="#Sample header">sample
  40. header</a> uses the Boost convention of all uppercase letters, with the
  41. header name prefixed by the namespace name, and suffixed with HPP, separated
  42. by underscores.</li>
  43. <li>Wrap the header contents in a namespace to prevent global namespace
  44. pollution. The namespace approach to pollution control is strongly preferred
  45. to older approaches such as adding funny prefixes to global names.&nbsp;
  46. Libraries which are designed to work well with other Boost libraries should
  47. be placed namespace <tt>boost</tt>.</li>
  48. <li>Place the header file in a sub-directory to prevent conflict with
  49. identically named header files in other libraries.&nbsp; The parent
  50. directory is added to the compiler's include search path.&nbsp; Then both
  51. your code and user code specifies the sub-directory in <tt>#include</tt>
  52. directives.&nbsp; Thus the header <a href="#Sample header">sample header</a>&nbsp;
  53. would be included by <tt>#include &lt;boost/furball.hpp&gt;</tt></li>
  54. <li>The preferred ordering for class definitions is public members, protected
  55. members, and finally private members.</li>
  56. <li>Include the boost/config.hpp <a href="../libs/config/index.htm">configuration
  57. header</a> if there is a need to deal with compiler or platform
  58. configuration issues.</li>
  59. </ul>
  60. <h2><a name="Sample header"></a>Sample Header</h2>
  61. <pre><tt>//&nbsp; Boost general library furball.hpp header file&nbsp; ---------------------------//
  62. //&nbsp; (C) Copyright Your Name 1998. Permission to copy, use, modify, sell and
  63. //&nbsp; distribute this software is granted provided this copyright notice appears
  64. //&nbsp; in all copies. This software is provided &quot;as is&quot; without express or implied
  65. //&nbsp; warranty, and with no claim as to its suitability for any purpose.
  66. //&nbsp; $Id$ or other version information
  67. #ifndef BOOST_FURBALL_HPP
  68. #define BOOST_FURBALL_HPP
  69. namespace boost {
  70. //&nbsp; Furball class declaration&nbsp; -----------------------------------------------//
  71. &nbsp; class furball
  72. {
  73. public:
  74. &nbsp; void throw_up();
  75. private:
  76. int whatever;
  77. &nbsp;&nbsp;};&nbsp; // furball
  78. } // namespace
  79. #endif&nbsp; // BOOST_FURBALL_HPP</tt></pre>
  80. <h2>Coding Style</h2>
  81. <p>The alert reader will have noticed that the <a href="#Sample header">sample
  82. header</a> employs a certain coding style for indentation, positioning braces,
  83. commenting ending braces, and similar formatting issues.&nbsp; These stylistic
  84. issues are viewed as personal preferences and are not part of the Boost Header
  85. Policy.</p>
  86. <hr>
  87. <p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->27 July, 2000<!--webbot bot="Timestamp" endspan i-checksum="21060" --></p>
  88. </body>
  89. </html>
粤ICP备19079148号