Modules | Alphabetical List | Class List | Directories | File List | GIL Home Page

# io_error.hpp

Go to the documentation of this file.

    00001 /*
    00002     Copyright 2005-2007 Adobe Systems Incorporated
    00003
    00004     Use, modification and distribution are subject to the Boost Software License,
    00005     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    00006     http://www.boost.org/LICENSE_1_0.txt).
    00007
    00008     See http://opensource.adobe.com/gil for most recent version including documentation.
    00009 */
    00010 /*************************************************************************************************/
    00011
    00012 #ifndef GIL_IO_ERROR_H
    00013 #define GIL_IO_ERROR_H
    00014
    00020
    00021 #include <ios>
    00022 #include "../../gil_config.hpp"
    00023 #include <boost/shared_ptr.hpp>
    00024
    00025 namespace boost { namespace gil {
    00026
    00027 inline void io_error(const char* descr) { throw std::ios_base::failure(descr); }
    00028 inline void io_error_if(bool expr, const char* descr="") { if (expr) io_error(descr); }
    00029
    00030 namespace detail {
    00031     class file_mgr {
    00032     protected:
    00033         shared_ptr<FILE> _fp;
    00034
    00035         struct null_deleter { void operator()(void const*) const {} };
    00036         file_mgr(FILE* file) : _fp(file, null_deleter()) {}
    00037
    00038         file_mgr(const char* filename, const char* flags) {
    00039             FILE* fp;
    00040             io_error_if((fp=fopen(filename,flags))==NULL, "file_mgr: failed to open file");
    00041             _fp=shared_ptr<FILE>(fp,fclose);
    00042         }
    00043
    00044     public:
    00045         FILE* get() { return _fp.get(); }
    00046     };
    00047 }
    00048
    00049 } }  // namespace boost::gil
    00050
    00051 #endif