00001 #ifndef SCTDATA_DEFECTIOHELPER_H
00002 #define SCTDATA_DEFECTIOHELPER_H
00003
00004 #include "DefectPrototype.h"
00005 #include "Sct/LogicErrors.h"
00006 #include "Sct/SctNames.h"
00007 #include <sstream>
00008
00009 namespace SctData {
00010 class DefectIOHelper {
00011 public:
00016 int getRepresentation(const DefectPrototype& defect) const;
00017
00022 const DefectPrototype& getFromRep(int id) const;
00023 };
00024
00025
00026 inline int DefectIOHelper::getRepresentation(const DefectPrototype& defect) const {
00027 return defect.id;
00028 }
00029
00030 inline const DefectPrototype& DefectIOHelper::getFromRep(int id) const {
00031 if (DefectPrototype::getMap().find(id)==DefectPrototype::getMap().end() ){
00032
00033 const std::map<int, DefectPrototype*>& theMap=DefectPrototype::getMap();
00034 std::ostringstream oss1;
00035 oss1 << "There are " << theMap.size() << " known DefectPrototypes:" << std::endl;
00036 for (std::map<int, DefectPrototype*>::const_iterator it = theMap.begin();
00037 it!=theMap.end();
00038 ++it){
00039 oss1 << (*it).first << " -> " << (*it).second->getName() << std::endl;
00040 }
00041 Sct::SctNames::Mrs() << "SCT_IO" << MRS_TEXT(oss1.str()) << MRS_DIAGNOSTIC << ENDM;
00042
00043 std::ostringstream os; os<<"DefectIOHelper::getFromRep : no representation "<<id;
00044 throw Sct::InvalidArgumentError(os.str(), __FILE__, __LINE__);
00045 }
00046 return *DefectPrototype::getMap()[id];
00047 }
00048
00049 }
00050 #endif //#ifndef SCTDATA_DEFECTIOHELPER_H