00001 #include "ScanWriterFactory.h" 00002 #include "ScanResultWriter.h" 00003 #include "ScanDataWriter.h" 00004 #include "Sct/IoExceptions.h" 00005 #include <sstream> 00006 00007 using namespace std; 00008 00009 namespace SctData { 00010 00011 ScanWriterFactory::ScanWriterFactory() {} 00012 00013 00014 ScanWriterFactory& ScanWriterFactory::getFactory() { 00015 static ScanWriterFactory* bertha = new ScanWriterFactory(); 00016 return *bertha; 00017 } 00018 00019 bool ScanWriterFactory::addWriterToMap(UINT16 dataType, ScanResultWriter& resultWriter, ScanDataWriter& dataWriter) { 00020 if (writerMap.find(dataType) != writerMap.end()) return false; 00021 writerMap[dataType] = pair<ScanResultWriter*, ScanDataWriter*>(&resultWriter, &dataWriter); 00022 return true; 00023 } 00024 00025 ScanDataWriter& ScanWriterFactory::getDataWriter(UINT16 dataType) { 00026 if (getFactory().writerMap.find(dataType) == getFactory().writerMap.end()) { 00027 std::ostringstream oss; 00028 oss << "No ScanDataWriter for dataType: " << dataType; 00029 throw Sct::NoSuchStreamerException("ScanHeader.dataType", oss.str(), __FILE__, __LINE__); 00030 } 00031 return *(getFactory().writerMap[dataType].second); 00032 } 00033 00034 ScanResultWriter& ScanWriterFactory::getResultWriter(UINT16 dataType) { 00035 if (getFactory().writerMap.find(dataType) == getFactory().writerMap.end()) { 00036 std::ostringstream oss; 00037 oss << "No ScanResultWriter for dataType: " << dataType; 00038 throw Sct::NoSuchStreamerException("ScanHeader.dataType", oss.str(), __FILE__, __LINE__); 00039 } 00040 return *(getFactory().writerMap[dataType].first); 00041 } 00042 00043 00044 }