- Main Page
- Classes
- Files

- File List

# OptFrame/Util/Scanner++/File.h

    00001 // File Object - Scanner++
    00002
    00003 // Copyright (C) 2009
    00004 // Igor Machado - Mario Henrique Perche - Pablo Munhoz - Sabir Ribas
    00005 //
    00006 // This file is part of the Scanner++ Library v0.91.  This library is free
    00007 // software; you can redistribute it and/or modify it under the
    00008 // terms of the GNU Lesser General Public License v3 as published by the
    00009 // Free Software Foundation.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU Lesser General Public License v3 for more details.
    00015
    00016 // You should have received a copy of the GNU Lesser General Public License v3
    00017 // along with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    00019 // USA.
    00020
    00021 #ifndef FILE_H_
    00022 #define FILE_H_
    00023
    00024 #include<fstream>
    00025 #include<string>
    00026
    00027 using namespace std;
    00028 #include<iostream>
    00029
    00030 class FileNotFound
    00031 {
    00032 private:
    00033    string file;
    00034 public:
    00035    FileNotFound(string str)
    00036    {
    00037       file = str;
    00038    }
    00039
    00040    string getFile()
    00041    {
    00042       return file;
    00043    }
    00044 };
    00045
    00046 class File
    00047 {
    00048 public:
    00049    std::ifstream* file;
    00050
    00051    //File(const char* filename);
    00052    //File(string filename)
    00053    File(string const filename)
    00054    {
    00055       std::fstream foo;
    00056
    00057       foo.open(filename.c_str());
    00058
    00059       if (foo.is_open() == true)
    00060          foo.close();
    00061       else
    00062          throw FileNotFound(filename);
    00063
    00064       file = new std::ifstream(filename.c_str(), std::ifstream::in);
    00065    }
    00066
    00067    virtual ~File()
    00068    {
    00069       close();
    00070    }
    00071
    00072    int get()
    00073    {
    00074       return file->get();
    00075    }
    00076
    00077    bool eof()
    00078    {
    00079       return file->eof();
    00080    }
    00081
    00082    void close()
    00083    {
    00084       file->close();
    00085    }
    00086 };
    00087
    00088 #endif /*FILE_H_*/

All Classes Functions