File: table

package info (click to toggle)
bobcat 3.01.00-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,612 kB
  • sloc: cpp: 12,107; makefile: 8,055; perl: 401; sh: 329
file content (116 lines) | stat: -rw-r--r-- 3,032 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef INCLUDED_BOBCAT_TABLE_
#define INCLUDED_BOBCAT_TABLE_

#include <sstream>

#include <bobcat/tablebase>

namespace FBB
{

class Table: public TableBase, public std::ostringstream
{
    template <typename Type>
    friend Table &operator<<(Table &table, Type const &ref);

    public:
        typedef std::string value_type;     // for C++-0x
        typedef Element const &const_reference;  // required for push_back()

        Table(size_t nColumns, FillDirection direction,             // 0
                                WidthType widthType = COLUMNWIDTH); 

        Table(TableSupport &tableSupport,                           // 1
                size_t nColumns, FillDirection direction,             
                WidthType widthType = COLUMNWIDTH);

        Table(Table const &other) = delete;
        Table &operator=(Table const &other) = delete;

        Table &append(std::string const &str, char const *sep = " \t",
                            bool addEmpty = false);

        template <typename InputIterator>
        void fill(InputIterator begin, InputIterator end);

        void push_back(Element const &element); // add an element to the
                                                // table, using the 
                                                // default alignment. 

        Table &setAlign(Align const &align);    // set an alignment

        Table &def();                       // fillup an incomplete table
                                            // automatically at insertions

        using TableBase::clear;
        void clearStr();                    // clear the ostringstream part

    private:
        Table &flush();                     // insert the text currently
                                            // inserted into the Table object
                                            // as ostringstream into the table 
};

template <typename Iter>
void Table::fill(Iter it, Iter end)
{
    TableBase::clear();

    while (it != end)
    {
        std::ostringstream str;
        str << *it++;
        push_back(str.str());
    }
}

inline void Table::push_back(Element const &element)
{
    d_tabulated = false;
    d_string.push_back(element);
}

inline Table &Table::setAlign(Align const &align)
{
    TableBase::setAlign(align);
    return *this;
}
                        // Insert column or element alignments
inline Table &operator<<(Table &tab, Align const &align)
{
    return tab.setAlign(align);
}

inline Table &Table::def()
{
    TableBase::def();
    return *this;
}

inline Table &def(Table &table)
{
    return table.def();
}
                        // For def
inline Table &operator<<(Table &table, Table &(*fun)(Table &))
{
    return (*fun)(table);
}

inline void Table::clearStr()
{
    std::ostringstream::clear();
}

template <typename Type>    // Insert any other insertable type into a Table
Table &operator<<(Table &table, Type const &ref)
{
    reinterpret_cast<std::ostringstream &>(table) << ref;
    return table.flush();
}

} // FBB



#endif