Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / writerfilter / inc / resourcemodel / TableData.hxx
blob61efa41b9c256cf7a11bbed4f535391142f2f11d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_TABLE_DATA
21 #define INCLUDED_TABLE_DATA
23 #include <resourcemodel/WW8ResourceModel.hxx>
25 #include <vector>
26 #include <boost/shared_ptr.hpp>
28 namespace writerfilter
31 template <typename T, typename PropertiesPointer>
32 /**
33 Class containing the data to describe a table cell.
35 class CellData
37 /**
38 Handle to start of cell.
40 T mStart;
42 /**
43 Handle to end of cell.
45 T mEnd;
47 /**
48 Pointer to properties of cell.
50 PropertiesPointer mpProps;
52 bool mbOpen;
54 public:
55 typedef boost::shared_ptr<CellData> Pointer_t;
57 CellData(T start, PropertiesPointer pProps)
58 : mStart(start), mEnd(start), mpProps(pProps), mbOpen(true)
62 virtual ~CellData() {}
64 /**
65 Set the start handle of the cell.
67 @param start the start handle of the cell
69 void setStart(T start) { mStart = start; }
71 /**
72 Set the end handle of a cell.
74 @param end the end handle of the cell
76 void setEnd(T end) { mEnd = end; mbOpen = false; }
78 /**
79 Set the properties of the cell.
81 @param pProps the properties of the cell
83 void setProperties(PropertiesPointer pProps) { mpProps = pProps; }
85 /**
86 Adds properties to the cell.
88 @param pProps the properties to add
90 void insertProperties(PropertiesPointer pProps)
92 if( mpProps.get() )
93 mpProps->InsertProps(pProps);
94 else
95 mpProps = pProps;
98 /**
99 Return start handle of the cell.
101 const T & getStart() { return mStart; }
104 Return end handle of the cell.
106 const T & getEnd() { return mEnd; }
109 Return properties of the cell.
111 PropertiesPointer getProperties() { return mpProps; }
113 bool isOpen() const { return mbOpen; }
116 template <typename T, typename PropertiesPointer>
118 Class to handle data of a table row.
120 class RowData
122 typedef typename CellData<T, PropertiesPointer>::Pointer_t
123 CellDataPointer_t;
124 typedef ::std::vector<CellDataPointer_t> Cells;
127 the cell data of the row
129 Cells mCells;
132 the properties of the row
134 mutable PropertiesPointer mpProperties;
136 public:
137 typedef boost::shared_ptr<RowData <T, PropertiesPointer> > Pointer_t;
139 RowData() {}
141 RowData(const RowData<T, PropertiesPointer> & rRowData)
142 : mCells(rRowData.mCells), mpProperties(rRowData.mpProperties)
146 virtual ~RowData() {}
149 Add a cell to the row.
151 @param start the start handle of the cell
152 @param end the end handle of the cell
153 @param pProps the properties of the cell
155 void addCell(const T & start, PropertiesPointer pProps)
157 CellDataPointer_t pCellData
158 (new CellData<T, PropertiesPointer>(start, pProps));
159 mCells.push_back(pCellData);
162 void endCell(const T & end)
164 if (mCells.size() > 0)
165 mCells.back()->setEnd(end);
168 bool isCellOpen() const
170 return mCells.size() > 0 && mCells.back()->isOpen();
174 Add properties to the row.
176 @param pProperties the properties to set
178 void insertProperties(PropertiesPointer pProperties)
180 if( pProperties.get() )
182 if( !mpProperties.get() )
183 mpProperties = pProperties;
184 else
185 mpProperties->InsertProps(pProperties);
190 Add properties to a cell of the row.
192 @param i index of the cell
193 @param pProps the properties to add
195 void insertCellProperties(unsigned int i, PropertiesPointer pProps)
197 mCells[i]->insertProperties(pProps);
201 Add properties to the last cell of the row.
203 void insertCellProperties(PropertiesPointer pProps)
205 if (! mCells.empty())
206 mCells.back()->insertProperties(pProps);
210 Return number of cells in the row.
212 unsigned int getCellCount()
214 return mCells.size();
218 Return start handle of a cell in the row.
220 @param i index of the cell
222 const T & getCellStart(unsigned int i) const
224 return mCells[i]->getStart();
228 Return end handle of a cell in the row.
230 @param i index of the cell
232 const T & getCellEnd(unsigned int i) const
234 return mCells[i]->getEnd();
238 Return the properties of a cell in the row.
240 @param i index of the cell
242 PropertiesPointer getCellProperties(unsigned int i) const
244 return mCells[i]->getProperties();
248 Return properties of the row.
250 PropertiesPointer getProperties()
252 return mpProperties;
256 Clear the row data.
258 void clear()
260 mCells.clear();
261 mpProperties.reset();
265 template <typename T, typename PropertiesPointer>
267 Class that holds the data of a table.
269 class TableData
271 typedef typename RowData<T, PropertiesPointer>::Pointer_t RowPointer_t;
272 typedef ::std::vector<RowPointer_t> Rows;
275 the table properties
277 PropertiesPointer mpTableProps;
280 the data of the rows of the table
282 Rows mRows;
285 pointer to the data of the current row (while building up the table data).
287 RowPointer_t mpRow;
290 depth of the current table in a hierarchy of tables
292 unsigned int mnDepth;
295 initialize mpRow
297 void newRow() { mpRow = RowPointer_t(new RowData<T, PropertiesPointer>()); }
299 public:
300 typedef boost::shared_ptr<TableData <T, PropertiesPointer> > Pointer_t;
302 TableData(unsigned int nDepth) : mnDepth(nDepth) { newRow(); }
303 ~TableData() {}
306 End the current row.
308 Sets properties of the current row and pushes the row to the
309 back of the rows currently contained in the table.
311 @param pProperties properties of the row to be ended
313 void endRow(PropertiesPointer pProperties)
315 mpRow->insertProperties(pProperties);
316 mRows.push_back(mpRow);
317 newRow();
321 Add a cell to the current row.
323 @param start start handle of the cell
324 @param end end handle of the cell
325 @param pProps properties of the cell
327 void addCell(const T & start, PropertiesPointer pProps)
329 mpRow->addCell(start, pProps);
333 End the current cell of the current row.
335 @parm end end handle of the cell
337 void endCell(const T & end)
339 mpRow->endCell(end);
343 Return if the current cell of the current row is open.
345 bool isCellOpen() const
347 return mpRow->isCellOpen();
351 Insert properties to the current cell of the current row.
353 @param pProps the properties to add
355 void insertCellProperties(PropertiesPointer pProps)
357 mpRow->insertCellProperties(pProps);
361 Add properties to a cell of the current row.
363 @param i index of the cell
364 @param pProps properties to add
366 void insertCellProperties(unsigned int i, PropertiesPointer pProps)
368 mpRow->insertCellProperties(i, pProps);
371 void insertTableProperties( PropertiesPointer pProps )
373 if ( mpTableProps.get( ) )
374 mpTableProps->insert( pProps );
375 else
376 mpTableProps = pProps;
380 Return the table properties.
382 PropertiesPointer getTableProperties( )
384 return mpTableProps;
388 Return number of rows in the table.
390 unsigned int getRowCount()
392 return mRows.size();
396 Return depth of table in surrounding table hierarchy.
398 unsigned int getDepth()
400 return mnDepth;
404 Return row data of a certain row.
406 @param i index of the row
408 const RowPointer_t getRow(unsigned int i) const
410 return mRows[i];
416 #endif // INCLUDED_TABLE_DATA
418 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */