Debian Codegraph @

yo/classtemplates/examples/table/tabletype/init.cc

raw
1 #include "tabletype.ih"
2
3 void TableType::init()
4 {
5 if (!d_string.size()) // no elements
6 return; // then do nothing
7
8 d_nRows = (d_string.size() + d_nColumns - 1) / d_nColumns;
9 d_string.resize(d_nRows * d_nColumns); // enforce complete table
10
11 // determine max width per column,
12 // and max column width
13 for (size_t col = 0; col < d_nColumns; col++)
14 {
15 size_t width = 0;
16 for (size_t row = 0; row < d_nRows; row++)
17 {
18 size_t len = stringAt(row, col).length();
19 if (width < len)
20 width = len;
21 }
22 d_colWidth[col] = width;
23
24 if (d_maxWidth < width) // max. width so far.
25 d_maxWidth = width;
26 }
27 }