Chris@16: /* Chris@16: Copyright 2005-2007 Adobe Systems Incorporated Chris@16: Chris@16: Use, modification and distribution are subject to the Boost Software License, Chris@16: Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt). Chris@16: Chris@16: See http://opensource.adobe.com/gil for most recent version including documentation. Chris@16: */ Chris@16: /*************************************************************************************************/ Chris@16: Chris@16: #ifndef GIL_IO_ERROR_H Chris@16: #define GIL_IO_ERROR_H Chris@16: Chris@16: /// \file Chris@16: /// \brief Handle input-output errors Chris@16: /// \author Lubomir Bourdev and Hailin Jin \n Chris@16: /// Adobe Systems Incorporated Chris@16: /// \date 2005-2007 \n Last updated on May 30, 2006 Chris@16: Chris@16: #include Chris@16: #include "../../gil_config.hpp" Chris@16: #include Chris@16: Chris@16: namespace boost { namespace gil { Chris@16: Chris@16: inline void io_error(const char* descr) { throw std::ios_base::failure(descr); } Chris@16: inline void io_error_if(bool expr, const char* descr="") { if (expr) io_error(descr); } Chris@16: Chris@16: namespace detail { Chris@16: class file_mgr { Chris@16: protected: Chris@16: shared_ptr _fp; Chris@16: Chris@16: struct null_deleter { void operator()(void const*) const {} }; Chris@16: file_mgr(FILE* file) : _fp(file, null_deleter()) {} Chris@16: Chris@16: file_mgr(const char* filename, const char* flags) { Chris@16: FILE* fp; Chris@16: io_error_if((fp=fopen(filename,flags))==NULL, "file_mgr: failed to open file"); Chris@16: _fp=shared_ptr(fp,fclose); Chris@16: } Chris@16: Chris@16: public: Chris@16: FILE* get() { return _fp.get(); } Chris@16: }; Chris@16: } Chris@16: Chris@16: } } // namespace boost::gil Chris@16: Chris@16: #endif