Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

base/File

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)1996 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: File 1029 2004-02-11 20:45:54Z jungd $
00019  
00020 ****************************************************************************/
00021 
00022 #ifndef _BASE_FILE_
00023 #define _BASE_FILE_
00024 
00025 #include <base/base>
00026 #include <base/VFile>
00027 #include <base/path_not_found>
00028 #include <base/io_error>
00029 
00030 
00031 #include <string>
00032 
00033 namespace base {
00034 
00035 
00036 class File : public VFile
00037 {
00038 public:
00039   virtual ~File();
00040 
00041   virtual String className() const { return String("File"); }
00042   virtual Object& clone() const { return *NewNamedObj(className()) File(*this); }
00043 
00044   virtual String extension() const { return pathname.extension(); }  // the file's extension (e.g. .png)
00045 
00046   virtual std::istream&  istream() const throw(io_error);
00047   virtual std::ostream&  ostream() const throw(io_error);
00048   virtual std::iostream& iostream(std::iostream::openmode mode = (std::iostream::in | std::iostream::out) ) const throw(io_error);
00049 
00050   virtual void close() const throw(io_error); // close the file (can be re-opened again via istream/ostream/iostream() )
00051 
00052 protected:
00053   void open(std::iostream::openmode mode) const throw(path_not_found, io_error);
00054 
00055   mutable bool opened;
00056   mutable std::iostream::openmode mode;
00057   mutable std::fstream* fileStream;
00058 
00059   File(const File& f) : VFile(f), opened(f.opened), fileStream(f.fileStream) {}
00060   explicit File(const PathName& pathname) throw(path_not_found, io_error);
00061   File(const String& pathname) throw(path_not_found, io_error, std::invalid_argument);
00062 
00063   friend class Directory;
00064   friend class StdFileSystem;
00065 };
00066 
00067 } // base
00068 
00069 #endif

Generated on Thu Jul 29 15:56:06 2004 for OpenSim by doxygen 1.3.6