StreamOutput.cpp

00001 #include "StreamOutput.h"
00002 
00003 #include <string>
00004 #include <ctime>
00005 #include <sys/types.h>
00006 #include <unistd.h>
00007 #include <iostream>
00008 #include <fstream>
00009 
00010 using namespace std;
00011 
00015 StreamOutput::StreamOutput()
00016 {
00017     m_name = "";
00018     m_enableOutput = 1;
00019     m_enableFileOutput = 1;
00020 }
00021 
00025 StreamOutput::~StreamOutput()
00026 {
00027 
00028 }
00029 
00036 void StreamOutput::setOutputFile ( string s )
00037 {
00038     if ( m_enableOutput )
00039     {
00040         if ( s == "" )
00041             cout<<"Clear output file for cout"<<endl;
00042         else
00043             cout<<"Output File for cout redirect is set now to "<<s<<endl;
00044     }
00045     m_name = s;
00046 }
00047 
00048 StreamOutput& StreamOutput::operator << ( const char* s )
00049 {
00050     if ( m_enableOutput )
00051     {
00052         cout<<s;
00053         if ( m_name!="" && m_enableFileOutput )
00054         {
00055             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00056             f<<s;
00057             f.close();
00058         }
00059     }
00060     return ( *this );
00061 }
00062 
00063 StreamOutput& StreamOutput::operator << ( char* s )
00064 {
00065     if ( m_enableOutput )
00066     {
00067         cout<<s;
00068         if ( m_name!="" && m_enableFileOutput )
00069         {
00070             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00071             f<<s;
00072             f.close();
00073         }
00074     }
00075     return ( *this );
00076 }
00077 
00078 StreamOutput& StreamOutput::operator << ( char s )
00079 {
00080     if ( m_enableOutput )
00081     {
00082         cout<<s;
00083         if ( m_name!="" && m_enableFileOutput )
00084         {
00085             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00086             f<<s;
00087             f.close();
00088         }
00089     }
00090     return ( *this );
00091 }
00092 
00093 StreamOutput& StreamOutput::operator << ( int s )
00094 {
00095     if ( m_enableOutput )
00096     {
00097         cout<<s;
00098         if ( m_name!="" && m_enableFileOutput )
00099         {
00100             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00101             f<<s;
00102             f.close();
00103         }
00104     }
00105     return ( *this );
00106 }
00107 
00108 StreamOutput& StreamOutput::operator << ( unsigned long s )
00109 {
00110     if ( m_enableOutput )
00111     {
00112         cout<<s;
00113         if ( m_name!="" && m_enableFileOutput )
00114         {
00115             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00116             f<<s;
00117             f.close();
00118         }
00119     }
00120     return ( *this );
00121 }
00122 
00123 StreamOutput& StreamOutput::operator << ( double s )
00124 {
00125     if ( m_enableOutput )
00126     {
00127         cout<<s;
00128         if ( m_name!="" && m_enableFileOutput )
00129         {
00130             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00131             f<<s;
00132             f.close();
00133         }
00134     }
00135     return ( *this );
00136 }
00137 
00138 StreamOutput& StreamOutput::operator << ( double* s )
00139 {
00140     if ( m_enableOutput )
00141     {
00142         cout<<s;
00143         if ( m_name!="" && m_enableFileOutput )
00144         {
00145             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00146             f<<s;
00147             f.close();
00148         }
00149     }
00150     return ( *this );
00151 }
00152 
00153 StreamOutput& StreamOutput::operator << ( float s )
00154 {
00155     if ( m_enableOutput )
00156     {
00157         cout<<s;
00158         if ( m_name!="" && m_enableFileOutput )
00159         {
00160             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00161             f<<s;
00162             f.close();
00163         }
00164     }
00165     return ( *this );
00166 }
00167 
00168 StreamOutput& StreamOutput::operator << ( float* s )
00169 {
00170     if ( m_enableOutput )
00171     {
00172         cout<<s;
00173         if ( m_name!="" && m_enableFileOutput )
00174         {
00175             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00176             f<<s;
00177             f.close();
00178         }
00179     }
00180     return ( *this );
00181 }
00182 
00183 StreamOutput& StreamOutput::operator << ( time_t s )
00184 {
00185     if ( m_enableOutput )
00186     {
00187         cout<<s;
00188         if ( m_name!="" && m_enableFileOutput )
00189         {
00190             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00191             f<<s;
00192             f.close();
00193         }
00194     }
00195     return ( *this );
00196 }
00197 
00198 StreamOutput& StreamOutput::operator << ( unsigned int s )
00199 {
00200     if ( m_enableOutput )
00201     {
00202         cout<<s;
00203         if ( m_name!="" && m_enableFileOutput )
00204         {
00205             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00206             f<<s;
00207             f.close();
00208         }
00209     }
00210     return ( *this );
00211 }
00212 
00213 StreamOutput& StreamOutput::operator << ( string s )
00214 {
00215     if ( m_enableOutput )
00216     {
00217         cout<<s;
00218         if ( m_name!="" && m_enableFileOutput )
00219         {
00220             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00221             f<<s;
00222             f.close();
00223         }
00224     }
00225     return ( *this );
00226 }
00227 
00231 StreamOutput& StreamOutput::operator << ( ostream& ( *s ) ( ostream& ) )
00232 {
00233     if ( m_enableOutput )
00234     {
00235         cout<<s;
00236         if ( m_name!="" && m_enableFileOutput )
00237         {
00238             fstream f ( m_name.c_str(), ios::out|ios::app|ios::ate );
00239             f<<s;
00240             f.close();
00241         }
00242     }
00243     return ( *this );
00244 }
00245 
00249 void StreamOutput::disableAllOutputs()
00250 {
00251     m_enableOutput = 0;
00252     m_enableFileOutput = 0;
00253 }
00254 
00258 void StreamOutput::disableFileOutputs()
00259 {
00260     cout<<"Disable file outputs"<<endl;
00261     m_enableFileOutput = 0;
00262 }
00263 
00267 void StreamOutput::enableAllOutputs()
00268 {
00269     m_enableOutput = 1;
00270     m_enableFileOutput = 1;
00271 }

Generated on Tue Jan 26 09:20:59 2010 for ELF by  doxygen 1.5.8