EvolvingObjects
eoFileMonitor.h
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // eoFileMonitor.h
00005 // (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000
00006 /*
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
00022              Marc.Schoenauer@polytechnique.fr
00023              mkeijzer@dhi.dk
00024  */
00025 //-----------------------------------------------------------------------------
00026 
00027 #ifndef EO_eoFileMonitor_h
00028 #define EO_eoFileMonitor_h
00029 
00030 #include <string>
00031 #include <fstream>
00032 #include <stdexcept>
00033 
00034 #include "utils/eoMonitor.h"
00035 #include "eoObject.h"
00036 
00037 
00046 class eoFileMonitor : public eoMonitor
00047 {
00048 public :
00049 
00060     eoFileMonitor(
00061         std::string _filename,
00062         std::string _delim = " ",
00063         bool _keep_existing = false,
00064         bool _header = false,
00065         bool _overwrite = false
00066         )
00067         : filename(_filename),
00068         delim(_delim),
00069         keep(_keep_existing),
00070         header(_header),
00071         firstcall(true),
00072         overwrite(_overwrite)
00073     {
00074         if (!_keep_existing) {
00075             std::ofstream os (filename.c_str ());
00076 
00077             if (!os) {
00078                 std::string str = "Error, eoFileMonitor could not open: " + filename;
00079                 throw std::runtime_error (str);
00080             }
00081         } // if ! keep
00082     }
00083 
00085     virtual eoMonitor& operator()(void);
00086 
00090     virtual eoMonitor& operator()(std::ostream& os);
00091 
00093     void printHeader(void);
00094 
00096     virtual void printHeader(std::ostream& os);
00097 
00098     virtual std::string getFileName() { return filename;}
00099 
00100 private :
00101 
00103     std::string filename;
00104 
00106     std::string delim;
00107 
00109     bool keep;
00110 
00112     bool header;
00113 
00115     bool firstcall;
00116 
00118     bool overwrite;
00119 };
00120 
00121 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends