Chris@16
|
1 /*
|
Chris@16
|
2 Copyright 2005-2007 Adobe Systems Incorporated
|
Chris@16
|
3
|
Chris@16
|
4 Use, modification and distribution are subject to the Boost Software License,
|
Chris@16
|
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 http://www.boost.org/LICENSE_1_0.txt).
|
Chris@16
|
7
|
Chris@16
|
8 See http://opensource.adobe.com/gil for most recent version including documentation.
|
Chris@16
|
9 */
|
Chris@16
|
10 /*************************************************************************************************/
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef GIL_IO_ERROR_H
|
Chris@16
|
13 #define GIL_IO_ERROR_H
|
Chris@16
|
14
|
Chris@16
|
15 /// \file
|
Chris@16
|
16 /// \brief Handle input-output errors
|
Chris@16
|
17 /// \author Lubomir Bourdev and Hailin Jin \n
|
Chris@16
|
18 /// Adobe Systems Incorporated
|
Chris@16
|
19 /// \date 2005-2007 \n Last updated on May 30, 2006
|
Chris@16
|
20
|
Chris@16
|
21 #include <ios>
|
Chris@16
|
22 #include "../../gil_config.hpp"
|
Chris@16
|
23 #include <boost/shared_ptr.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 namespace boost { namespace gil {
|
Chris@16
|
26
|
Chris@16
|
27 inline void io_error(const char* descr) { throw std::ios_base::failure(descr); }
|
Chris@16
|
28 inline void io_error_if(bool expr, const char* descr="") { if (expr) io_error(descr); }
|
Chris@16
|
29
|
Chris@16
|
30 namespace detail {
|
Chris@16
|
31 class file_mgr {
|
Chris@16
|
32 protected:
|
Chris@16
|
33 shared_ptr<FILE> _fp;
|
Chris@16
|
34
|
Chris@16
|
35 struct null_deleter { void operator()(void const*) const {} };
|
Chris@16
|
36 file_mgr(FILE* file) : _fp(file, null_deleter()) {}
|
Chris@16
|
37
|
Chris@16
|
38 file_mgr(const char* filename, const char* flags) {
|
Chris@16
|
39 FILE* fp;
|
Chris@16
|
40 io_error_if((fp=fopen(filename,flags))==NULL, "file_mgr: failed to open file");
|
Chris@16
|
41 _fp=shared_ptr<FILE>(fp,fclose);
|
Chris@16
|
42 }
|
Chris@16
|
43
|
Chris@16
|
44 public:
|
Chris@16
|
45 FILE* get() { return _fp.get(); }
|
Chris@16
|
46 };
|
Chris@16
|
47 }
|
Chris@16
|
48
|
Chris@16
|
49 } } // namespace boost::gil
|
Chris@16
|
50
|
Chris@16
|
51 #endif
|