SummaryManager.cpp

00001 #include "SummaryManager.h"
00002 #include "SummaryWriter.h"
00003 #include "SctData/TestResult.h"
00004 #include "Sct/SctNames.h"
00005 #include "Sct/IoExceptions.h"
00006 #include "Sct/LogicErrors.h"
00007 #include <sstream>
00008 #include <iomanip>
00009 #include <cstdlib>
00010 #include <boost/date_time/posix_time/posix_time.hpp>
00011 
00012 using namespace Sct;
00013 using namespace boost;
00014 using namespace std;
00015 
00016 namespace SctData {
00017     namespace TestSummary{
00018     using boost::shared_ptr;
00019 
00020     SummaryManager::SummaryManager() {}
00021 
00022     SummaryManager::~SummaryManager() {}
00023 
00024     SummaryManager& SummaryManager::instance() throw () {
00025         static SummaryManager bertha;
00026         return bertha;
00027     }
00028 
00029     string SummaryManager::write(const TestResult& t) throw(IoError, LogicError) {
00030         ostringstream oss;
00031         write(t, oss);
00032         return oss.str();
00033     }
00034     
00035     void SummaryManager::write(const TestResult& t, ostream& stream) throw(IoError, LogicError) {
00036         shared_ptr<const SummaryWriter> writer = getWriter(t.getClassName());
00037         writer->writeHeader(t, stream);
00038         writer->write(t, stream);
00039     }
00040     
00041 /*  shared_ptr<ofstream> SummaryManager::getOutputFileStream(const string& modulename) const throw(Sct::IoError, Sct::LogicError) {
00042         using namespace boost::gregorian;
00043         std::ostringstream os;
00044         os << SctNames::getTempDir() << "/" << modulename << "_" << to_iso_string( date(day_clock::local_day() ) ) << ".txt" ;
00045         cout << "SummaryManager opening file " << os.str() << endl;
00046         shared_ptr<ofstream> file ( new ofstream( os.str().c_str() , ios::app ) );
00047         if (!file->is_open() ) throw FileException(os.str(), "SummaryManager can't open file", __FILE__, __LINE__);
00048         return file;
00049     }
00050     */
00051     shared_ptr<const SummaryWriter> SummaryManager::getWriter(const string& classname) const throw(Sct::LogicError) {
00052         WriterMap::const_iterator it = theMap.find(classname);
00053         if ( it == theMap.end() ){
00054         cerr << "SummaryManager::getWriter no writer for " << classname << endl;
00055         cerr << "known writers:" << endl ;
00056         for (WriterMap::const_iterator it = theMap.begin(); it != theMap.end(); ++it){
00057             cerr << (*it).first << endl;
00058         }
00059         throw InvalidArgumentError( string("SummaryManager::getWriter no writer for ") + classname, __FILE__, __LINE__ );
00060         } else {
00061         return (*it).second ;
00062         }
00063     }
00064 
00065     bool SummaryManager::addWriter(const string& testname, shared_ptr<SummaryWriter> writer) throw(Sct::LogicError) {
00066         if (theMap.find(testname) == theMap.end() ){
00067         theMap[testname] = writer;
00068         return true;
00069         }
00070         return false;
00071     }
00072 
00073     } // end of namespace TestSummary
00074 } // end of namespace SctData

Generated on Mon Feb 6 14:01:30 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6