Adobe Systems, Inc.

io_error.hpp

Go to the documentation of this file.
00001 /*
00002   Copyright 2005-2006 Adobe Systems Incorporated
00003   Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004   or a copy at http://opensource.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef GIL_IO_ERROR_H
00010 #define GIL_IO_ERROR_H
00011 
00017 
00018 #include <ios>
00019 #include "../../core/gil_config.hpp"
00020 #include <boost/shared_ptr.hpp>
00021 
00022 ADOBE_GIL_NAMESPACE_BEGIN
00023 
00024 inline void io_error(const char* descr) { throw std::ios_base::failure(descr); }
00025 inline void io_error_if(bool expr, const char* descr="") { if (expr) io_error(descr); }
00026 
00027 namespace detail {
00028     class file_mgr {
00029     protected:
00030         boost::shared_ptr<FILE> _fp;
00031 
00032         struct null_deleter { void operator()(void const*) const {} };
00033         file_mgr(FILE* file) : _fp(file, null_deleter()) {}
00034 
00035         file_mgr(const char* filename, const char* flags) {
00036             FILE* fp;
00037             io_error_if((fp=fopen(filename,flags))==NULL, "file_mgr: failed to open file");
00038             _fp=boost::shared_ptr<FILE>(fp,fclose);
00039         }
00040 
00041     public:
00042         FILE* get() { return _fp.get(); }
00043     };
00044 }
00045 
00046 ADOBE_GIL_NAMESPACE_END
00047 
00048 #endif

Copyright © 2006 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google