Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unique_ptr for gerbv_project_t #551

Merged
merged 1 commit into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions drill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,6 @@ ExcellonProcessor::ExcellonProcessor(const boost::program_options::variables_map
tiling = std::make_unique<Tiling>(tileInfo, cfactor, ocodes.getUniqueCode());
}

/******************************************************************************/
/*
Destructor
*/
/******************************************************************************/
ExcellonProcessor::~ExcellonProcessor()
{
gerbv_destroy_project(project);
}

/******************************************************************************/
/*
*/
Expand Down Expand Up @@ -697,12 +687,12 @@ void ExcellonProcessor::save_svg(
}
}

gerbv_project_t* ExcellonProcessor::parse_project(const string& filename) {
gerbv_project_t* project = gerbv_create_project();
std::unique_ptr<gerbv_project_t, ExcellonProcessor::GerbvDeleter> ExcellonProcessor::parse_project(const string& filename) {
auto project = std::unique_ptr<gerbv_project_t, GerbvDeleter>(gerbv_create_project());
auto gerb_filename = std::make_unique<char[]>(filename.size() + 1);
strcpy(gerb_filename.get(), filename.c_str());

gerbv_open_layer_from_filename(project, gerb_filename.get());
gerbv_open_layer_from_filename(project.get(), gerb_filename.get());

if (project->file[0] == NULL) {
throw drill_exception();
Expand Down
8 changes: 5 additions & 3 deletions drill.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class ExcellonProcessor
public:
ExcellonProcessor(const boost::program_options::variables_map& options,
const point_type_fp min, const point_type_fp max);
~ExcellonProcessor();
void add_header(std::string);
void set_preamble(std::string);
void set_postamble(std::string);
Expand All @@ -93,7 +92,10 @@ class ExcellonProcessor
std::shared_ptr< std::map<int, multi_linestring_type_fp> > get_holes();

private:
gerbv_project_t* parse_project(const std::string& filename);
struct GerbvDeleter {
void operator()(gerbv_project_t* p) { gerbv_destroy_project(p); }
};
std::unique_ptr<gerbv_project_t, GerbvDeleter> parse_project(const std::string& filename);
std::map<int, drillbit> parse_bits();
std::map<int, multi_linestring_type_fp> parse_holes();

Expand All @@ -116,7 +118,7 @@ class ExcellonProcessor
const box_type_fp board_dimensions;
const coordinate_type_fp board_center_x;

gerbv_project_t * const project;
std::unique_ptr<gerbv_project_t, GerbvDeleter> const project;
const bool bMetricOutput; //Flag to indicate metric output
const std::map<int, drillbit> parsed_bits;
const std::map<int, multi_linestring_type_fp> parsed_holes;
Expand Down