/*************************************************************************** * * Copyright (c) 2011 **.com, Inc. All Rights Reserved * **************************************************************************/ /** * @file def.h * @author ** * @date 2011/06/16 12:38:11 * @brief * **/ #ifndef __FILE_AUTO_PTR_H_ #define __FILE_AUTO_PTR_H_ #include <stdio.h> class file_auto_ptr { public: explicit file_auto_ptr(FILE *fp) : fp_(fp) {} ~file_auto_ptr() { if (NULL != fp_) { fclose(fp_); } } operator FILE*() { return fp_; } operator bool() const { return (NULL != fp_); } FILE& operator*() const { return *fp_; } FILE* operator->() const { return fp_; } private: file_auto_ptr(const file_auto_ptr &oth) : fp_(oth.fp_) {} const file_auto_ptr& operator=(const file_auto_ptr&) {} FILE * const fp_; }; #endif //__FILE_AUTO_PTR_H_