MWAWTable.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2 
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33 
34 /*
35  * Structure to store and construct a table from an unstructured list
36  * of cell
37  *
38  */
39 
40 #ifndef MWAW_TABLE_HELPER
41 # define MWAW_TABLE_HELPER
42 
43 #include <iostream>
44 #include <vector>
45 
46 #include "libmwaw_internal.hxx"
47 
49 typedef shared_ptr<MWAWContentListener> MWAWContentListenerPtr;
50 
51 
52 class MWAWTable;
53 
56 {
57  friend class MWAWTable;
58 public:
61  }
63  virtual ~MWAWTableCell() { }
65  void setBox(Box2f const &dim) {
66  m_box = dim;
67  }
69  Box2f const &box() const {
70  return m_box;
71  }
72 
74  friend std::ostream &operator<<(std::ostream &o, MWAWTableCell const &cell) {
75  if (cell.m_position.x() >= 0) {
76  o << "pos=" << cell.m_position << ",";
77  if (cell.m_numberCellSpanned[0]!=1 || cell.m_numberCellSpanned[1]!=1)
78  o << "span=" << cell.m_position << ",";
79  }
80  o << "box=" << cell.m_box << ",";
81  return o;
82  }
83 
85  virtual bool send(MWAWContentListenerPtr listener) = 0;
86 
88  virtual bool sendContent(MWAWContentListenerPtr listener) = 0;
89 
90 protected:
92  struct Compare {
93  Compare(int dim) : m_coord(dim) {}
95  struct Point {
96  Point(int wh, MWAWTableCell const *cell) : m_which(wh), m_cell(cell) {}
97  float getPos(int coord) const {
98  if (m_which)
99  return m_cell->box().max()[coord];
100  return m_cell->box().min()[coord];
101  }
102  float getSize(int coord) const {
103  return m_cell->box().size()[coord];
104  }
105  int m_which;
107  };
108 
110  bool operator()(Point const &c1, Point const &c2) const {
111  float diffF = c1.getPos(m_coord)-c2.getPos(m_coord);
112  if (diffF < 0) return true;
113  if (diffF > 0) return false;
114  int diff = c2.m_which - c1.m_which;
115  if (diff) return (diff < 0);
116  diffF = c1.m_cell->box().size()[m_coord]
117  - c2.m_cell->box().size()[m_coord];
118  if (diffF < 0) return true;
119  if (diffF > 0) return false;
120  return ssize_t(c1.m_cell) < ssize_t(c2.m_cell);
121  }
122 
124  int m_coord;
125  };
126 
127 protected:
130 
133 };
134 
136 {
137 public:
140 
142  virtual ~MWAWTable();
143 
145  void add(shared_ptr<MWAWTableCell> cell) {
146  m_cellsList.push_back(cell);
147  }
148 
150  int numCells() const {
151  return int(m_cellsList.size());
152  }
154  shared_ptr<MWAWTableCell> get(int id);
155 
160  bool sendTable(MWAWContentListenerPtr listener);
161 
166 
168  bool sendAsText(MWAWContentListenerPtr listener);
169 
170 protected:
172  bool buildStructures();
173 
175  std::vector<shared_ptr<MWAWTableCell> > m_cellsList;
177  std::vector<float> m_rowsSize, m_colsSize;
178 };
179 
180 #endif
void setBox(Box2f const &dim)
set the bounding box (units in point)
Definition: MWAWTable.hxx:65
MWAWTable()
the constructor
Definition: MWAWTable.hxx:139
Vec2< T > const & min() const
the minimum 2D point (in x and in y)
Definition: libmwaw_internal.hxx:719
std::vector< shared_ptr< MWAWTableCell > > m_cellsList
the list of cells
Definition: MWAWTable.hxx:175
Vec2i m_position
the final position in the table
Definition: MWAWTable.hxx:132
a virtual structure used to store/send a cell to a listener
Definition: MWAWTable.hxx:55
Definition: MWAWTable.hxx:135
a comparaison structure used retrieve the rows and the columns
Definition: MWAWTable.hxx:92
shared_ptr< MWAWContentListener > MWAWContentListenerPtr
Definition: MWAWContentListener.hxx:260
virtual bool send(MWAWContentListenerPtr listener)=0
call when a cell must be send
float getPos(int coord) const
Definition: MWAWTable.hxx:97
int m_coord
the coord to compare
Definition: MWAWTable.hxx:124
Vec2< T > const & max() const
the maximum 2D point (in x and in y)
Definition: libmwaw_internal.hxx:723
void add(shared_ptr< MWAWTableCell > cell)
add a new cells
Definition: MWAWTable.hxx:145
virtual ~MWAWTable()
the destructor
Definition: MWAWTable.cxx:52
T x() const
first element
Definition: libmwaw_internal.hxx:395
friend std::ostream & operator<<(std::ostream &o, MWAWTableCell const &cell)
operator&lt;&lt;
Definition: MWAWTable.hxx:74
MWAWTableCell const * m_cell
Definition: MWAWTable.hxx:106
virtual bool sendContent(MWAWContentListenerPtr listener)=0
call when the content of a cell must be send
bool sendAsText(MWAWContentListenerPtr listener)
try to send the table as basic text
Definition: MWAWTable.cxx:217
MWAWTableCell()
constructor
Definition: MWAWTable.hxx:60
std::vector< float > m_rowsSize
the final row and col size (in point)
Definition: MWAWTable.hxx:177
small structure to define a cell point
Definition: MWAWTable.hxx:95
Box2f const & box() const
return the bounding box
Definition: MWAWTable.hxx:69
bool sendTable(MWAWContentListenerPtr listener)
try to send the table
Definition: MWAWTable.cxx:153
std::vector< float > m_colsSize
Definition: MWAWTable.hxx:177
bool operator()(Point const &c1, Point const &c2) const
comparaison function
Definition: MWAWTable.hxx:110
Vec2i m_numberCellSpanned
the number of cell span
Definition: MWAWTable.hxx:132
virtual ~MWAWTableCell()
destructor
Definition: MWAWTable.hxx:63
Definition: MWAWContentListener.hxx:68
virtual void sendPreTableData(MWAWContentListenerPtr)
a function called just before calling listener-&gt;openTable(), to insert extra data ...
Definition: MWAWTable.hxx:165
bool buildStructures()
create the correspondance list, ...
Definition: MWAWTable.cxx:67
Point(int wh, MWAWTableCell const *cell)
Definition: MWAWTable.hxx:96
Vec2< T > size() const
the box size
Definition: libmwaw_internal.hxx:743
int m_which
Definition: MWAWTable.hxx:105
Box2f m_box
the cell bounding box (unit in point)
Definition: MWAWTable.hxx:129
Compare(int dim)
Definition: MWAWTable.hxx:93
float getSize(int coord) const
Definition: MWAWTable.hxx:102
int numCells() const
returns the number of cell
Definition: MWAWTable.hxx:150

Generated for libmwaw by doxygen 1.8.5