MsgOStreamService Class Reference

#include <MsgOStreamService.h>

List of all members.

Public Types

typedef MsgOStream *(* MsgOStreamMaker_t )(const char *)

Public Member Functions

 ~MsgOStreamService ()
MsgOStreamGetStream (const char *streamName)
void Register (MsgOStreamMaker_t msgOStreamMaker)

Static Public Member Functions

static MsgOStreamServiceInstance ()

Private Member Functions

 MsgOStreamService ()

Private Attributes

map< string, MsgOStream * > fMsgOStreamTable
list< MsgOStreamMaker_tfMsgOStreamMakerList

Static Private Attributes

static MsgOStreamServicefInstance = 0

Detailed Description

Definition at line 32 of file MsgOStreamService.h.


Member Typedef Documentation

Definition at line 35 of file MsgOStreamService.h.


Constructor & Destructor Documentation

MsgOStreamService::~MsgOStreamService (  ) 

Definition at line 20 of file MsgOStreamService.cxx.

References fMsgOStreamTable.

00021 {
00022   // Delete all the MsgOStreams pointed to in the table
00023   map<std::string,MsgOStream*>::iterator mend (fMsgOStreamTable.end());
00024   for (map<std::string,MsgOStream*>::iterator i = fMsgOStreamTable.begin();
00025        i != mend;
00026        ++i) {
00027     delete i->second;
00028   }
00029 }

MsgOStreamService::MsgOStreamService (  )  [inline, private]

Definition at line 44 of file MsgOStreamService.h.

Referenced by Instance().

00044 { }              // This class is a singleton


Member Function Documentation

MsgOStream * MsgOStreamService::GetStream ( const char *  streamName  ) 

Definition at line 33 of file MsgOStreamService.cxx.

References MsgOStream::AddReference(), fMsgOStreamMakerList, and fMsgOStreamTable.

Referenced by MsgStream::AttachOStream(), MsgOStreamServiceValidate::TestMsgCustonStream(), and MsgOStreamServiceValidate::TestMsgOStreamService().

00034 {
00035 //======================================================================
00036 // Purpose: Find a named message output stream. If the stream does not 
00037 //          exist it is created
00038 //
00039 // Inputs: streamName - the name of the stream I want
00040 //
00041 // Returns: The message output stream
00042 //======================================================================
00043 
00044   // Look for the stream in the stream map
00045   std::string msgStreamName(streamName);
00046   MsgOStream *msgOStream = fMsgOStreamTable[msgStreamName];
00047 
00048   // If the stream does not already exist then create it
00049   if (msgOStream == 0) {
00050 
00051     // Test if the user has supplied a definition for this stream
00052     if (!fMsgOStreamMakerList.empty()) {
00053       list<MsgOStreamMaker_t>::iterator lend(fMsgOStreamMakerList.end());
00054       for (list<MsgOStreamMaker_t>::iterator itr=fMsgOStreamMakerList.begin();
00055            itr != lend;
00056            ++itr) {
00057         msgOStream = (*itr)(streamName);
00058         if (msgOStream) break; // Done
00059       }
00060     }
00061 
00062     // No user definition: test if its one of the standard streams
00063     if (!msgOStream) {
00064       if (strcmp(streamName, "cout")==0 || 
00065           strcmp(streamName, "cerr")==0 ||
00066           strcmp(streamName, "clog")==0) {
00067         // Create a using one of the standard streams
00068         msgOStream = new MsgStandardOStream(streamName);
00069       }
00070     }
00071 
00072     // No user definition and its not a standard stream: Supply an
00073     // output file stream
00074     if (msgOStream == 0) {
00075       // Create a file stream with "streamName" as the name
00076       // This is hard-wired to clobber any existing files -- could be 
00077       // more flexible
00078       msgOStream = new MsgFileOStream(streamName, ios::out);
00079     }
00080     // By now we *must* have a valid MsgOStream
00081     assert(msgOStream);
00082 
00083     // Add to list of known streams
00084 
00085     fMsgOStreamTable[msgStreamName] = msgOStream;
00086   }
00087 
00088   // Log a new client of this OStream
00089   msgOStream->AddReference();
00090 
00091   return msgOStream;
00092 }

MsgOStreamService * MsgOStreamService::Instance (  )  [static]

Definition at line 96 of file MsgOStreamService.cxx.

References fInstance, and MsgOStreamService().

Referenced by MsgStream::AttachOStream(), MsgG4OStreamRegistrar::MsgG4OStreamRegistrar(), MsgOStreamServiceValidate::TestMsgCustonStream(), and MsgOStreamServiceValidate::TestMsgOStreamService().

00097 {
00098 //======================================================================
00099 // Purpose: Return a pointer to the sole instance of the 
00100 //          MsgOStreamService
00101 //======================================================================  
00102   if (fInstance == 0) fInstance = new MsgOStreamService();
00103   return fInstance;
00104 }

void MsgOStreamService::Register ( MsgOStreamMaker_t  msgOStreamMaker  ) 

Definition at line 108 of file MsgOStreamService.cxx.

References fMsgOStreamMakerList.

00109 {
00110 //=======================================================================
00111 // Purpose: Register the routine msgOStreamMaker as one of the possible
00112 //          routines that can make MsgOStreams
00113 // Inputs: msgOStreamMaker: A routine name of type MsgOStreamMaker_t
00114 //=======================================================================
00115   fMsgOStreamMakerList.push_front(msgOStreamMaker);
00116 }


Member Data Documentation

Definition at line 45 of file MsgOStreamService.h.

Referenced by Instance().

Definition at line 49 of file MsgOStreamService.h.

Referenced by GetStream(), and Register().

Definition at line 48 of file MsgOStreamService.h.

Referenced by GetStream(), and ~MsgOStreamService().


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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1