Skip to content

Commit 3f7f85e

Browse files
committed
some refactoring
1 parent 8263b04 commit 3f7f85e

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

CGTeaSidebar.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@ CGTeaSidebar::CGTeaSidebar(CGTeaFrame *parent, wxWindowID winid) : wxPanel(paren
1111
wxFont font = statistics_text->GetFont();
1212
font.SetPointSize(16);
1313
statistics_text->SetFont(font);
14-
15-
wxButton* compute_stat = new wxButton(this, 100, "Compute Statistics");
14+
auto compute_stat = std::make_unique<wxButton>(this, 100, "Compute Statistics");
1615
Connect(100, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(CGTeaSidebar::computeStat));
17-
18-
wxBoxSizer* panel1Sizer = new wxBoxSizer(wxVERTICAL);
16+
auto panel1Sizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
1917
panel1Sizer->Add(statistics_text, 4, wxEXPAND | wxALL, 8);//, 1, wxLEFT, 8);
20-
panel1Sizer->Add(compute_stat, 1, wxEXPAND | wxBOTTOM, 8);
21-
SetSizer(panel1Sizer);
18+
panel1Sizer->Add(compute_stat.release(), 1, wxEXPAND | wxBOTTOM, 8);
19+
SetSizer(panel1Sizer.release());
2220
}
2321

2422
void CGTeaSidebar::computeStat(wxCommandEvent & WXUNUSED(event))
2523
{
26-
auto frame = ((CGTeaFrame*)this->m_parent);
24+
auto frame = static_cast<CGTeaFrame*>(this->m_parent);
2725
string out;
28-
for(auto& gi : frame->availableReports) {
26+
for(const auto& gi : frame->availableReports) {
2927
out += gi->name() + ": " + gi->report(frame->currentGraph) + "\n";
3028
}
3129
statistics_text->SetValue(wxString(out.c_str()));

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.10)
22
project(CGTea)
33
set(CMAKE_CXX_STANDARD 17)
44
find_package(wxWidgets REQUIRED COMPONENTS net core base)
5+
find_package(Boost COMPONENTS system filesystem unit_test_framework REQUIRED)
56
include(${wxWidgets_USE_FILE})
67
include_directories(${Boost_INCLUDE_DIRS})
78
file(GLOB BoostTestSrc "BoostTestSrc/*.cpp")
@@ -12,5 +13,6 @@ file(GLOB ConjectureCheck "ConjectureCheck/*.cpp")
1213
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
1314
#set( CMAKE_CXX_FLAGS "`wx-config --cxxflags --libs`")
1415
add_executable(CGTea CGTeaApp.cpp BasicDrawPane.cpp CGTeaFrame.cpp CGTeaSidebar.cpp ${Reports} ${Generators} ${Actions})
16+
add_executable(BoostTest ${Reports} ${Generators} ${BoostTestSrc} ${ConjectureCheck} ${Actions})
1517
target_link_libraries(CGTea ${wxWidgets_LIBRARIES} ${Boost_LIBRARIES})
16-
18+
target_link_libraries(BoostTest ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})

datatypes.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "boost/graph/sequential_vertex_coloring.hpp"
77
#include "boost/cstdlib.hpp"
88
#include "boost/graph/topology.hpp"
9-
#include <memory>
109
#include <fstream>
1110
#include <boost/dynamic_bitset.hpp>
1211
#include <random>
@@ -45,22 +44,20 @@ typedef boost::graph_traits<Graph>::edge_iterator E_iter;
4544
typedef Graph::vertex_descriptor Ver;
4645
typedef Graph::edge_descriptor Edge;
4746
typedef boost::property_map<Graph, boost::edge_weight_t>::type edge_weight_type;
48-
typedef boost::dynamic_bitset<> dynbit;
47+
typedef boost::dynamic_bitset<> computed_dynamic_bit;
4948

5049
//typedef std::vector<boost::square_topology<minstd_rand>::point> PositionVec;
5150
//typedef boost::iterator_property_map<PositionVec::iterator, boost::property_map<Graph, boost::vertex_index_t>::type> PositionMap;
5251

5352
template<typename Lambda>
5453
static void for_each_v(Graph& g, Lambda func) {
55-
V_iter vi, vi_end;
56-
tie(vi, vi_end) = vertices(g);
54+
auto [vi, vi_end] = vertices(g);
5755
std::for_each(vi,vi_end,func);
5856
}
5957

6058
template<typename Lambda>
6159
static void for_each_v_const(const Graph& g, Lambda func) {
62-
V_iter vi, vi_end;
63-
tie(vi, vi_end) = vertices(g);
60+
auto [vi, vi_end] = vertices(g);
6461
std::for_each(vi,vi_end,func);
6562
}
6663

@@ -79,7 +76,7 @@ static void for_each_e_const(const Graph& g, Lambda func) {
7976
}
8077

8178
//static string statistics(const Graph& g) {
82-
// tuple<double,double,double> t = eigen_values(g);
79+
// tuple<double, double, double> t = eigen_values(g);
8380
// string stat = string("Number of vertices:") + to_string( boost::num_vertices(g)) +
8481
// string("\nNumber of edges:") + to_string(boost::num_edges(g)) +
8582
// string("\nMaximum eigenvalue:" + to_string(std::get<0>(t))) +
@@ -88,17 +85,17 @@ static void for_each_e_const(const Graph& g, Lambda func) {
8885
// return stat;
8986
//}
9087

91-
static auto ge_degree = [](pair<int,int> t1, pair<int,int> t2){return t1.second>=t2.second;};
92-
static auto lt_degree = [](pair<int,int> t1, pair<int,int> t2){return t1.second<t2.second;};
88+
static auto ge_degree = [](const pair<int,int>& t1, const pair<int,int>& t2){return t1.second>=t2.second;};
89+
static auto lt_degree = [](const pair<int,int>& t1, const pair<int,int>& t2){return t1.second<t2.second;};
9390

94-
static bool cmp_degrees(pair<int,pair<int,int> > t1, pair<int,pair<int,int> > t2)
91+
static bool cmp_degrees(const pair<int,pair<int,int> >& t1, const pair<int,pair<int,int> >& t2)
9592
{
9693
if (t1.second.second < t2.second.second) {
97-
return 1;
94+
return true;
9895
} else if (t1.second.second == t2.second.second && t1.second.first < t2.second.first) {
99-
return 1;
96+
return true;
10097
} else {
101-
return 0;
98+
return false;
10299
}
103100
}
104101

@@ -107,7 +104,7 @@ static bool mysymmetric = false;
107104
/**
108105
* \brief Computes the fill-reducing ordering
109106
*
110-
* @param g the given simple graph which would be converted to a metis input format
107+
* @param g the given simple graph, which would be converted to a metis input format
111108
* @param name the name of the file which is given to metis command
112109
* @param met_ord the computed ordering in Metis
113110
*/

0 commit comments

Comments
 (0)