-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdocument_element.hpp
More file actions
521 lines (414 loc) · 13.3 KB
/
Copy pathdocument_element.hpp
File metadata and controls
521 lines (414 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
#pragma once
#include <memory>
#include <optional>
#include <string>
#include <odr/definitions.hpp>
namespace odr {
struct TablePosition;
struct TableDimensions;
class DocumentPath;
class File;
struct TextStyle;
struct ParagraphStyle;
struct TableStyle;
struct TableColumnStyle;
struct TableRowStyle;
struct TableCellStyle;
struct GraphicStyle;
struct PageLayout;
} // namespace odr
namespace odr::internal::abstract {
class Document;
class ElementAdapter;
class TextRootAdapter;
class SlideAdapter;
class PageAdapter;
class SheetAdapter;
class SheetCellAdapter;
class MasterPageAdapter;
class LineBreakAdapter;
class ParagraphAdapter;
class SpanAdapter;
class TextAdapter;
class LinkAdapter;
class BookmarkAdapter;
class ListItemAdapter;
class TableAdapter;
class TableColumnAdapter;
class TableRowAdapter;
class TableCellAdapter;
class FrameAdapter;
class RectAdapter;
class LineAdapter;
class CircleAdapter;
class CustomShapeAdapter;
class ImageAdapter;
} // namespace odr::internal::abstract
namespace odr {
class Element;
class ElementIterator;
class ElementRange;
class TextRoot;
class Slide;
class Sheet;
class SheetCell;
class Page;
class MasterPage;
class LineBreak;
class Paragraph;
class Span;
class Text;
class Link;
class Bookmark;
class ListItem;
class Table;
class TableColumn;
class TableRow;
class TableCell;
class Frame;
class Rect;
class Line;
class Circle;
class CustomShape;
class Image;
/// @brief Collection of element types.
enum class ElementType {
none,
root,
slide,
sheet,
page,
master_page,
sheet_cell,
text,
line_break,
page_break,
paragraph,
span,
link,
bookmark,
list,
list_item,
table,
table_column,
table_row,
table_cell,
frame,
image,
rect,
line,
circle,
custom_shape,
group,
};
/// @brief Collection of anchor types.
enum class AnchorType {
as_char,
at_char,
at_frame,
at_page,
at_paragraph,
};
/// @brief Collection of value types.
enum class ValueType {
unknown,
string,
float_number,
};
/// @brief Represents an element in a document.
class Element {
public:
Element();
Element(const internal::abstract::ElementAdapter *adapter,
ElementIdentifier identifier);
explicit operator bool() const;
[[nodiscard]] ElementType type() const;
[[nodiscard]] Element parent() const;
[[nodiscard]] Element first_child() const;
[[nodiscard]] Element previous_sibling() const;
[[nodiscard]] Element next_sibling() const;
[[nodiscard]] bool is_unique() const;
[[nodiscard]] bool is_self_locatable() const;
[[nodiscard]] bool is_editable() const;
[[nodiscard]] DocumentPath document_path() const;
[[nodiscard]] Element navigate_path(const DocumentPath &path) const;
[[nodiscard]] ElementRange children() const;
[[nodiscard]] TextRoot as_text_root() const;
[[nodiscard]] Slide as_slide() const;
[[nodiscard]] Sheet as_sheet() const;
[[nodiscard]] Page as_page() const;
[[nodiscard]] SheetCell as_sheet_cell() const;
[[nodiscard]] MasterPage as_master_page() const;
[[nodiscard]] LineBreak as_line_break() const;
[[nodiscard]] Paragraph as_paragraph() const;
[[nodiscard]] Span as_span() const;
[[nodiscard]] Text as_text() const;
[[nodiscard]] Link as_link() const;
[[nodiscard]] Bookmark as_bookmark() const;
[[nodiscard]] ListItem as_list_item() const;
[[nodiscard]] Table as_table() const;
[[nodiscard]] TableColumn as_table_column() const;
[[nodiscard]] TableRow as_table_row() const;
[[nodiscard]] TableCell as_table_cell() const;
[[nodiscard]] Frame as_frame() const;
[[nodiscard]] Rect as_rect() const;
[[nodiscard]] Line as_line() const;
[[nodiscard]] Circle as_circle() const;
[[nodiscard]] CustomShape as_custom_shape() const;
[[nodiscard]] Image as_image() const;
protected:
const internal::abstract::ElementAdapter *m_adapter{nullptr};
ElementIdentifier m_identifier{null_element_id};
friend bool operator==(const Element &lhs, const Element &rhs) {
return lhs.m_identifier == rhs.m_identifier;
}
[[nodiscard]] bool exists_() const;
};
/// @brief Represents an iterator for elements in a document.
class ElementIterator {
public:
using value_type = Element;
using difference_type = std::ptrdiff_t;
using pointer = Element *;
using reference = Element;
using iterator_category = std::forward_iterator_tag;
ElementIterator();
ElementIterator(const internal::abstract::ElementAdapter *adapter,
ElementIdentifier identifier);
Element operator*() const;
ElementIterator &operator++();
ElementIterator operator++(int) const;
private:
const internal::abstract::ElementAdapter *m_adapter{nullptr};
ElementIdentifier m_identifier{null_element_id};
friend bool operator==(const ElementIterator &lhs,
const ElementIterator &rhs) {
return lhs.m_identifier == rhs.m_identifier;
}
[[nodiscard]] bool exists_() const;
};
/// @brief Represents a range of elements in a document.
class ElementRange {
public:
ElementRange();
explicit ElementRange(const ElementIterator &begin);
ElementRange(const ElementIterator &begin, const ElementIterator &end);
[[nodiscard]] ElementIterator begin() const;
[[nodiscard]] ElementIterator end() const;
private:
ElementIterator m_begin;
ElementIterator m_end;
};
/// @brief Represents a typed element in a document.
template <typename T> class ElementBase : public Element {
public:
ElementBase() = default;
ElementBase(const internal::abstract::ElementAdapter *adapter,
ElementIdentifier identifier, const T *adapter2)
: Element(adapter, identifier), m_adapter2{adapter2} {}
explicit operator bool() const { return exists_(); }
protected:
const T *m_adapter2{nullptr};
[[nodiscard]] bool exists_() const {
return Element::exists_() && m_adapter2 != nullptr;
}
};
/// @brief Represents a root element in a document.
class TextRoot final : public ElementBase<internal::abstract::TextRootAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] PageLayout page_layout() const;
[[nodiscard]] MasterPage first_master_page() const;
};
/// @brief Represents a slide element in a document.
class Slide final : public ElementBase<internal::abstract::SlideAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::string name() const;
[[nodiscard]] PageLayout page_layout() const;
[[nodiscard]] MasterPage master_page() const;
};
/// @brief Represents a sheet element in a document.
class Sheet final : public ElementBase<internal::abstract::SheetAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::string name() const;
[[nodiscard]] TableDimensions dimensions() const;
[[nodiscard]] TableDimensions
content(std::optional<TableDimensions> range) const;
[[nodiscard]] SheetCell cell(std::uint32_t column, std::uint32_t row) const;
[[nodiscard]] ElementRange shapes() const;
[[nodiscard]] TableStyle style() const;
[[nodiscard]] TableColumnStyle column_style(std::uint32_t column) const;
[[nodiscard]] TableRowStyle row_style(std::uint32_t row) const;
[[nodiscard]] TableCellStyle cell_style(std::uint32_t column,
std::uint32_t row) const;
};
/// @brief Represents a sheet cell element in a document.
class SheetCell final
: public ElementBase<internal::abstract::SheetCellAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] TablePosition position() const;
[[nodiscard]] bool is_covered() const;
[[nodiscard]] TableDimensions span() const;
[[nodiscard]] ValueType value_type() const;
};
/// @brief Represents a page element in a document.
class Page final : public ElementBase<internal::abstract::PageAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::string name() const;
[[nodiscard]] PageLayout page_layout() const;
[[nodiscard]] MasterPage master_page() const;
};
/// @brief Represents a master page element in a document.
class MasterPage final
: public ElementBase<internal::abstract::MasterPageAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] PageLayout page_layout() const;
};
/// @brief Represents a line break element in a document.
class LineBreak final
: public ElementBase<internal::abstract::LineBreakAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] TextStyle style() const;
};
/// @brief Represents a paragraph element in a document.
class Paragraph final
: public ElementBase<internal::abstract::ParagraphAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] ParagraphStyle style() const;
[[nodiscard]] TextStyle text_style() const;
};
/// @brief Represents a span element in a document.
class Span final : public ElementBase<internal::abstract::SpanAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] TextStyle style() const;
};
/// @brief Represents a text element in a document.
class Text final : public ElementBase<internal::abstract::TextAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::string content() const;
void set_content(const std::string &text) const;
[[nodiscard]] TextStyle style() const;
};
/// @brief Represents a link element in a document.
class Link final : public ElementBase<internal::abstract::LinkAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::string href() const;
};
/// @brief Represents a bookmark element in a document.
class Bookmark final : public ElementBase<internal::abstract::BookmarkAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::string name() const;
};
/// @brief Represents a list item element in a document.
class ListItem final : public ElementBase<internal::abstract::ListItemAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] TextStyle style() const;
};
/// @brief Represents a table element in a document.
class Table final : public ElementBase<internal::abstract::TableAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] TableRow first_row() const;
[[nodiscard]] TableColumn first_column() const;
[[nodiscard]] ElementRange columns() const;
[[nodiscard]] ElementRange rows() const;
[[nodiscard]] TableDimensions dimensions() const;
[[nodiscard]] TableStyle style() const;
};
/// @brief Represents a table column element in a document.
class TableColumn final
: public ElementBase<internal::abstract::TableColumnAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] TableColumnStyle style() const;
};
/// @brief Represents a table row element in a document.
class TableRow final : public ElementBase<internal::abstract::TableRowAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] TableRowStyle style() const;
};
/// @brief Represents a table cell element in a document.
class TableCell final
: public ElementBase<internal::abstract::TableCellAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] bool is_covered() const;
[[nodiscard]] TableDimensions span() const;
[[nodiscard]] ValueType value_type() const;
[[nodiscard]] TableCellStyle style() const;
};
/// @brief Represents a frame element in a document.
class Frame final : public ElementBase<internal::abstract::FrameAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] AnchorType anchor_type() const;
[[nodiscard]] std::optional<std::string> x() const;
[[nodiscard]] std::optional<std::string> y() const;
[[nodiscard]] std::optional<std::string> width() const;
[[nodiscard]] std::optional<std::string> height() const;
[[nodiscard]] std::optional<std::string> z_index() const;
[[nodiscard]] GraphicStyle style() const;
};
/// @brief Represents a rectangle element in a document.
class Rect final : public ElementBase<internal::abstract::RectAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::string x() const;
[[nodiscard]] std::string y() const;
[[nodiscard]] std::string width() const;
[[nodiscard]] std::string height() const;
[[nodiscard]] GraphicStyle style() const;
};
/// @brief Represents a line element in a document.
class Line final : public ElementBase<internal::abstract::LineAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::string x1() const;
[[nodiscard]] std::string y1() const;
[[nodiscard]] std::string x2() const;
[[nodiscard]] std::string y2() const;
[[nodiscard]] GraphicStyle style() const;
};
/// @brief Represents a circle element in a document.
class Circle final : public ElementBase<internal::abstract::CircleAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::string x() const;
[[nodiscard]] std::string y() const;
[[nodiscard]] std::string width() const;
[[nodiscard]] std::string height() const;
[[nodiscard]] GraphicStyle style() const;
};
/// @brief Represents a custom shape element in a document.
class CustomShape final
: public ElementBase<internal::abstract::CustomShapeAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] std::optional<std::string> x() const;
[[nodiscard]] std::optional<std::string> y() const;
[[nodiscard]] std::string width() const;
[[nodiscard]] std::string height() const;
[[nodiscard]] GraphicStyle style() const;
};
/// @brief Represents an image element in a document.
class Image final : public ElementBase<internal::abstract::ImageAdapter> {
public:
using ElementBase::ElementBase;
[[nodiscard]] bool is_internal() const;
[[nodiscard]] std::optional<File> file() const;
[[nodiscard]] std::string href() const;
};
} // namespace odr