/* * SpecificFragmentController_impl.hpp * * Created on: Aug 27, 2012 * Author: heber */ #ifndef SPECIFICFRAGMENTCONTROLLER_IMPL_HPP_ #define SPECIFICFRAGMENTCONTROLLER_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "SpecificFragmentController.hpp" #include "CodePatterns/Assert.hpp" #include "CodePatterns/toString.hpp" template void SpecificFragmentController::getResults(std::map &IdData) { // receive receiveResults(host, port); RunService("Requesting results"); std::vector fragmentresults = getReceivedResults(); // convert std::vector fragmentData; ConvertFragmentResultTo(fragmentresults, fragmentData); // put into map IdData.clear(); std::vector::const_iterator resultiter = fragmentresults.begin(); typename std::vector::const_iterator dataiter = fragmentData.begin(); for(;resultiter != fragmentresults.end(); ++resultiter, ++dataiter) { #ifndef NDEBUG std::pair::iterator, bool> inserter = #endif IdData.insert( std::make_pair( (*resultiter)->getId(), *dataiter) ); ASSERT( inserter.second, "SpecificFragmentController::getResults() - result id " +toString(inserter.first->first)+" already present."); } ASSERT( dataiter == fragmentData.end(), "SpecificFragmentController::getResults() - fragmentresults and fragmentdata differ in size."); } template void SpecificFragmentController::ConvertFragmentResultTo( const std::vector &results, std::vector &fragmentData) { // extract results fragmentData.clear(); fragmentData.reserve(results.size()); LOG(2, "DEBUG: Parsing now through " << results.size() << " results."); for (std::vector::const_iterator iter = results.begin(); iter != results.end(); ++iter) { //LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result)); T extractedData; std::stringstream inputstream((*iter)->result); LOG(2, "DEBUG: First 50 characters FragmentResult's string: "+(*iter)->result.substr(0, 50)); boost::archive::text_iarchive ia(inputstream); ia >> extractedData; LOG(1, "INFO: extracted data is " << extractedData << "."); fragmentData.push_back(extractedData); } ASSERT( results.size() == fragmentData.size(), "ConvertFragmentResultTo() - the number of extracted data differs from the number of results."); } #endif /* SPECIFICFRAGMENTCONTROLLER_IMPL_HPP_ */