diff --git a/drill.cpp b/drill.cpp index ba9923cc6..c06a6e58c 100644 --- a/drill.cpp +++ b/drill.cpp @@ -120,16 +120,6 @@ ExcellonProcessor::ExcellonProcessor(const boost::program_options::variables_map tiling = std::make_unique(tileInfo, cfactor, ocodes.getUniqueCode()); } -/******************************************************************************/ -/* - Destructor - */ -/******************************************************************************/ -ExcellonProcessor::~ExcellonProcessor() -{ - gerbv_destroy_project(project); -} - /******************************************************************************/ /* */ @@ -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 ExcellonProcessor::parse_project(const string& filename) { + auto project = std::unique_ptr(gerbv_create_project()); auto gerb_filename = std::make_unique(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(); diff --git a/drill.hpp b/drill.hpp index afebf2bdd..042361373 100644 --- a/drill.hpp +++ b/drill.hpp @@ -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); @@ -93,7 +92,10 @@ class ExcellonProcessor std::shared_ptr< std::map > 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 parse_project(const std::string& filename); std::map parse_bits(); std::map parse_holes(); @@ -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 const project; const bool bMetricOutput; //Flag to indicate metric output const std::map parsed_bits; const std::map parsed_holes;