Skip to content

Commit

Permalink
refactor: Remove all usage of new
Browse files Browse the repository at this point in the history
  • Loading branch information
eyal0 committed Feb 9, 2021
1 parent aaa1461 commit 120ef80
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
9 changes: 5 additions & 4 deletions board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "board.hpp"
#include <memory>
using std::shared_ptr;
using std::make_shared;
using std::dynamic_pointer_cast;

#include <string>
Expand Down Expand Up @@ -125,20 +126,20 @@ void Board::createLayers()
shared_ptr<GerberImporter> importer = get<0>(prepared_layer.second);
const bool fill = fill_outline && prepared_layer.first == "outline";

shared_ptr<Surface_vectorial> surface(new Surface_vectorial(
auto surface = make_shared<Surface_vectorial>(
30,
bounding_box,
prepared_layer.first, outputdir, tsp_2opt,
mill_feed_direction, invert_gerbers,
render_paths_to_shapes || (prepared_layer.first == "outline")));
render_paths_to_shapes || (prepared_layer.first == "outline"));
if (fill) {
surface->enable_filling();
}
surface->render(importer, get<1>(prepared_layer.second)->optimise);
shared_ptr<Layer> layer(new Layer(prepared_layer.first,
auto layer = make_shared<Layer>(prepared_layer.first,
surface,
get<1>(prepared_layer.second),
get<2>(prepared_layer.second))); // see comment for prep_t in board.hpp
get<2>(prepared_layer.second)); // see comment for prep_t in board.hpp
layers.insert(std::make_pair(layer->get_name(), layer));
}

Expand Down
10 changes: 4 additions & 6 deletions drill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ ExcellonProcessor::ExcellonProcessor(const boost::program_options::variables_map

preamble += "G90 (Absolute coordinates.)\n";

tiling = std::unique_ptr<Tiling>(new Tiling(tileInfo, cfactor, ocodes.getUniqueCode()));
tiling = std::make_unique<Tiling>(tileInfo, cfactor, ocodes.getUniqueCode());
}

/******************************************************************************/
Expand Down Expand Up @@ -699,12 +699,10 @@ void ExcellonProcessor::save_svg(

gerbv_project_t* ExcellonProcessor::parse_project(const string& filename) {
gerbv_project_t* project = gerbv_create_project();
const char* cfilename = filename.c_str();
char *gerb_filename = new char[strlen(cfilename) + 1];
strcpy(gerb_filename, cfilename);
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);
delete[] gerb_filename;
gerbv_open_layer_from_filename(project, gerb_filename.get());

if (project->file[0] == NULL) {
throw drill_exception();
Expand Down
1 change: 0 additions & 1 deletion gerberimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ pair<multi_polygon_type_fp, map<coordinate_type_fp, multi_linestring_type_fp>> G
bool render_paths_to_shapes,
unsigned int points_per_circle) const {
ring_type_fp region;
unique_ptr<multi_polygon_type_fp> temp_mpoly (new multi_polygon_type_fp());
bool contour = false; // Are we in contour mode?

vector<pair<const gerbv_layer_t *, vector<mp_pair>>> layers(1);
Expand Down
23 changes: 11 additions & 12 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using std::endl;
using std::flush;
using std::fstream;
using std::shared_ptr;
using std::make_shared;

#include <string>
using std::string;
Expand Down Expand Up @@ -92,8 +93,7 @@ void do_pcb2gcode(int argc, const char* argv[]) {

if (vm.count("front") || vm.count("back"))
{
isolator = shared_ptr<Isolator>(new Isolator());
// TODO: support more than one mill-diameter.
isolator = make_shared<Isolator>();
for (const auto& tool_diameter : flatten(vm["mill-diameters"].as<std::vector<CommaSeparated<Length>>>())) {
isolator->tool_diameters_and_overlap_widths.push_back(
std::make_pair(
Expand Down Expand Up @@ -135,7 +135,7 @@ void do_pcb2gcode(int argc, const char* argv[]) {
isolator->spindown_time = spindown_time;
}

shared_ptr<Cutter> cutter(new Cutter());
auto cutter = make_shared<Cutter>();

if (vm.count("outline") ||
(vm.count("drill") &&
Expand Down Expand Up @@ -173,7 +173,7 @@ void do_pcb2gcode(int argc, const char* argv[]) {

if (vm.count("drill"))
{
driller = shared_ptr<Driller>(new Driller());
driller = make_shared<Driller>();
driller->zwork = vm["zdrill"].as<Length>().asInch(unit);
driller->zsafe = vm["zsafe"].as<Length>().asInch(unit);
driller->feed = vm["drill-feed"].as<Velocity>().asInchPerMinute(unit);
Expand Down Expand Up @@ -259,14 +259,13 @@ void do_pcb2gcode(int argc, const char* argv[]) {

//---------------------------------------------------------------------------

shared_ptr<Board> board(
new Board(
auto board = make_shared<Board>(
vm["fill-outline"].as<bool>(),
outputdir,
vm["tsp-2opt"].as<bool>(),
vm["mill-feed-direction"].as<MillFeedDirection::MillFeedDirection>(),
vm["invert-gerbers"].as<bool>(),
!vm["draw-gerber-lines"].as<bool>()));
!vm["draw-gerber-lines"].as<bool>());

// this is currently disabled, use --outline instead
if (vm.count("margins"))
Expand All @@ -280,7 +279,7 @@ void do_pcb2gcode(int argc, const char* argv[]) {
cout << "Importing front side... " << flush;
if (vm.count("front") > 0) {
string frontfile = vm["front"].as<string>();
shared_ptr<GerberImporter> importer(new GerberImporter());
auto importer = make_shared<GerberImporter>();
if (!importer->load_file(frontfile)) {
options::maybe_throw("ERROR.", ERR_INVALIDPARAMETER);
}
Expand All @@ -293,7 +292,7 @@ void do_pcb2gcode(int argc, const char* argv[]) {
cout << "Importing back side... " << flush;
if (vm.count("back") > 0) {
string backfile = vm["back"].as<string>();
shared_ptr<GerberImporter> importer(new GerberImporter());
auto importer = make_shared<GerberImporter>();
if (!importer->load_file(backfile)) {
options::maybe_throw("ERROR.", ERR_INVALIDPARAMETER);
}
Expand All @@ -306,7 +305,7 @@ void do_pcb2gcode(int argc, const char* argv[]) {
cout << "Importing outline... " << flush;
if (vm.count("outline") > 0) {
string outline = vm["outline"].as<string>();
shared_ptr<GerberImporter> importer(new GerberImporter());
auto importer = make_shared<GerberImporter>();
if (!importer->load_file(outline)) {
options::maybe_throw("ERROR.", ERR_INVALIDPARAMETER);
}
Expand All @@ -321,7 +320,7 @@ void do_pcb2gcode(int argc, const char* argv[]) {
cout << "DONE.\n";

if (!vm["no-export"].as<bool>()) {
shared_ptr<NGC_Exporter> exporter(new NGC_Exporter(board));
auto exporter = make_shared<NGC_Exporter>(board);
exporter->add_header(PACKAGE_STRING);

if (vm.count("preamble") || vm.count("preamble-text")) {
Expand Down Expand Up @@ -352,7 +351,7 @@ void do_pcb2gcode(int argc, const char* argv[]) {
//best we can do)
if(board->get_layersnum() == 0)
{
shared_ptr<GerberImporter> importer(new GerberImporter());
auto importer = make_shared<GerberImporter>();
if (!importer->load_file(vm["drill"].as<string>())) {
options::maybe_throw("ERROR.", ERR_INVALIDPARAMETER);
}
Expand Down
5 changes: 3 additions & 2 deletions svg_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using std::string;
using std::unique_ptr;
using std::make_unique;

svg_writer::svg_writer(string filename, box_type_fp bounding_box) :
output_file(filename),
Expand All @@ -25,8 +26,8 @@ svg_writer::svg_writer(string filename, box_type_fp bounding_box) :
const string svg_dimensions =
str(boost::format("width=\"%1%\" height=\"%2%\" viewBox=\"0 0 %3% %4%\"") % width % height % viewBox_width % viewBox_height);

mapper = unique_ptr<bg::svg_mapper<point_type_fp>>
(new bg::svg_mapper<point_type_fp>(output_file, viewBox_width, viewBox_height, svg_dimensions));
mapper = make_unique<bg::svg_mapper<point_type_fp>>(
output_file, viewBox_width, viewBox_height, svg_dimensions);
mapper->add(bounding_box);
}

Expand Down

0 comments on commit 120ef80

Please sign in to comment.