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