NamedFileStream.h

Go to the documentation of this file.
00001 
00006 /* Copyright (C) 2003, Bernd Speiser */
00007 /* This file is part of BSUtilities.
00008 
00009 BSUtilities is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 BSUtilities is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018   
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00022 02111-1307, USA.
00023 */
00024 
00025 #ifndef _NamedFileStream_h
00026 #define _NamedFileStream_h
00027 
00028 #include<string>
00029 #include<fstream>
00030 
00031 namespace BSUtilities {
00032 
00033 class NamedIFileStream : public std::ifstream
00034 {
00035     private:
00036 
00037       std::string _filename;
00038 
00039     public:
00040 
00041       NamedIFileStream (void);
00042 
00043       ~NamedIFileStream (void);
00044 
00045       void open 
00046            (const std::string & filename, std::ios_base::openmode mode);
00047 
00048       void open (const char *filename, std::ios_base::openmode mode);
00049 
00050       std::string name (void);
00051 };
00052 
00053 NamedIFileStream::NamedIFileStream (void) {}
00054 
00055 NamedIFileStream::~NamedIFileStream (void) {}
00056 
00057 void NamedIFileStream::open 
00058   (const std::string &filename, 
00059                               std::ios_base::openmode mode=std::ios::in)
00060   {
00061     std::ifstream::open (filename.c_str (), mode | std::ios::in);
00062 
00063     _filename = filename;
00064   }
00065 
00066 void NamedIFileStream::open 
00067        (const char *filename, std::ios_base::openmode mode=std::ios::in)
00068   {
00069     std::ifstream::open (filename, mode | std::ios::in);
00070 
00071     _filename = filename;
00072   }
00073 
00074 inline std::string NamedIFileStream::name (void) {return _filename;}
00075 
00076 class NamedOFileStream : public std::ofstream
00077 {
00078     private:
00079 
00080       std::string _filename;
00081 
00082     public:
00083 
00084       NamedOFileStream (void);
00085 
00086       ~NamedOFileStream (void);
00087 
00088       void open 
00089             (const std::string &filename, std::ios_base::openmode mode);
00090 
00091       void open (const char *filename, std::ios_base::openmode mode);
00092 
00093       std::string name (void);
00094 };
00095 
00096 NamedOFileStream::NamedOFileStream (void) {}
00097 
00098 NamedOFileStream::~NamedOFileStream (void) {}
00099 
00100 void NamedOFileStream::open 
00101    (const std::string &filename, 
00102                              std::ios_base::openmode mode=std::ios::out)
00103   {
00104     std::ofstream::open (filename.c_str (), mode | std::ios::out);
00105 
00106     _filename = filename;
00107   }
00108 
00109 void NamedOFileStream::open 
00110       (const char *filename, std::ios_base::openmode mode=std::ios::out)
00111   {
00112     std::ofstream::open (filename, mode | std::ios::out);
00113 
00114     _filename = filename;
00115   }
00116 
00117 inline std::string NamedOFileStream::name (void) {return _filename;}
00118 
00119 }
00120 
00121 #endif /* _NamedFileStream_h */

Generated on Sun Jul 26 16:51:58 2009 for BSUtilities by  doxygen 1.5.3