00001 /* 00002 * Copyright (C) Sergey P. Derevyago, 2003-2004. 00003 * 00004 * Permission to copy, use, modify, sell and distribute this software is granted 00005 * provided this copyright notice appears in all copies. 00006 * This software is provided "as is" without express or implied warranty, and 00007 * with no claim as to its suitability for any purpose. 00008 * 00009 */ 00010 00015 #ifndef __AUTOFILE_HPP__ 00016 #define __AUTOFILE_HPP__ 00017 00018 #include <stdio.h> 00019 00023 class AutoFILE { 00025 FILE* f; 00026 00028 AutoFILE(const AutoFILE&); 00030 AutoFILE& operator=(const AutoFILE&); 00031 00032 public: 00036 explicit AutoFILE(FILE* f_) : f(f_) {} 00037 00041 FILE* get() const { return f; } 00042 00046 ~AutoFILE() { if (f) fclose(f); } 00047 }; 00048 00049 #endif