errinfo_file_handle.html 6.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
  2. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
  4. <head>
  5. <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
  6. <title>errinfo_file_handle</title>
  7. <link href='reno.css' type='text/css' rel='stylesheet'/>
  8. </head>
  9. <body>
  10. <div class="body-0">
  11. <div class="body-1">
  12. <div class="body-2">
  13. <div>
  14. <div id="boost_logo">
  15. <a href="http://www.boost.org"><img style="border:0" src="../../../boost.png" alt="Boost" width="277" height="86"/></a>
  16. </div>
  17. <h1>Boost Exception</h1>
  18. </div>
  19. <!-- Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. -->
  20. <!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
  21. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  22. <div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h3>errinfo_file_handle</h3>
  23. </div>
  24. <div class="RenoIncludeDIV"><p><span class="RenoEscape">&#35;<!--<wiki>`&#35;</wiki>--></span>include &lt;<span class="RenoLink"><a href="boost_exception_errinfo_file_handle_hpp.html">boost/exception/errinfo_file_handle.hpp</a></span>&gt;</p>
  25. <div class="RenoIncludeDIV"><pre>#include &lt;<span class="RenoLink"><a href="boost_exception_error_info_hpp.html">boost/exception/error_info.hpp</a></span>&gt;
  26. namespace
  27. boost
  28. {
  29. template &lt;class&gt; class weak_ptr;
  30. <span class="RenoIncludeSPAN"> <span class="RenoIncludeSPAN">typedef <span class="RenoLink"><a href="error_info.html">error_info</a></span>&lt;struct errinfo_file_handle_,weak_ptr&lt;FILE&gt; &gt; <span class="RenoLink">errinfo_file_handle</span>;</span></span>
  31. }</pre>
  32. </div></div><p>This type is designed to be used as a standard <span class="RenoLink"><a href="error_info.html">error_info</a></span> instance for transporting a relevant FILE pointer managed by a boost::shared_ptr&lt;FILE&gt; in exceptions deriving from boost::<span class="RenoLink"><a href="exception.html">exception</a></span>.</p>
  33. <h3>Example:</h3>
  34. <div class="RenoIncludeDIV"><pre>#include &lt;<span class="RenoLink"><a href="boost_exception_errinfo_api_function_hpp.html">boost/exception/errinfo_api_function.hpp</a></span>&gt;
  35. #include &lt;<span class="RenoLink"><a href="boost_exception_errinfo_at_line_hpp.html">boost/exception/errinfo_at_line.hpp</a></span>&gt;
  36. #include &lt;<span class="RenoLink"><a href="boost_exception_errinfo_errno_hpp.html">boost/exception/errinfo_errno.hpp</a></span>&gt;
  37. #include &lt;<span class="RenoLink"><a href="boost_exception_errinfo_file_handle_hpp.html">boost/exception/errinfo_file_handle.hpp</a></span>&gt;
  38. #include &lt;<span class="RenoLink"><a href="boost_exception_errinfo_file_name_hpp.html">boost/exception/errinfo_file_name.hpp</a></span>&gt;
  39. #include &lt;<span class="RenoLink"><a href="boost_exception_errinfo_file_open_mode_hpp.html">boost/exception/errinfo_file_open_mode.hpp</a></span>&gt;
  40. #include &lt;<span class="RenoLink"><a href="boost_exception_info_hpp.html">boost/exception/info.hpp</a></span>&gt;
  41. #include &lt;<span class="RenoLink"><a href="boost_throw_exception_hpp.html">boost/throw_exception.hpp</a></span>&gt;
  42. #include &lt;boost/shared_ptr.hpp&gt;
  43. #include &lt;boost/weak_ptr.hpp&gt;
  44. #include &lt;stdio.h&gt;
  45. #include &lt;errno.h&gt;
  46. #include &lt;exception&gt;
  47. struct error : virtual std::exception, virtual boost::<span class="RenoLink"><a href="exception.html">exception</a></span> { };
  48. struct file_error : virtual error { };
  49. struct file_open_error: virtual file_error { };
  50. struct file_read_error: virtual file_error { };
  51. boost::shared_ptr&lt;FILE&gt;
  52. open_file( char const * file, char const * mode )
  53. {
  54. if( FILE * f=fopen(file,mode) )
  55. return boost::shared_ptr&lt;FILE&gt;(f,fclose);
  56. else
  57. <span class="RenoLink"><a href="BOOST_THROW_EXCEPTION.html">BOOST_THROW_EXCEPTION</a></span>(
  58. file_open_error() &lt;&lt;
  59. boost::<span class="RenoLink"><a href="errinfo_api_function.html">errinfo_api_function</a></span>("fopen") &lt;&lt;
  60. boost::<span class="RenoLink"><a href="errinfo_errno.html">errinfo_errno</a></span>(errno) &lt;&lt;
  61. boost::<span class="RenoLink"><a href="errinfo_file_name.html">errinfo_file_name</a></span>(file) &lt;&lt;
  62. boost::<span class="RenoLink"><a href="errinfo_file_open_mode.html">errinfo_file_open_mode</a></span>(mode) );
  63. }
  64. size_t
  65. read_file( boost::shared_ptr&lt;FILE&gt; const &amp; f, void * buf, size_t size )
  66. {
  67. size_t nr=fread(buf,1,size,f.get());
  68. if( ferror(f.get()) )
  69. <span class="RenoLink"><a href="BOOST_THROW_EXCEPTION.html">BOOST_THROW_EXCEPTION</a></span>(
  70. file_read_error() &lt;&lt;
  71. boost::<span class="RenoLink"><a href="errinfo_api_function.html">errinfo_api_function</a></span>("fread") &lt;&lt;
  72. boost::<span class="RenoLink"><a href="errinfo_errno.html">errinfo_errno</a></span>(errno) &lt;&lt;
  73. boost::<span class="RenoLink">errinfo_file_handle</span>(f) );
  74. return nr;
  75. }</pre>
  76. </div></div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div>
  77. See also: <span class="RenoPageList"><a href="boost_exception_errinfo_file_handle_hpp.html">boost/exception/errinfo_file_handle.hpp</a></span>
  78. </div>
  79. <!-- Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. -->
  80. <!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
  81. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  82. <div id="footer">
  83. <p>
  84. <a class="logo" href="http://jigsaw.w3.org/css-validator/check/referer"><img class="logo_pic" src="valid-css.png" alt="Valid CSS" height="31" width="88"/></a>
  85. <a class="logo" href="http://validator.w3.org/check?uri=referer"><img class="logo_pic" src="valid-xhtml.png" alt="Valid XHTML 1.0" height="31" width="88"/></a>
  86. <small>Copyright (c) 2006-2009 by Emil Dotchevski and Reverge Studios, Inc.<br/>
  87. Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License, Version 1.0</a>.</small>
  88. </p>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </body>
  94. </html>