Skip to content

Commit

Permalink
Use unique_ptr for gerbv_project_t
Browse files Browse the repository at this point in the history
This removes a raw pointer but requires a custom deleter.
  • Loading branch information
eyal0 committed Feb 21, 2021
1 parent 5f68f7a commit 5784c09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
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

0 comments on commit 5784c09

Please sign in to comment.