WPXTable.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* libwpd
00003  * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00004  * Copyright (C) 2002 Marc Maurer (uwog@uwog.net)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
00019  *
00020  * For further information visit http://libwpd.sourceforge.net
00021  */
00022 
00023 /* "This product is not manufactured, approved, or supported by
00024  * Corel Corporation or Corel Corporation Limited."
00025  */
00026 
00027 // WPXTable: an intermediate representation of a table, designed to be created
00028 // "ahead of time". unlike wordperfect's table definition messages, this representation
00029 // is _consistent_: we can always count on the messages being sent using this representation
00030 // (once it is created and finalized) to be reliable (assuming no bugs in this code!) :-)
00031 //
00032 // example situation where this might be useful: WordPerfect allows two cells,
00033 // side by side, one with border, one without-- creating a false ambiguity (none
00034 // actually exists: if one cell does not have a border, the other doesn't either)
00035 
00036 #ifndef _WPXTABLE_H
00037 #define _WPXTABLE_H
00038 #include <vector>
00039 #include "libwpd_types.h"
00040 
00041 typedef struct _WPXTableCell WPXTableCell;
00042 
00043 struct _WPXTableCell
00044 {
00045         _WPXTableCell(uint8_t colSpan, uint8_t rowSpan, uint8_t borderBits);
00046         uint8_t m_colSpan;
00047         uint8_t m_rowSpan;
00048         uint8_t m_borderBits;
00049 };
00050 
00051 class WPXTable
00052 {
00053 public:
00054         WPXTable() : m_tableRows() {}
00055         ~WPXTable();
00056         void insertRow();
00057         void insertCell(uint8_t colSpan, uint8_t rowSpan, uint8_t borderBits);
00058         const WPXTableCell  *getCell(int i, int j)
00059         {
00060                 return (m_tableRows[i])[j];
00061         }
00062         void makeBordersConsistent();
00063         void _makeCellBordersConsistent(WPXTableCell *cell, std::vector<WPXTableCell *> &adjacentCells,
00064                                         int adjacencyBitCell, int adjacencyBitBoundCells);
00065         std::vector<WPXTableCell *>  _getCellsBottomAdjacent(int i, int j);
00066         std::vector<WPXTableCell *>  _getCellsRightAdjacent(int i, int j);
00067 
00068         const std::vector< std::vector<WPXTableCell *> >& getRows() const
00069         {
00070                 return m_tableRows;
00071         }
00072         bool isEmpty() const
00073         {
00074                 return m_tableRows.size() == 0;
00075         }
00076 
00077 private:
00078         std::vector< std::vector<WPXTableCell *> > m_tableRows;
00079 };
00080 
00081 class WPXTableList
00082 {
00083 public:
00084         WPXTableList();
00085         WPXTableList(const WPXTableList &);
00086         WPXTableList &operator=(const WPXTableList &tableList);
00087         virtual ~WPXTableList();
00088 
00089         WPXTable *operator[](unsigned long i)
00090         {
00091                 return (*m_tableList)[i];
00092         }
00093         void add(WPXTable *table)
00094         {
00095                 m_tableList->push_back(table);
00096         }
00097 
00098 private:
00099         void release();
00100         void acquire(int *refCount, std::vector<WPXTable *> *tableList);
00101         int *getRef() const
00102         {
00103                 return m_refCount;
00104         }
00105         std::vector<WPXTable *> * get() const
00106         {
00107                 return m_tableList;
00108         }
00109 
00110         std::vector<WPXTable *> *m_tableList;
00111         int *m_refCount;
00112 };
00113 #endif /* _WPXTABLE_H */
00114 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */