File: def.cc

package info (click to toggle)
bobcat 2.08.01-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,668 kB
  • ctags: 953
  • sloc: cpp: 10,403; makefile: 9,042; perl: 401; sh: 195
file content (46 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "tablebase.ih"

void TableBase::def()
{
    if (d_tabulated || !d_string.size())    // no elements or already 
        return;                             // tabulated then do nothing

    d_nRows = (d_string.size() + d_nColumns - 1) / d_nColumns;
    d_string.resize(d_nRows * d_nColumns);  // enforce complete table

                                            // determine max width per column,
                                            // max column width, and alignment
    size_t maxWidth = 0;
    
    for (size_t col = 0; col < d_nColumns; col++)
    {
        size_t maxColWidth = 0;
        for (size_t row = 0; row < d_nRows; row++)
        {
            Element &element = elementAt(row, col);

            size_t len = element.length();
            if (maxColWidth < len)
                maxColWidth = len;
        }
        d_align[col].setWidth(maxColWidth);

                                        // max. width so far.
        if (d_widthType == EQUALWIDTH && maxWidth < maxColWidth)
            maxWidth = maxColWidth;
    }

    if (d_widthType == EQUALWIDTH)
    {
        for (size_t col = 0; col < d_nColumns; col++)
            d_align[col].setWidth(maxWidth);
    }

    d_tabulated = true;
}