#include "RecordsParam.h" #include "../../src/dictionary/Field.h" #include "../../src/dictionary/DicRecord.h" const vector RecordsParam::fieldNames {"English", "Russian", "Finnish"}; RecordsParam::RecordsParam( vector packFields, vector > records, vector questions, vector > answers): packFields(packFields), questions(questions), answers(answers) { for(vector fieldValues: records) { DicRecord* record = new DicRecord; for(unsigned i = 0; i < fieldValues.size(); i++) record->setField(fieldNames[i].c_str(), fieldValues[i].c_str()); this->records << record; } } vector RecordsParam::hashToStrVector(const QHash& hash, const vector& keys) { vector res; for(unsigned i = 0; i < keys.size(); i++) res.push_back( hash[keys[i].c_str()].toStdString() ); return res; } vector RecordsParam::recordsToStr() const { vector res; for(DicRecord* record: records) { vector fieldValues = hashToStrVector(record->getFields(), fieldNames); res.push_back(string("(") + vectorToStr(fieldValues) + ")"); } return res; } ostream& operator<<(ostream& os, const RecordsParam& param) { os << "Fields(" << param.vectorToStr(param.packFields) << ") "; os << "{" << param.vectorToStr( param.recordsToStr() ) << "}"; return os; }