Skip to content

Commit 26e6567

Browse files
committed
some refactoring
1 parent 3f7f85e commit 26e6567

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

CGTeaFrame.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CGTeaFrame::CGTeaFrame(const wxString& title, const wxPoint& pos, const wxSize&
7777
availableActions.emplace_back(std::make_unique<Coloring>());
7878
availableActions.emplace_back(std::make_unique<LineGraph>());
7979

80-
auto menuFile = new wxMenu;
80+
auto menuFile = std::make_unique<wxMenu>();
8181
menuFile->Append(1000, "&Open");
8282
menuFile->Append(1001, "&Save");
8383
menuFile->AppendSeparator();
@@ -87,7 +87,7 @@ CGTeaFrame::CGTeaFrame(const wxString& title, const wxPoint& pos, const wxSize&
8787
Connect(1001, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::Save));
8888
Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::OnExit));
8989

90-
auto menuGenerate = new wxMenu;
90+
auto menuGenerate = std::make_unique<wxMenu>();
9191
int i = 1;
9292
// std::apply([&](auto&&... args) {((menuGenerate->Append(i, wxString(args.name().c_str(), wxConvUTF8), wxString(args.description().c_str(), wxConvUTF8)),i++), ...);}, availableGenerators);
9393
for (auto& gi : availableGenerators) {
@@ -97,38 +97,38 @@ CGTeaFrame::CGTeaFrame(const wxString& title, const wxPoint& pos, const wxSize&
9797
i++;
9898
}
9999

100-
auto menuReport = new wxMenu;
100+
auto menuReport = std::make_unique<wxMenu>();
101101
for (auto& ri : availableReports) {
102102
menuReport->Append(i, wxString(ri->name().c_str(), wxConvUTF8),
103103
wxString(ri->description().c_str(), wxConvUTF8));
104104
Connect(i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::Report));
105105
i++;
106106
}
107107

108-
auto menuAction = new wxMenu;
108+
auto menuAction = std::make_unique<wxMenu>();
109109
for (auto& ai : availableActions) {
110110
menuAction->Append(i, wxString(ai->name().c_str(), wxConvUTF8),
111111
wxString(ai->description().c_str(), wxConvUTF8));
112112
Connect(i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::Action));
113113
i++;
114114
}
115115

116-
auto *menuLayout = new wxMenu;
116+
auto menuLayout = std::make_unique<wxMenu>();
117117
menuLayout->Append(i, "Force-directed drawing", "Force-directed drawing");
118118
Connect(i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::Layout));
119119
i++;
120120
menuLayout->Append(i, "&Fit Width", "Fit Graph to Width");
121121
Connect(i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CGTeaFrame::OnFitWidth));
122-
auto menuHelp = new wxMenu;
122+
auto menuHelp = std::make_unique<wxMenu>();
123123
menuHelp->Append(wxID_ABOUT);
124-
wxMenuBar *menuBar = new wxMenuBar;
125-
menuBar->Append(menuFile, "&File");
126-
menuBar->Append(menuGenerate, "&Generate");
127-
menuBar->Append(menuReport, "&Report");
128-
menuBar->Append(menuAction, "&Action");
129-
menuBar->Append(menuLayout, "&Layout");
130-
menuBar->Append(menuHelp, "&Help");
131-
SetMenuBar(menuBar);
124+
auto menuBar = std::make_unique<wxMenuBar>();
125+
menuBar->Append(menuFile.release(), "&File");
126+
menuBar->Append(menuGenerate.release(), "&Generate");
127+
menuBar->Append(menuReport.release(), "&Report");
128+
menuBar->Append(menuAction.release(), "&Action");
129+
menuBar->Append(menuLayout.release(), "&Layout");
130+
menuBar->Append(menuHelp.release(), "&Help");
131+
SetMenuBar(menuBar.release());
132132
CreateStatusBar();
133133
SetStatusText("Welcome to CGTea!");
134134

@@ -147,11 +147,11 @@ CGTeaFrame::CGTeaFrame(const wxString& title, const wxPoint& pos, const wxSize&
147147
}
148148
}
149149

150-
void CGTeaFrame::OnExit(wxCommandEvent& event) {
150+
void CGTeaFrame::OnExit(wxCommandEvent&) {
151151
Close(true);
152152
}
153153

154-
void CGTeaFrame::OnAbout(wxCommandEvent& event) {
154+
void CGTeaFrame::OnAbout(wxCommandEvent&) {
155155
wxMessageBox("CGTea is a C++-version of GraphTea, a software for working with graphs.",
156156
"CGTea 1.0", wxOK | wxICON_INFORMATION);
157157
}
@@ -220,7 +220,7 @@ void CGTeaFrame::Report(wxCommandEvent& event) {
220220
const int id = event.GetId();
221221
const std::string report_results = availableReports[id - availableGenerators.size() - 1]->report(currentGraph);
222222
const std::string report_name = availableReports[id - availableGenerators.size() - 1]->name();
223-
((CGTeaSidebar*)this->GetSizer()->GetChildren()[0]->GetWindow())->statistics_text->SetValue(report_name + ": " +report_results);
223+
static_cast<CGTeaSidebar*>(this->GetSizer()->GetChildren()[0]->GetWindow())->statistics_text->SetValue(report_name + ": " +report_results);
224224
}
225225

226226
void CGTeaFrame::Action(wxCommandEvent& event) {

generators/Antiprism.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Antiprism : public GeneratorInterface {
3131
std::vector<cgtea_geometry::Point> pos2 = position_generators::circle(width, height, 200.0, n);
3232
pos1.insert(pos1.end(), pos2.begin(), pos2.end());
3333
int i = 0;
34-
for_each_v(g, [&](Ver v) {
34+
for_each_v(g, [&](const Ver v) {
3535
boost::put(boost::vertex_distance, g, v, pos1[i]);
3636
i++;
3737
});

generators/Banana.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Banana : public GeneratorInterface {
2323
Graph g = generate(n, k);
2424
std::vector<cgtea_geometry::Point> pos = position_generators::circle(width, height, 100.0, n);
2525
int i = 0;
26-
for_each_v(g, [&](Ver v) {
26+
for_each_v(g, [&](const Ver v) {
2727
boost::put(boost::vertex_distance, g, v, pos[i]);
2828
i++;
2929
});

generators/CocktailParty.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CocktailParty : public GeneratorInterface {
3333
}
3434
std::vector<cgtea_geometry::Point> pos = position_generators::circle(width, height, 200.0, 2*n);
3535

36-
for_each_v(g, [&](Ver v) {boost::put(boost::vertex_distance, g, v, pos[v]);});
36+
for_each_v(g, [&](const Ver v) {boost::put(boost::vertex_distance, g, v, pos[v]);});
3737
return g;
3838
}
3939

generators/Complete.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Complete : public GeneratorInterface {
2020

2121
Graph generate_with_positions(unsigned int n, unsigned int k, double width, double height) override {
2222
Graph g = generate(n, k);
23-
std::vector<cgtea_geometry::Point> pos = position_generators::circle(width, height, 100.0, n);
23+
const std::vector<cgtea_geometry::Point> pos = position_generators::circle(width, height, 100.0, n);
2424
int i = 0;
2525
for_each_v(g, [&](Ver v) {
2626
boost::put(boost::vertex_distance, g, v, pos[i]);

generators/GeneratorInterface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class GeneratorInterface {
1818
virtual Graph
1919
generate_with_positions(unsigned int n, unsigned int k, double width, double height) { return Graph(); };
2020

21-
Graph generate_with_force_directed(unsigned int n, unsigned int k, double width, double height) {
21+
Graph generate_with_force_directed(const unsigned int n, const unsigned int k, const double width, const double height) {
2222
Graph g = generate(n, k);
23-
std::vector<cgtea_geometry::Point> pos = compute_force_directed(50, 50, width, height, g);
23+
const std::vector<cgtea_geometry::Point> pos = compute_force_directed(50, 50, width, height, g);
2424
int i = 0;
25-
for_each_v(g, [&](Ver v) {
25+
for_each_v(g, [&](const Ver v) {
2626
boost::put(boost::vertex_distance, g, v, pos[i]);
2727
i++;
2828
});

0 commit comments

Comments
 (0)