JPGygax68
7/4/2013 - 2:47 PM

RIIA wrapper for FILE*. No copy semantics yet.

RIIA wrapper for FILE*. No copy semantics yet.

class FilePtr {
public:
    FilePtr() { fp = nullptr; }
    FilePtr(FILE *fp_) { fp = fp_; }
    FilePtr & operator = (FILE *fp_) { assert(fp == nullptr); fp = fp_; return *this; }
    ~FilePtr() { if (fp != nullptr) fclose(fp); }
    operator FILE * () { return fp; }
private:
    FILE *fp;
};