Board 0.9.6
ShapeVisitor.h
Go to the documentation of this file.
1/* -*- mode: c++ -*- */
26#ifndef BOARD_SHAPE_VISITOR_H
27#define BOARD_SHAPE_VISITOR_H
28
29#include <board/Color.h>
30#include <board/Globals.h>
31#include <board/Style.h>
32#include <cstddef> // For std::size_t
33#include <functional>
34#include <set>
35
36namespace LibBoard
37{
38
39struct Shape;
40struct ShapeWithStyle;
41struct ShapeList;
42struct Board;
43struct Dot;
44struct Line;
45struct Arrow;
46struct Polyline;
47struct Ellipse;
48struct Text;
49struct Bezier;
50
55 virtual void visit(Shape & shape) = 0;
56 virtual void visit(Shape & shape) const = 0;
57 virtual void visit(ShapeWithStyle & shape);
58 virtual void visit(ShapeWithStyle & shape) const;
59 virtual void visit(Dot &);
60 virtual void visit(Dot &) const;
61 virtual void visit(Line &);
62 virtual void visit(Line &) const;
63 virtual void visit(Arrow &);
64 virtual void visit(Arrow & arrow) const;
65 virtual void visit(Polyline &);
66 virtual void visit(Polyline &) const;
67 virtual void visit(Ellipse &);
68 virtual void visit(Ellipse &) const;
69 virtual void visit(Text &);
70 virtual void visit(Text &) const;
71 virtual void visit(Bezier &);
72 virtual void visit(Bezier &) const;
73 virtual ~ShapeVisitor();
74};
75
80 virtual void visit(const Shape & shape) = 0;
81 virtual void visit(const Shape & shape) const = 0;
82 virtual void visit(const ShapeWithStyle & shape);
83 virtual void visit(const ShapeWithStyle & shape) const;
84 virtual void visit(const Dot &);
85 virtual void visit(const Dot &) const;
86 virtual void visit(const Line &);
87 virtual void visit(const Line &) const;
88 virtual void visit(const Arrow &);
89 virtual void visit(const Arrow & arrow) const;
90 virtual void visit(const Polyline &);
91 virtual void visit(const Polyline &) const;
92 virtual void visit(const Ellipse &);
93 virtual void visit(const Ellipse &) const;
94 virtual void visit(const Text &);
95 virtual void visit(const Text &) const;
96 virtual void visit(const Bezier &);
97 virtual void visit(const Bezier &) const;
98 virtual ~ConstShapeVisitor();
99};
100
105 virtual Shape * map(const Shape &) = 0;
106 virtual Shape * map(const Shape &) const = 0;
107 virtual Shape * map(const Dot &);
108 virtual Shape * map(const Dot &) const;
109 virtual Shape * map(const Line &);
110 virtual Shape * map(const Line &) const;
111 virtual Shape * map(const Arrow &);
112 virtual Shape * map(const Arrow &) const;
113 virtual Shape * map(const Polyline &);
114 virtual Shape * map(const Polyline &) const;
115 virtual Shape * map(const Ellipse &);
116 virtual Shape * map(const Ellipse &) const;
117 virtual Shape * map(const Text &);
118 virtual Shape * map(const Text &) const;
119 virtual Shape * map(const Bezier &);
120 virtual Shape * map(const Bezier &) const;
121 virtual ~CompositeShapeTransform();
122};
123
130 void visit(const Shape &) override;
131 void visit(const Shape &) const override;
132 const ShapeList & shapeList() const;
133
134private:
135 ShapeList & _shapeList;
136};
137
143 void visit(const Shape &) override;
144 void visit(const Shape &) const override;
145};
146
152 ShapeCounter();
153 void clear();
154 std::size_t value() const;
155 void visit(const Shape &) override;
156 void visit(const Shape &) const override;
157
158private:
159 std::size_t _count;
160};
161
168 void clear();
169 void visit(const Shape &) override;
170 void visit(const Shape &) const override;
171 void visit(const Dot & d) override;
172 void visit(const Line &) override;
173 void visit(const Arrow &) override;
174 void visit(const Polyline &) override;
175 void visit(const Ellipse &) override;
176 void visit(const Text &) override;
177 void visit(const Bezier &) override;
178 const std::set<Color> & colors() const;
179
180private:
181 std::set<Color> _colors;
182};
183
189 void clear();
190 void visit(const Shape &) override;
191 void visit(const Shape &) const override;
192 void visit(const Dot &) override;
193 void visit(const Line &) override;
194 void visit(const Arrow &) override;
195 void visit(const Polyline &) override;
196 void visit(const Ellipse &) override;
197 void visit(const Text &) override;
198 void visit(const Bezier &) override;
199 const std::set<Color> & colors() const;
200
201private:
202 std::set<Color> _colors;
203};
204
209 typedef std::function<void(const Shape &)> Function;
211 void visit(const Shape &) override;
212 void visit(const Shape &) const override;
213 void visit(const Dot &) override;
214 void visit(const Line &) override;
215 void visit(const Arrow &) override;
216 void visit(const Polyline &) override;
217 void visit(const Ellipse &) override;
218 void visit(const Text &) override;
219 void visit(const Bezier &) override;
220
221private:
222 Function _f;
223};
224
228struct LeafVisitor : public ShapeVisitor {
229 typedef std::function<void(Shape &)> Function;
231 void visit(Shape &) override;
232 void visit(Shape &) const override;
233 void visit(Dot &) override;
234 void visit(Line &) override;
235 void visit(Arrow &) override;
236 void visit(Polyline &) override;
237 void visit(Ellipse &) override;
238 void visit(Text &) override;
239 void visit(Bezier &) override;
240
241private:
242 Function _f;
243};
244
249 typedef std::function<void(ShapeWithStyle &)> Function;
253 ShapeWithStyleVisitor(Color penColor, Color fillColor);
254 ShapeWithStyleVisitor(double lineWidth);
258 void visit(Shape &) override;
259 void visit(Shape &) const override;
260 void visit(ShapeWithStyle &) override;
261 void visit(ShapeWithStyle &) const override;
262 void visit(Dot &) override;
263 void visit(Dot &) const override;
264 void visit(Line &) override;
265 void visit(Line &) const override;
266 void visit(Arrow &) override;
267 void visit(Arrow &) const override;
268 void visit(Polyline &) override;
269 void visit(Polyline &) const override;
270 void visit(Ellipse &) override;
271 void visit(Ellipse &) const override;
272 void visit(Text &) override;
273 void visit(Text &) const override;
274 void visit(Bezier &) override;
275 void visit(Bezier &) const override;
276
277private:
278 Function _f;
279};
280
281} // namespace LibBoard
282
283#endif /* BOARD_SHAPE_VISITOR_H */
The Color structure. @copyright This source code is part of the Board project, a C++ library whose pu...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Structure representing an RGB triple.
Definition Color.h:43
Definition Board.h:55
LineStyle
Definition Style.h:47
ColorSpecification
The ColorSpecification enum.
Definition Globals.h:92
LineCap
Definition Style.h:35
LineJoin
Definition Style.h:41
A line between two points with an arrow at one extremity.
Definition Arrow.h:38
A Bezier curve described by two series of 2D points (curve points and control points).
Definition Bezier.h:42
The BoundingBoxExtractor struct may be used to compute the bounding box of a composite shape tree.
Definition ShapeVisitor.h:128
const ShapeList & shapeList() const
Definition ShapeVisitor.cpp:46
void visit(const Shape &) override
Definition ShapeVisitor.cpp:36
The BoundingBoxViewer struct may be used to display the bounding boxes of the shapes in a composite t...
Definition ShapeVisitor.h:142
void visit(const Shape &) override
Definition ShapeVisitor.cpp:51
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition ShapeVisitor.h:104
virtual Shape * map(const Shape &)=0
virtual ~CompositeShapeTransform()
Definition ShapeVisitor.cpp:321
virtual Shape * map(const Shape &) const =0
Leaf visitor may be used to apply a function on each leaf, in back-to-front order.
Definition ShapeVisitor.h:208
void visit(const Shape &) override
Definition ShapeVisitor.cpp:428
std::function< void(const Shape &)> Function
Definition ShapeVisitor.h:209
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:79
virtual void visit(const Shape &shape)=0
virtual void visit(const Shape &shape) const =0
virtual ~ConstShapeVisitor()
Definition ShapeVisitor.cpp:169
A line between two points.
Definition Dot.h:42
An ellipse.
Definition Ellipse.h:38
The fill-color extractor may be used to retrieve all fill colors.
Definition ShapeVisitor.h:187
void visit(const Shape &) override
Definition ShapeVisitor.cpp:379
const std::set< Color > & colors() const
Definition ShapeVisitor.cpp:421
FillColorExtractor()
Definition ShapeVisitor.cpp:377
Leaf visitor may be used to apply a function on each leaf, in back-to-front order.
Definition ShapeVisitor.h:228
std::function< void(Shape &)> Function
Definition ShapeVisitor.h:229
void visit(Shape &) override
Definition ShapeVisitor.cpp:469
A line between two points.
Definition Line.h:38
The pen-color extractor may be used to retrieve all pen colors.
Definition ShapeVisitor.h:166
void visit(const Shape &) override
Definition ShapeVisitor.cpp:330
const std::set< Color > & colors() const
Definition ShapeVisitor.cpp:372
PenColorExtractor()
Definition ShapeVisitor.cpp:323
void clear()
Definition ShapeVisitor.cpp:325
A polygonal line described by a series of 2D points.
Definition Polyline.h:38
The ShapeCounter struct may be used to count shapes in the composite shapes tree.
Definition ShapeVisitor.h:151
std::size_t value() const
Definition ShapeVisitor.cpp:70
ShapeCounter()
Definition ShapeVisitor.cpp:63
void clear()
Definition ShapeVisitor.cpp:65
void visit(const Shape &) override
Definition ShapeVisitor.cpp:75
A group of shapes.
Definition ShapeList.h:47
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:54
virtual void visit(Shape &shape)=0
virtual ~ShapeVisitor()
Definition ShapeVisitor.cpp:167
virtual void visit(Shape &shape) const =0
Leaf visitor may be used to apply a function on each Shape with style, in back-to-front order.
Definition ShapeVisitor.h:248
void visit(Shape &) override
Definition ShapeVisitor.cpp:550
std::function< void(ShapeWithStyle &)> Function
Definition ShapeVisitor.h:249
Abstract structure for a 2D shape.
Definition ShapeWithStyle.h:38
Abstract structure for a 2D shape.
Definition Shape.h:64
Definition Style.h:69
A piece of text.
Definition Text.h:40