eoFileMonitor.cpp

00001 #ifdef _MSC_VER
00002 // to avoid long name warnings
00003 #pragma warning(disable:4786)
00004 #endif 
00005 
00006 #include <iostream>
00007 #include <fstream>
00008 #include <stdexcept>
00009 
00010 #include <utils/eoFileMonitor.h>
00011 #include <utils/compatibility.h>
00012 #include <utils/eoParam.h>
00013 
00014 using namespace std;
00015 
00016 void eoFileMonitor::printHeader(std::ostream& os)
00017 {
00018     iterator it = vec.begin();
00019 
00020     os << (*it)->longName();
00021 
00022     ++it;
00023 
00024     for (; it != vec.end(); ++it)
00025     {
00026         os << delim.c_str() << (*it)->longName();
00027     }
00028     os << '\n';
00029 }
00030 
00031 void eoFileMonitor::printHeader()
00032 {
00033     // create file
00034     ofstream os(filename.c_str()); 
00035 
00036     if (!os)
00037     {
00038         string str = "eoFileMonitor: Could not open " + filename;
00039         throw runtime_error(str);
00040     }
00041     
00042     printHeader(os);
00043 }
00044 
00045 eoMonitor& eoFileMonitor::operator()(void)
00046 {
00047     ofstream os(filename.c_str(), ios_base::app);
00048 
00049     if (!os)
00050     {
00051         string str = "eoFileMonitor: Could not append to " + filename;
00052         throw runtime_error(str);
00053     }
00054 
00055     if (firstcall && !keep && header ){
00056       printHeader();
00057       firstcall = false;
00058     }
00059     
00060     return operator()(os);
00061 }
00062 
00063 eoMonitor& eoFileMonitor::operator()(std::ostream& os)
00064 {
00065     iterator it = vec.begin();
00066 
00067     os << (*it)->getValue();
00068     
00069     for(++it; it != vec.end(); ++it)
00070     {
00071         os << delim.c_str() << (*it)->getValue();
00072     }
00073 
00074     os << '\n';
00075     return *this;
00076 }
00077 

Generated on Thu Oct 19 05:06:35 2006 for EO by  doxygen 1.3.9.1