| 1 |
#ifndef INCLUDED_TABLETYPE_ |
| 2 |
#define INCLUDED_TABLETYPE_ |
| 3 |
|
| 4 |
#include <string> |
| 5 |
#include <vector> |
| 6 |
|
| 7 |
#include "../tablesupport/tablesupport.h" |
| 8 |
|
| 9 |
namespace FBB |
| 10 |
{ |
| 11 |
|
| 12 |
class TableType |
| 13 |
{ |
| 14 |
public: |
| 15 |
enum WidthType |
| 16 |
{ |
| 17 |
EQUALWIDTH, |
| 18 |
COLUMNWIDTH, |
| 19 |
}; |
| 20 |
enum FillDirection |
| 21 |
{ |
| 22 |
HORIZONTAL, |
| 23 |
VERTICAL |
| 24 |
}; |
| 25 |
|
| 26 |
private: |
| 27 |
//DATA |
| 28 |
TableSupport *d_tableSupportPtr; |
| 29 |
TableSupport &d_tableSupport; |
| 30 |
size_t d_maxWidth; |
| 31 |
size_t d_nRows; |
| 32 |
size_t d_nColumns; |
| 33 |
WidthType d_widthType; |
| 34 |
std::vector<size_t> d_colWidth; |
| 35 |
size_t (TableType::*d_widthFun) |
| 36 |
(size_t col) const; |
| 37 |
std::string const &(TableType::*d_indexFun) |
| 38 |
(size_t row, size_t col) const; |
| 39 |
//= |
| 40 |
protected: |
| 41 |
//PROT |
| 42 |
std::vector<std::string> d_string; |
| 43 |
//= |
| 44 |
public: |
| 45 |
std::ostream &insert(std::ostream &ostr) const; |
| 46 |
void setWidth(WidthType type); |
| 47 |
|
| 48 |
protected: |
| 49 |
TableType(TableSupport &tableSupport, size_t nColumns, |
| 50 |
FillDirection direction); |
| 51 |
TableType(size_t nColumns, FillDirection direction); |
| 52 |
~TableType() |
| 53 |
{ |
| 54 |
delete d_tableSupportPtr; |
| 55 |
} |
| 56 |
void init(); |
| 57 |
private: |
| 58 |
size_t width(size_t col) const // returns correct column width, |
| 59 |
{ // given d_widthType |
| 60 |
return (this->*d_widthFun)(col); |
| 61 |
} |
| 62 |
|
| 63 |
size_t maxWidth(size_t) const |
| 64 |
{ |
| 65 |
return d_maxWidth; |
| 66 |
} |
| 67 |
size_t columnWidth(size_t col) const |
| 68 |
{ |
| 69 |
return d_colWidth[col]; |
| 70 |
} |
| 71 |
// returns string at particular location |
| 72 |
std::string const &stringAt(size_t row, size_t col) const |
| 73 |
{ |
| 74 |
return (this->*d_indexFun)(row, col); |
| 75 |
} |
| 76 |
|
| 77 |
std::string const &hIndex(size_t row, size_t col) const; |
| 78 |
std::string const &vIndex(size_t row, size_t col) const; |
| 79 |
}; |
| 80 |
|
| 81 |
//INDEX |
| 82 |
inline std::string const &TableType::hIndex(size_t row, size_t col) const |
| 83 |
{ |
| 84 |
return d_string[row * d_nColumns + col]; |
| 85 |
} |
| 86 |
inline std::string const &TableType::vIndex(size_t row, size_t col) const |
| 87 |
{ |
| 88 |
return d_string[col * d_nRows + row]; |
| 89 |
} |
| 90 |
//= |
| 91 |
|
| 92 |
} // FBB |
| 93 |
|
| 94 |
std::ostream &operator<<(std::ostream &str, FBB::TableType const &tableType); |
| 95 |
|
| 96 |
#endif |