MsgCatStream Class Reference

#include <MsgCatStream.h>

List of all members.

Public Member Functions

 MsgCatStream ()
 MsgCatStream (const char *fileName)
 ~MsgCatStream ()
const char * GetOutputFileName () const
void SetOutputFile (const char *filename)
void AddFileToList (const char *filename)
void DoConcatenation ()

Private Attributes

string fOutFile
vector< string > fFileList

Friends

ostream & operator<< (ostream &os, const MsgCatStream &m)

Detailed Description

Definition at line 30 of file MsgCatStream.h.


Constructor & Destructor Documentation

MsgCatStream::MsgCatStream (  ) 

Definition at line 41 of file MsgCatStream.cxx.

00041 : fOutFile("") { }

MsgCatStream::MsgCatStream ( const char *  fileName  ) 

Definition at line 45 of file MsgCatStream.cxx.

00045 : fOutFile(fileName) { }

MsgCatStream::~MsgCatStream (  ) 

Definition at line 49 of file MsgCatStream.cxx.

00049 { }


Member Function Documentation

void MsgCatStream::AddFileToList ( const char *  filename  ) 

Definition at line 53 of file MsgCatStream.cxx.

References fFileList.

Referenced by MsgService::AddCatStream().

00054 {
00055 //======================================================================
00056 // Purpose: Add a file to the list of files to be concatenated
00057 // Inputs: filename - the name of the file that will be concatenated
00058 //======================================================================
00059   string aName(filename);
00060   fFileList.push_back(aName); 
00061 }

void MsgCatStream::DoConcatenation (  ) 

Definition at line 65 of file MsgCatStream.cxx.

References fFileList, and fOutFile.

00066 {
00067 //======================================================================
00068 // Purpose: Concatenate the contents of the files in the fFileList list
00069 //          to a single output file fOutFile. The files in the fFileList
00070 //          *are deleted* once their contents have been copied to 
00071 //          fOutFile
00072 //======================================================================
00073   // Open the output file
00074   ofstream outFile(fOutFile.c_str());
00075   if (!outFile) {
00076     cerr << "=E= " << __FILE__ << ":" << __LINE__ 
00077          << " Can't open file " << fOutFile 
00078          << " for write."
00079          << " Concatenation not performed\n";
00080     return;
00081   }
00082 
00083   // Append the contents of each file in the list to outFile and
00084   // delete the file
00085   vector<string>::iterator vend(fFileList.end());
00086   for (vector<string>::iterator itrMsgName = fFileList.begin();
00087        itrMsgName != vend;
00088        ++itrMsgName) {
00089     ifstream *inFile;
00090     inFile = new ifstream(itrMsgName->c_str());
00091     if ((*inFile)) {
00092       char ch;
00093       while (inFile->get(ch)) outFile.put(ch);
00094       delete inFile;
00095       if ( unlink(itrMsgName->c_str()) != 0) {
00096         cerr << "=W= " << __FILE__ << ":" << __LINE__
00097              << "Failed to unlink file '" 
00098              << (*itrMsgName) << "'.\n";
00099       }
00100     }
00101     else {
00102       // Input stream didn't open correctly
00103       cerr << "=E= " << __FILE__ << ":" << __LINE__ 
00104            << " Can't open file " << (*itrMsgName)
00105            << " for read."
00106            << " File skipped\n";      
00107       continue;
00108     }
00109   }
00110 }

const char* MsgCatStream::GetOutputFileName (  )  const [inline]

Definition at line 38 of file MsgCatStream.h.

References fOutFile.

00038 { return fOutFile.c_str(); }

void MsgCatStream::SetOutputFile ( const char *  filename  )  [inline]

Definition at line 40 of file MsgCatStream.h.

References fOutFile.

00040 {fOutFile = filename; }


Friends And Related Function Documentation

ostream& operator<< ( ostream &  os,
const MsgCatStream m 
) [friend]

Member Data Documentation

vector<string> MsgCatStream::fFileList [private]

Definition at line 45 of file MsgCatStream.h.

Referenced by AddFileToList(), DoConcatenation(), and operator<<().

string MsgCatStream::fOutFile [private]

Definition at line 44 of file MsgCatStream.h.

Referenced by DoConcatenation(), GetOutputFileName(), operator<<(), and SetOutputFile().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1