Skip to content

Commit 5479639

Browse files
authored
Merge pull request #7985 from gadfort/gui-const-any
gui: use const& for std::any in gui interface
2 parents f8ce580 + d974903 commit 5479639

File tree

14 files changed

+588
-510
lines changed

14 files changed

+588
-510
lines changed

src/drt/src/dr/FlexDR_graphics.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ class GridGraphDescriptor : public gui::Descriptor
2828
const frDesign* design;
2929
};
3030

31-
std::string getName(std::any object) const override;
31+
std::string getName(const std::any& object) const override;
3232
std::string getTypeName() const override;
33-
bool getBBox(std::any object, odb::Rect& bbox) const override;
33+
bool getBBox(const std::any& object, odb::Rect& bbox) const override;
3434

35-
void highlight(std::any object, gui::Painter& painter) const override;
35+
void highlight(const std::any& object, gui::Painter& painter) const override;
3636

37-
Properties getProperties(std::any object) const override;
38-
gui::Selected makeSelected(std::any object) const override;
39-
bool lessThan(std::any l, std::any r) const override;
37+
Properties getProperties(const std::any& object) const override;
38+
gui::Selected makeSelected(const std::any& object) const override;
39+
bool lessThan(const std::any& l, const std::any& r) const override;
4040

4141
void visitAllObjects(
4242
const std::function<void(const gui::Selected&)>& func) const override;
4343
};
4444

45-
std::string GridGraphDescriptor::getName(std::any object) const
45+
std::string GridGraphDescriptor::getName(const std::any& object) const
4646
{
4747
auto data = std::any_cast<Data>(object);
4848
return "<" + std::to_string(data.x) + ", " + std::to_string(data.y) + ", "
@@ -54,7 +54,7 @@ std::string GridGraphDescriptor::getTypeName() const
5454
return "Grid Graph Node";
5555
}
5656

57-
bool GridGraphDescriptor::getBBox(std::any object, odb::Rect& bbox) const
57+
bool GridGraphDescriptor::getBBox(const std::any& object, odb::Rect& bbox) const
5858
{
5959
auto data = std::any_cast<Data>(object);
6060
auto* graph = data.graph;
@@ -64,7 +64,7 @@ bool GridGraphDescriptor::getBBox(std::any object, odb::Rect& bbox) const
6464
return true;
6565
}
6666

67-
void GridGraphDescriptor::highlight(std::any object,
67+
void GridGraphDescriptor::highlight(const std::any& object,
6868
gui::Painter& painter) const
6969
{
7070
odb::Rect bbox;
@@ -76,7 +76,7 @@ void GridGraphDescriptor::highlight(std::any object,
7676
}
7777

7878
gui::Descriptor::Properties GridGraphDescriptor::getProperties(
79-
std::any object) const
79+
const std::any& object) const
8080
{
8181
auto data = std::any_cast<Data>(object);
8282
auto* graph = data.graph;
@@ -169,15 +169,15 @@ gui::Descriptor::Properties GridGraphDescriptor::getProperties(
169169
return props;
170170
}
171171

172-
gui::Selected GridGraphDescriptor::makeSelected(std::any object) const
172+
gui::Selected GridGraphDescriptor::makeSelected(const std::any& object) const
173173
{
174174
if (auto data = std::any_cast<Data>(&object)) {
175175
return gui::Selected(*data, this);
176176
}
177177
return gui::Selected();
178178
}
179179

180-
bool GridGraphDescriptor::lessThan(std::any l, std::any r) const
180+
bool GridGraphDescriptor::lessThan(const std::any& l, const std::any& r) const
181181
{
182182
auto l_grid = std::any_cast<Data>(l);
183183
auto r_grid = std::any_cast<Data>(r);

src/gui/include/gui/gui.h

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,20 @@ class Descriptor
297297
{
298298
public:
299299
virtual ~Descriptor() = default;
300-
virtual std::string getName(std::any object) const = 0;
301-
virtual std::string getShortName(std::any object) const
300+
virtual std::string getName(const std::any& object) const = 0;
301+
virtual std::string getShortName(const std::any& object) const
302302
{
303303
return getName(std::move(object));
304304
}
305305
virtual std::string getTypeName() const = 0;
306-
virtual std::string getTypeName(std::any /* object */) const
306+
virtual std::string getTypeName(const std::any& /* object */) const
307307
{
308308
return getTypeName();
309309
}
310-
virtual bool getBBox(std::any object, odb::Rect& bbox) const = 0;
310+
virtual bool getBBox(const std::any& object, odb::Rect& bbox) const = 0;
311311

312-
virtual bool isInst(std::any /* object */) const { return false; }
313-
virtual bool isNet(std::any /* object */) const { return false; }
312+
virtual bool isInst(const std::any& /* object */) const { return false; }
313+
virtual bool isNet(const std::any& /* object */) const { return false; }
314314

315315
virtual void visitAllObjects(
316316
const std::function<void(const Selected&)>& func) const
@@ -358,13 +358,19 @@ class Descriptor
358358
};
359359
using Editors = std::map<std::string, Editor>;
360360

361-
virtual Properties getProperties(std::any object) const = 0;
362-
virtual Actions getActions(std::any /* object */) const { return Actions(); }
363-
virtual Editors getEditors(std::any /* object */) const { return Editors(); }
361+
virtual Properties getProperties(const std::any& object) const = 0;
362+
virtual Actions getActions(const std::any& /* object */) const
363+
{
364+
return Actions();
365+
}
366+
virtual Editors getEditors(const std::any& /* object */) const
367+
{
368+
return Editors();
369+
}
364370

365-
virtual Selected makeSelected(std::any object) const = 0;
371+
virtual Selected makeSelected(const std::any& object) const = 0;
366372

367-
virtual bool lessThan(std::any l, std::any r) const = 0;
373+
virtual bool lessThan(const std::any& l, const std::any& r) const = 0;
368374

369375
static Editor makeEditor(const EditorCallback& func,
370376
const std::vector<EditorOption>& options)
@@ -378,8 +384,11 @@ class Descriptor
378384

379385
// The caller (Selected and Renderers) will pre-configure the Painter's pen
380386
// and brush before calling.
381-
virtual void highlight(std::any object, Painter& painter) const = 0;
382-
virtual bool isSlowHighlight(std::any /* object */) const { return false; }
387+
virtual void highlight(const std::any& object, Painter& painter) const = 0;
388+
virtual bool isSlowHighlight(const std::any& /* object */) const
389+
{
390+
return false;
391+
}
383392

384393
static std::string convertUnits(double value,
385394
bool area = false,
@@ -414,7 +423,7 @@ class Selected
414423

415424
bool isInst() const { return descriptor_->isInst(object_); }
416425
bool isNet() const { return descriptor_->isNet(object_); }
417-
std::any getObject() const { return object_; }
426+
const std::any& getObject() const { return object_; }
418427

419428
// If the select_flag is false, the drawing will happen in highlight mode.
420429
// Highlight shapes are persistent which will not get removed from

src/gui/src/bufferTreeDescriptor.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ BufferTreeDescriptor::BufferTreeDescriptor(
115115
BufferTree::setSTA(sta);
116116
}
117117

118-
std::string BufferTreeDescriptor::getName(std::any object) const
118+
std::string BufferTreeDescriptor::getName(const std::any& object) const
119119
{
120-
BufferTree* bnet = std::any_cast<BufferTree>(&object);
120+
const BufferTree* bnet = std::any_cast<BufferTree>(&object);
121121
return bnet->getName();
122122
}
123123

@@ -126,9 +126,10 @@ std::string BufferTreeDescriptor::getTypeName() const
126126
return "Buffer Tree";
127127
}
128128

129-
bool BufferTreeDescriptor::getBBox(std::any object, odb::Rect& bbox) const
129+
bool BufferTreeDescriptor::getBBox(const std::any& object,
130+
odb::Rect& bbox) const
130131
{
131-
BufferTree* bnet = std::any_cast<BufferTree>(&object);
132+
const BufferTree* bnet = std::any_cast<BufferTree>(&object);
132133
bbox.mergeInit();
133134
for (auto* net : bnet->getNets()) {
134135
odb::Rect box;
@@ -139,9 +140,10 @@ bool BufferTreeDescriptor::getBBox(std::any object, odb::Rect& bbox) const
139140
return true;
140141
}
141142

142-
void BufferTreeDescriptor::highlight(std::any object, Painter& painter) const
143+
void BufferTreeDescriptor::highlight(const std::any& object,
144+
Painter& painter) const
143145
{
144-
BufferTree* bnet = std::any_cast<BufferTree>(&object);
146+
const BufferTree* bnet = std::any_cast<BufferTree>(&object);
145147

146148
ColorGenerator generator;
147149
painter.saveState();
@@ -153,9 +155,9 @@ void BufferTreeDescriptor::highlight(std::any object, Painter& painter) const
153155
}
154156

155157
Descriptor::Properties BufferTreeDescriptor::getProperties(
156-
std::any object) const
158+
const std::any& object) const
157159
{
158-
BufferTree* bnet = std::any_cast<BufferTree>(&object);
160+
const BufferTree* bnet = std::any_cast<BufferTree>(&object);
159161
Properties props;
160162

161163
auto gui = Gui::get();
@@ -184,18 +186,18 @@ Descriptor::Properties BufferTreeDescriptor::getProperties(
184186
return props;
185187
}
186188

187-
Selected BufferTreeDescriptor::makeSelected(std::any object) const
189+
Selected BufferTreeDescriptor::makeSelected(const std::any& object) const
188190
{
189191
if (auto* bnet = std::any_cast<BufferTree>(&object)) {
190192
return Selected(*bnet, this);
191193
}
192194
return Selected();
193195
}
194196

195-
bool BufferTreeDescriptor::lessThan(std::any l, std::any r) const
197+
bool BufferTreeDescriptor::lessThan(const std::any& l, const std::any& r) const
196198
{
197-
BufferTree* l_bnet = std::any_cast<BufferTree>(&l);
198-
BufferTree* r_bnet = std::any_cast<BufferTree>(&r);
199+
const BufferTree* l_bnet = std::any_cast<BufferTree>(&l);
200+
const BufferTree* r_bnet = std::any_cast<BufferTree>(&r);
199201
return l_bnet->getName() < r_bnet->getName();
200202
}
201203

@@ -218,7 +220,8 @@ void BufferTreeDescriptor::visitAllObjects(
218220
}
219221
}
220222

221-
Descriptor::Actions BufferTreeDescriptor::getActions(std::any object) const
223+
Descriptor::Actions BufferTreeDescriptor::getActions(
224+
const std::any& object) const
222225
{
223226
BufferTree bnet = *std::any_cast<BufferTree>(&object);
224227

src/gui/src/bufferTreeDescriptor.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ class BufferTreeDescriptor : public Descriptor
5757
const std::set<odb::dbNet*>& guide_nets,
5858
const std::set<odb::dbNet*>& tracks_nets);
5959

60-
std::string getName(std::any object) const override;
60+
std::string getName(const std::any& object) const override;
6161
std::string getTypeName() const override;
62-
bool getBBox(std::any object, odb::Rect& bbox) const override;
62+
bool getBBox(const std::any& object, odb::Rect& bbox) const override;
6363

64-
void highlight(std::any object, Painter& painter) const override;
64+
void highlight(const std::any& object, Painter& painter) const override;
6565

66-
Properties getProperties(std::any object) const override;
67-
Actions getActions(std::any object) const override;
68-
Selected makeSelected(std::any object) const override;
69-
bool lessThan(std::any l, std::any r) const override;
66+
Properties getProperties(const std::any& object) const override;
67+
Actions getActions(const std::any& object) const override;
68+
Selected makeSelected(const std::any& object) const override;
69+
bool lessThan(const std::any& l, const std::any& r) const override;
7070

7171
void visitAllObjects(
7272
const std::function<void(const Selected&)>& func) const override;

0 commit comments

Comments
 (0)