Newer
Older
#include "SubConfig.hpp"
SubConfig::SubConfig(BaseConfig & model) : Config(model.rawInput), model(model)
{
wordIndex = model.wordIndex;
characterIndex = model.characterIndex;
state = model.state;
history = model.history;
update();
}
bool SubConfig::needsUpdate()
{
return wordIndex-firstLineIndex >= 0.8*getNbLines();
}
{
unsigned int currentLastLineIndex = firstLineIndex + getNbLines();
if (currentLastLineIndex >= model.getNbLines()-1)
std::size_t newFirstLineIndex = spanSize/2 >= wordIndex ? 0 : wordIndex - spanSize/2;
std::size_t newLastLineIndex = std::min(newFirstLineIndex + spanSize, model.getNbLines());
unsigned int newLineNumber = newLastLineIndex - newFirstLineIndex;
if (getNbLines() < newLineNumber)
resizeLines(newLineNumber);
// The two windows are disjoint, we must copy every value from model
if (currentLastLineIndex <= newFirstLineIndex or newLastLineIndex <= firstLineIndex)
{
auto linesBegin = getIterator(0, firstLineIndex, 0);
auto firstToSave = model.getConstIterator(0, newFirstLineIndex, 0);
auto lastToSave = model.getConstIterator(0, newLastLineIndex, 0);
while (firstToSave != lastToSave)
*linesBegin++ = *firstToSave++;
} // The new window is a bit shifted to the right, we will keep the lasts elements from old window
else if (currentLastLineIndex > newFirstLineIndex and currentLastLineIndex < newLastLineIndex)
{
auto linesBegin = getIterator(0, firstLineIndex, 0);
auto firstToSave = getConstIterator(0, newFirstLineIndex, 0);
auto lastToSave = getConstIterator(0, currentLastLineIndex, 0);
while (firstToSave != lastToSave)
*linesBegin++ = *firstToSave++;
firstToSave = model.getConstIterator(0, currentLastLineIndex, 0);
lastToSave = model.getConstIterator(0, newLastLineIndex, 0);
while (firstToSave != lastToSave)
*linesBegin++ = *firstToSave++;
} // If the two windows are the same, do nothing.
else if (firstLineIndex == newFirstLineIndex and currentLastLineIndex == newLastLineIndex)
{
}
else
{
util::myThrow("Update after a regression of wordIndex is not yet supported !");
}
if (getNbLines() > newLineNumber)
resizeLines(newLineNumber);
firstLineIndex = newFirstLineIndex;
}
std::size_t SubConfig::getNbColumns() const
{
return model.getNbColumns();
}
std::size_t SubConfig::getColIndex(const std::string & colName) const
{
return model.getColIndex(colName);
}
bool SubConfig::hasColIndex(const std::string & colName) const
{
const std::string & SubConfig::getColName(int colIndex) const
{
return model.getColName(colIndex);
}
std::size_t SubConfig::getFirstLineIndex() const
{
return firstLineIndex;
}