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  * Version: MPL 2.0 / LGPLv2.1+
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Major Contributor(s):
00010  * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00011  * Copyright (C) 2002 Marc Maurer (uwog@uwog.net)
00012  *
00013  * For minor contributions see the git repository.
00014  *
00015  * Alternatively, the contents of this file may be used under the terms
00016  * of the GNU Lesser General Public License Version 2.1 or later
00017  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00018  * applicable instead of those above.
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 <stdio.h>
00040 #include "libwpd_types.h"
00041 
00042 typedef struct _WPXTableCell WPXTableCell;
00043 
00044 struct _WPXTableCell
00045 {
00046         _WPXTableCell(uint8_t colSpan, uint8_t rowSpan, uint8_t borderBits);
00047         uint8_t m_colSpan;
00048         uint8_t m_rowSpan;
00049         uint8_t m_borderBits;
00050 };
00051 
00052 class WPXTable
00053 {
00054 public:
00055         WPXTable() : m_tableRows() {}
00056         ~WPXTable();
00057         void insertRow();
00058         void insertCell(uint8_t colSpan, uint8_t rowSpan, uint8_t borderBits);
00059         const WPXTableCell  *getCell(size_t i, size_t j)
00060         {
00061                 return (m_tableRows[i])[j];
00062         }
00063         void makeBordersConsistent();
00064         void _makeCellBordersConsistent(WPXTableCell *cell, std::vector<WPXTableCell *> &adjacentCells,
00065                                         int adjacencyBitCell, int adjacencyBitBoundCells);
00066         std::vector<WPXTableCell *>  _getCellsBottomAdjacent(int i, int j);
00067         std::vector<WPXTableCell *>  _getCellsRightAdjacent(int i, int j);
00068 
00069         const std::vector< std::vector<WPXTableCell *> > &getRows() const
00070         {
00071                 return m_tableRows;
00072         }
00073         bool isEmpty() const
00074         {
00075                 return m_tableRows.empty();
00076         }
00077 
00078 private:
00079         std::vector< std::vector<WPXTableCell *> > m_tableRows;
00080 };
00081 
00082 class WPXTableList
00083 {
00084 public:
00085         WPXTableList();
00086         WPXTableList(const WPXTableList &);
00087         WPXTableList &operator=(const WPXTableList &tableList);
00088         virtual ~WPXTableList();
00089 
00090         WPXTable *operator[](unsigned long i)
00091         {
00092                 return (*m_tableList)[i];
00093         }
00094         void add(WPXTable *table)
00095         {
00096                 m_tableList->push_back(table);
00097         }
00098 
00099 private:
00100         void release();
00101         void acquire(int *refCount, std::vector<WPXTable *> *tableList);
00102         int *getRef() const
00103         {
00104                 return m_refCount;
00105         }
00106         std::vector<WPXTable *> *get() const
00107         {
00108                 return m_tableList;
00109         }
00110 
00111         std::vector<WPXTable *> *m_tableList;
00112         int *m_refCount;
00113 };
00114 #endif /* _WPXTABLE_H */
00115 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */