/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus * * MAUS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MAUS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MAUS. If not, see . * */ #ifndef _SRC_COMMON_CPP_API_MAPBASE_INL_ #define _SRC_COMMON_CPP_API_MAPBASE_INL_ #include #include "src/common_cpp/API/APIExceptions.hh" #include "src/legacy/Interface/Squeal.hh" #include "src/common_cpp/Utils/CppErrorHandler.hh" #include "src/common_cpp/Converter/ConverterFactory.hh" namespace MAUS { template MapBase::MapBase(const std::string& s) : IMap(), ModuleBase(s) {} template MapBase::MapBase(const std::string& s) : IMap(), ModuleBase(s) {} template MapBase::MapBase(const MapBase& mb) : IMap(), ModuleBase(mb._classname) {} template MapBase::MapBase(const MapBase& mb) : IMap(), ModuleBase(mb._classname) {} template MapBase::~MapBase() {} template MapBase::~MapBase() {} template OUTPUT* MapBase::process(INPUT* i) const { if (!i) { throw NullInputException(_classname); } OUTPUT* o = 0; try { o = _process(i); } catch(Squeal& s) { CppErrorHandler::getInstance()->HandleSquealNoJson(s, _classname); } catch(std::exception& e) { CppErrorHandler::getInstance()->HandleStdExcNoJson(e, _classname); } catch(...) { throw UnhandledException(_classname); } return o; } template OUTPUT* MapBase::process(Json::Value* i) const { if (!i) { throw NullInputException(_classname); } OUTPUT* o = 0; try { o = _process(i); } catch(Squeal& s) { CppErrorHandler::getInstance()->HandleSqueal(*i, s, _classname); } catch(std::exception& e) { CppErrorHandler::getInstance()->HandleStdExc(*i, e, _classname); } catch(...) { throw UnhandledException(_classname); } return o; } template template OUTPUT* MapBase::process(OTHER* o) const { ConverterFactory c; INPUT* tmp = 0; OUTPUT* ret = 0; try { tmp = c.convert(o); ret = process(tmp); } catch(std::exception& e) { if (tmp) { delete tmp; } CppErrorHandler::getInstance()->HandleStdExcNoJson(e, _classname); return ret; } // catch the pass through case if (reinterpret_cast(tmp) != reinterpret_cast(o) && reinterpret_cast(tmp) != reinterpret_cast(ret) ) { delete tmp; } return ret; } template template OUTPUT* MapBase::process(OTHER* o) const { ConverterFactory c; Json::Value* tmp; OUTPUT* ret; try { tmp = c.convert(o); ret = process(tmp); } catch(std::exception& e) { if (tmp) { delete tmp; } CppErrorHandler::getInstance()->HandleStdExcNoJson(e, _classname); return ret; } // catch the pass through case if (reinterpret_cast(tmp) != reinterpret_cast(o) && reinterpret_cast(tmp) != reinterpret_cast(ret) ) { delete tmp; } return ret; } }// end of namespace #endif