Skip to content

Commit

Permalink
Fix bug with fixed-length array columns in tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbernstein committed May 16, 2019
1 parent 2ef2512 commit d1484a9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions FTable2.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace img {
v.insert(v.begin()+insertBeforeRow, insertNumber, DT());
return v.size();
}

};

// Specialization for string-valued scalar arrays, check length as needed
Expand Down Expand Up @@ -359,7 +359,7 @@ namespace img {
v.resize(in.size());
for (long i=0; i<in.size(); i++)
writeCell(in[i], i);
}
}

virtual ColumnBase* duplicate() const {return new FixedArrayColumn(*this);}

Expand Down Expand Up @@ -399,8 +399,10 @@ namespace img {

virtual long writeCell(const vector<DT>& value, long row) {
checkWidth(value);
if (v.size() < row+1) v.resize(row+1);
v[row].reserve(width);
if (v.size() < row+1) {
// Fill out array with vectors of proper size
insertRows(v.size(), row-v.size());
}
// Use normal variable-length array writer
long out = Base::writeCell(value, row);
// Fill out cell with null values as needed to meet fixed array length
Expand All @@ -413,7 +415,7 @@ namespace img {
virtual long writeCells(const vector<vector<DT> >& values, long rowStart=0) {
// extend column to hold data
if (rowStart + values.size() > v.size())
v.resize(rowStart+values.size(), vector<DT>(width));
insertRows(v.size(), rowStart + values.size() - v.size());
for (int i=0; i<values.size(); i++)
writeCell(values[i], i+rowStart);
return v.size();
Expand All @@ -428,6 +430,13 @@ namespace img {
v.insert(v.begin()+insertBeforeRow, insertNumber, vector<DT>(width));
return v.size();
}

virtual void resize(long newSize) {
if (newSize > v.size())
insertRows(v.size(), newSize - v.size()); //growing
else if (newSize < v.size())
v.resize(newSize); // shrinking
}
};

class TableData {
Expand Down

0 comments on commit d1484a9

Please sign in to comment.