From a1fc02b9300152c31601ccc91cb8acb385aa4791 Mon Sep 17 00:00:00 2001 From: Franck Dary <franck.dary@lis-lab.fr> Date: Sat, 21 Mar 2020 12:47:31 +0100 Subject: [PATCH] Added some error messages in Config::get --- reading_machine/src/Config.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/reading_machine/src/Config.cpp b/reading_machine/src/Config.cpp index 24612ff..902b1cd 100644 --- a/reading_machine/src/Config.cpp +++ b/reading_machine/src/Config.cpp @@ -216,6 +216,8 @@ void Config::printForDebug(FILE * dest) const Config::String & Config::getLastNotEmpty(int colIndex, int lineIndex) { + if (!has(colIndex, lineIndex, 0)) + util::myThrow(fmt::format("asked for line {} but nbLines = {}", lineIndex, getNbLines())); int baseIndex = getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex); for (int i = nbHypothesesMax; i > 0; --i) @@ -227,6 +229,8 @@ Config::String & Config::getLastNotEmpty(int colIndex, int lineIndex) Config::String & Config::getLastNotEmptyHyp(int colIndex, int lineIndex) { + if (!has(colIndex, lineIndex, 0)) + util::myThrow(fmt::format("asked for line {} but nbLines = {}", lineIndex, getNbLines())); int baseIndex = getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex); for (int i = nbHypothesesMax; i > 0; --i) @@ -238,6 +242,8 @@ Config::String & Config::getLastNotEmptyHyp(int colIndex, int lineIndex) Config::String & Config::getFirstEmpty(int colIndex, int lineIndex) { + if (!has(colIndex, lineIndex, 0)) + util::myThrow(fmt::format("asked for line {} but nbLines = {}", lineIndex, getNbLines())); int baseIndex = getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex); for (int i = 1; i < nbHypothesesMax; ++i) @@ -254,6 +260,8 @@ Config::String & Config::getFirstEmpty(const std::string & colName, int lineInde const Config::String & Config::getLastNotEmptyConst(int colIndex, int lineIndex) const { + if (!has(colIndex, lineIndex, 0)) + util::myThrow(fmt::format("asked for line {} but nbLines = {}", lineIndex, getNbLines())); int baseIndex = getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex); for (int i = nbHypothesesMax; i > 0; --i) @@ -265,6 +273,8 @@ const Config::String & Config::getLastNotEmptyConst(int colIndex, int lineIndex) const Config::String & Config::getLastNotEmptyHypConst(int colIndex, int lineIndex) const { + if (!has(colIndex, lineIndex, 0)) + util::myThrow(fmt::format("asked for line {} but nbLines = {}", lineIndex, getNbLines())); int baseIndex = getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex); for (int i = nbHypothesesMax; i > 0; --i) @@ -309,11 +319,15 @@ const Config::String & Config::getLastNotEmptyHypConst(const std::string & colNa Config::ValueIterator Config::getIterator(int colIndex, int lineIndex, int hypothesisIndex) { + if (!has(colIndex, lineIndex, 0)) + util::myThrow(fmt::format("asked for line {} but nbLines = {}", lineIndex, getNbLines())); return lines.begin() + getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex) + hypothesisIndex; } Config::ConstValueIterator Config::getConstIterator(int colIndex, int lineIndex, int hypothesisIndex) const { + if (!has(colIndex, lineIndex, 0)) + util::myThrow(fmt::format("asked for line {} but nbLines = {}", lineIndex, getNbLines())); return lines.begin() + getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex) + hypothesisIndex; } -- GitLab