WPXTable.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwpd
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
11 * Copyright (C) 2002 Marc Maurer (uwog@uwog.net)
12 *
13 * For minor contributions see the git repository.
14 *
15 * Alternatively, the contents of this file may be used under the terms
16 * of the GNU Lesser General Public License Version 2.1 or later
17 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
18 * applicable instead of those above.
19 *
20 * For further information visit http://libwpd.sourceforge.net
21 */
22
23 /* "This product is not manufactured, approved, or supported by
24 * Corel Corporation or Corel Corporation Limited."
25 */
26
27 // WPXTable: an intermediate representation of a table, designed to be created
28 // "ahead of time". unlike wordperfect's table definition messages, this representation
29 // is _consistent_: we can always count on the messages being sent using this representation
30 // (once it is created and finalized) to be reliable (assuming no bugs in this code!) :-)
31 //
32 // example situation where this might be useful: WordPerfect allows two cells,
33 // side by side, one with border, one without-- creating a false ambiguity (none
34 // actually exists: if one cell does not have a border, the other doesn't either)
35
36 #ifndef _WPXTABLE_H
37 #define _WPXTABLE_H
38
39 #include <vector>
40
41 struct WPXTableCell
42 {
43 WPXTableCell(unsigned char colSpan, unsigned char rowSpan, unsigned char borderBits);
44 unsigned char m_colSpan;
45 unsigned char m_rowSpan;
46 unsigned char m_borderBits;
47 };
48
49 class WPXTable
50 {
51 public:
52 WPXTable() : m_tableRows() {}
53 ~WPXTable();
54 void insertRow();
55 void insertCell(unsigned char colSpan, unsigned char rowSpan, unsigned char borderBits);
56 const WPXTableCell *getCell(size_t i, size_t j)
57 {
58 return &(m_tableRows[i])[j];
59 }
60 void makeBordersConsistent();
61
62 unsigned getRowCount() const
63 {
64 return m_tableRows.size();
65 }
66 unsigned getColumnCount(unsigned row) const
67 {
68 return m_tableRows[row].size();
69 }
70 bool isEmpty() const
71 {
72 return m_tableRows.empty();
73 }
74
75 private:
76 void _makeCellBordersConsistent(WPXTableCell &cell, std::vector<WPXTableCell *> &adjacentCells,
77 int adjacencyBitCell, int adjacencyBitBoundCells);
78 std::vector<WPXTableCell *> _getCellsBottomAdjacent(int i, int j);
79 std::vector<WPXTableCell *> _getCellsRightAdjacent(int i, int j);
80
81 private:
82 std::vector< std::vector<WPXTableCell> > m_tableRows;
83 };
84
85 #endif /* _WPXTABLE_H */
86 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPXTable
Definition: WPXTable.h:50
WPXTable::_getCellsRightAdjacent
std::vector< WPXTableCell * > _getCellsRightAdjacent(int i, int j)
Definition: WPXTable.cpp:127
WPXTable::_getCellsBottomAdjacent
std::vector< WPXTableCell * > _getCellsBottomAdjacent(int i, int j)
Definition: WPXTable.cpp:107
WPXTable::WPXTable
WPXTable()
Definition: WPXTable.h:52
WPXTable::_makeCellBordersConsistent
void _makeCellBordersConsistent(WPXTableCell &cell, std::vector< WPXTableCell * > &adjacentCells, int adjacencyBitCell, int adjacencyBitBoundCells)
Definition: WPXTable.cpp:83
WPXTable::insertRow
void insertRow()
Definition: WPXTable.cpp:45
WPXTable::~WPXTable
~WPXTable()
Definition: WPXTable.cpp:41
WPXTable::isEmpty
bool isEmpty() const
Definition: WPXTable.h:70
WPXTable::getColumnCount
unsigned getColumnCount(unsigned row) const
Definition: WPXTable.h:66
WPXTable::getCell
const WPXTableCell * getCell(size_t i, size_t j)
Definition: WPXTable.h:56
WPXTable::getRowCount
unsigned getRowCount() const
Definition: WPXTable.h:62
WPXTable::makeBordersConsistent
void makeBordersConsistent()
Definition: WPXTable.cpp:60
WPXTable::insertCell
void insertCell(unsigned char colSpan, unsigned char rowSpan, unsigned char borderBits)
Definition: WPXTable.cpp:50
WPXTable::m_tableRows
std::vector< std::vector< WPXTableCell > > m_tableRows
Definition: WPXTable.h:82
WPXTableCell
Definition: WPXTable.h:42
WPXTableCell::m_borderBits
unsigned char m_borderBits
Definition: WPXTable.h:46
WPXTableCell::m_colSpan
unsigned char m_colSpan
Definition: WPXTable.h:44
WPXTableCell::m_rowSpan
unsigned char m_rowSpan
Definition: WPXTable.h:45
WPXTableCell::WPXTableCell
WPXTableCell(unsigned char colSpan, unsigned char rowSpan, unsigned char borderBits)
Definition: WPXTable.cpp:34