From 1716820c16f7639c56698206087627cba555c4aa Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sun, 20 Jan 2019 18:02:41 -0600 Subject: [PATCH] genapt: Resolve memory leaks. Reclaimed 1,419,778 bytes in 6,419 blocks. genapt memory stability : Good. --- src/Airports/GenAirports850/airport.cxx | 44 +++++----- src/Airports/GenAirports850/airport.hxx | 32 +++---- src/Airports/GenAirports850/beznode.hxx | 5 +- src/Airports/GenAirports850/closedpoly.cxx | 66 +++++--------- src/Airports/GenAirports850/closedpoly.hxx | 18 ++-- src/Airports/GenAirports850/elevations.cxx | 2 +- src/Airports/GenAirports850/helipad.hxx | 4 +- src/Airports/GenAirports850/linearfeature.cxx | 20 ++--- src/Airports/GenAirports850/linearfeature.hxx | 12 +-- .../GenAirports850/linked_objects.hxx | 8 +- src/Airports/GenAirports850/main.cxx | 4 +- src/Airports/GenAirports850/object.hxx | 4 +- src/Airports/GenAirports850/parser.cxx | 87 +++++++++---------- src/Airports/GenAirports850/parser.hxx | 61 ++++++------- src/Airports/GenAirports850/runway.hxx | 6 +- src/Airports/GenAirports850/scheduler.cxx | 19 ++-- src/Airports/GenAirports850/taxiway.hxx | 4 +- src/Lib/terragear/tg_surface.cxx | 2 +- 18 files changed, 196 insertions(+), 202 deletions(-) diff --git a/src/Airports/GenAirports850/airport.cxx b/src/Airports/GenAirports850/airport.cxx index 1ac75a08..6b87c6f4 100644 --- a/src/Airports/GenAirports850/airport.cxx +++ b/src/Airports/GenAirports850/airport.cxx @@ -93,59 +93,59 @@ Airport::Airport( int c, char* def) Airport::~Airport() { - for (unsigned int i=0; i + #include #include #include @@ -20,46 +22,46 @@ public: Airport( int c, char* def); ~Airport(); - void AddRunway( Runway* runway ) + void AddRunway( std::shared_ptr runway ) { runways.push_back( runway ); } - void AddWaterRunway( WaterRunway* waterrunway ) + void AddWaterRunway( std::shared_ptr waterrunway ) { waterrunways.push_back( waterrunway ); } - void AddObj( LightingObj* lightobj ) + void AddObj( std::shared_ptr lightobj ) { lightobjects.push_back( lightobj ); } - void AddHelipad( Helipad* helipad ) + void AddHelipad( std::shared_ptr helipad ) { helipads.push_back( helipad ); } - void AddTaxiway( Taxiway* taxiway ) + void AddTaxiway( std::shared_ptr taxiway ) { taxiways.push_back( taxiway ); } - void AddPavement( ClosedPoly* pavement ) + void AddPavement( std::shared_ptr pavement ) { pavements.push_back( pavement ); } - void AddFeature( LinearFeature* feature ) + void AddFeature( std::shared_ptr feature ) { features.push_back( feature ); } - void AddFeatures( FeatureList* feature_list ) + void AddFeatures( FeatureList feature_list ) { - for (unsigned int i=0; isize(); i++) + for (auto feature : feature_list) { - features.push_back( feature_list->at(i) ); + features.push_back( feature ); } } @@ -68,22 +70,22 @@ public: return features.size(); } - void AddBoundary( ClosedPoly* bndry ) + void AddBoundary( std::shared_ptr bndry ) { boundary.push_back( bndry ); } - void AddWindsock( Windsock* windsock ) + void AddWindsock( std::shared_ptr windsock ) { windsocks.push_back( windsock ); } - void AddBeacon( Beacon* beacon ) + void AddBeacon( std::shared_ptr beacon ) { beacons.push_back( beacon ); } - void AddSign( Sign* sign ) + void AddSign( std::shared_ptr sign ) { signs.push_back( sign ); } @@ -163,6 +165,6 @@ private: debug_map debug_features; }; -typedef std::vector AirportList; +typedef std::vector> AirportList; #endif diff --git a/src/Airports/GenAirports850/beznode.hxx b/src/Airports/GenAirports850/beznode.hxx index 3fcac81f..7fc5524b 100644 --- a/src/Airports/GenAirports850/beznode.hxx +++ b/src/Airports/GenAirports850/beznode.hxx @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -282,8 +283,8 @@ private: // array of BezNodes make a contour -typedef std::vector BezContour; -typedef std::vector BezContourArray; +typedef std::vector> BezContour; +typedef std::vector BezContourArray; #endif diff --git a/src/Airports/GenAirports850/closedpoly.cxx b/src/Airports/GenAirports850/closedpoly.cxx index 3efb82c4..a0313f02 100644 --- a/src/Airports/GenAirports850/closedpoly.cxx +++ b/src/Airports/GenAirports850/closedpoly.cxx @@ -37,9 +37,8 @@ ClosedPoly::ClosedPoly( char* desc ) description = "none"; } - boundary = NULL; - cur_contour = NULL; - cur_feature = NULL; + boundary.clear(); + cur_contour.clear(); } ClosedPoly::ClosedPoly( int st, float s, float th, char* desc ) @@ -62,9 +61,8 @@ ClosedPoly::ClosedPoly( int st, float s, float th, char* desc ) description = "none"; } - boundary = NULL; - cur_contour = NULL; - cur_feature = NULL; + boundary.clear(); + cur_contour.clear(); } ClosedPoly::~ClosedPoly() @@ -72,14 +70,9 @@ ClosedPoly::~ClosedPoly() TG_LOG( SG_GENERAL, SG_DEBUG, "Deleting ClosedPoly " << description ); } -void ClosedPoly::AddNode( BezNode* node ) +void ClosedPoly::AddNode( std::shared_ptr node ) { - // if this is the first node of the contour - create a new contour - if (!cur_contour) - { - cur_contour = new BezContour; - } - cur_contour->push_back( node ); + cur_contour.push_back( node ); TG_LOG(SG_GENERAL, SG_DEBUG, "CLOSEDPOLY::ADDNODE : " << node->GetLoc() ); @@ -89,7 +82,7 @@ void ClosedPoly::AddNode( BezNode* node ) if (!cur_feature) { std::string feature_desc = description + " - "; - if (boundary) + if (boundary.size() == 0) { feature_desc += "hole"; } @@ -99,7 +92,7 @@ void ClosedPoly::AddNode( BezNode* node ) } TG_LOG(SG_GENERAL, SG_DEBUG, " Adding node " << node->GetLoc() << " to current linear feature " << cur_feature); - cur_feature = new LinearFeature(feature_desc, 1.0f ); + cur_feature = std::make_shared(feature_desc, 1.0f); } cur_feature->AddNode( node ); } @@ -122,26 +115,26 @@ void ClosedPoly::CloseCurContour() // add the contour to the poly - first one is the outer boundary // subsequent contours are holes - if ( boundary == NULL ) + if ( boundary.size() == 0 ) { boundary = cur_contour; // generate the convex hull from the bezcontour node locations // CreateConvexHull(); - cur_contour = NULL; + cur_contour.clear(); } else { holes.push_back( cur_contour ); - cur_contour = NULL; + cur_contour.clear(); } } -void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst ) +void ClosedPoly::ConvertContour( const BezContour& src, tgContour& dst ) { - BezNode* curNode; - BezNode* nextNode; + std::shared_ptr curNode; + std::shared_ptr nextNode; SGGeod curLoc; SGGeod nextLoc; @@ -152,25 +145,25 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst ) double total_dist; int num_segs = BEZIER_DETAIL; - TG_LOG(SG_GENERAL, SG_DEBUG, "Creating a contour with " << src->size() << " nodes"); + TG_LOG(SG_GENERAL, SG_DEBUG, "Creating a contour with " << src.size() << " nodes"); // clear anything in this point list dst.Erase(); // iterate through each bezier node in the contour - for (unsigned int i = 0; i <= src->size()-1; i++) + for (unsigned int i = 0; i <= src.size()-1; i++) { TG_LOG(SG_GENERAL, SG_DEBUG, "\nHandling Node " << i << "\n\n"); - curNode = src->at(i); - if (i < src->size() - 1) + curNode = src.at(i); + if (i < src.size() - 1) { - nextNode = src->at(i+1); + nextNode = src.at(i + 1); } else { // for the last node, next is the first. as all contours are closed - nextNode = src->at(0); + nextNode = src.at(0); } // now determine how we will iterate from current node to next node @@ -337,14 +330,14 @@ void ClosedPoly::Finish() tgContour dst_contour; // error handling - if (boundary == NULL) + if (boundary.size() == 0) { TG_LOG(SG_GENERAL, SG_ALERT, "no boundary"); } TG_LOG(SG_GENERAL, SG_DEBUG, "Converting a poly with " << holes.size() << " holes"); - if (boundary != NULL) + if (boundary.size() != 0) { // create the boundary ConvertContour( boundary, dst_contour ); @@ -367,22 +360,9 @@ void ClosedPoly::Finish() } // save memory by deleting unneeded resources - for (unsigned int i=0; isize(); i++) - { - delete boundary->at(i); - } - delete boundary; - boundary = NULL; + boundary.clear(); // and the hole contours - for (unsigned int i=0; isize(); j++) - { - delete holes[i]->at(j); - } - } - holes.clear(); } diff --git a/src/Airports/GenAirports850/closedpoly.hxx b/src/Airports/GenAirports850/closedpoly.hxx index 623add8b..a400d57c 100644 --- a/src/Airports/GenAirports850/closedpoly.hxx +++ b/src/Airports/GenAirports850/closedpoly.hxx @@ -1,6 +1,8 @@ #ifndef _BEZPOLY_H_ #define _BEZPOLY_H_ +#include + #include #include "beznode.hxx" @@ -14,7 +16,7 @@ public: ~ClosedPoly(); inline std::string GetDescription() { return description; } - void AddNode( BezNode* node ); + void AddNode( std::shared_ptr node ); void CloseCurContour(); void Finish(); @@ -36,15 +38,15 @@ public: tgAccumulator& accum, std::string& shapefile_name ); - FeatureList* GetFeatures() + FeatureList& GetFeatures() { - return &features; + return features; } private: // convert the BezierPoly to a normal Poly (adding nodes for the curves) void CreateConvexHull( void ); - void ConvertContour( BezContour* src, tgContour& dst ); + void ConvertContour( const BezContour& src, tgContour& dst ); std::string GetMaterial( int surface ); @@ -58,13 +60,13 @@ private: std::string description; // outer boundary definition as bezier nodes - BezContour* boundary; + BezContour boundary; // holes BezContourArray holes; // contour that nodes will be added until done - BezContour* cur_contour; + BezContour cur_contour; // Converted polygon after parsing complete tgPolygon pre_tess; @@ -73,10 +75,10 @@ private: tgpolygon_list shoulder_polys; // pavement definitions have multiple linear features (markings and lights for each contour) - LinearFeature* cur_feature; + std::shared_ptr cur_feature; FeatureList features; }; -typedef std::vector PavementList; +typedef std::vector> PavementList; #endif diff --git a/src/Airports/GenAirports850/elevations.cxx b/src/Airports/GenAirports850/elevations.cxx index 5607c290..3e017beb 100644 --- a/src/Airports/GenAirports850/elevations.cxx +++ b/src/Airports/GenAirports850/elevations.cxx @@ -109,7 +109,7 @@ double tgAverageElevation( const std::string &root, const string_list elev_src, } } - array.close(); + array.unload(); } else { done = true; } diff --git a/src/Airports/GenAirports850/helipad.hxx b/src/Airports/GenAirports850/helipad.hxx index 654734d4..5127f24e 100644 --- a/src/Airports/GenAirports850/helipad.hxx +++ b/src/Airports/GenAirports850/helipad.hxx @@ -16,6 +16,8 @@ #ifndef _HELIPAD_HXX #define _HELIPAD_HXX +#include + #include #include #include @@ -91,6 +93,6 @@ private: }; -typedef std::vector HelipadList; +typedef std::vector> HelipadList; #endif diff --git a/src/Airports/GenAirports850/linearfeature.cxx b/src/Airports/GenAirports850/linearfeature.cxx index fe5bdcf7..b8a0ed67 100644 --- a/src/Airports/GenAirports850/linearfeature.cxx +++ b/src/Airports/GenAirports850/linearfeature.cxx @@ -4,10 +4,10 @@ #include "beznode.hxx" #include "linearfeature.hxx" -void LinearFeature::ConvertContour( BezContour* src, bool closed ) +void LinearFeature::ConvertContour( const BezContour& src, bool closed ) { - BezNode* curNode; - BezNode* nextNode; + std::shared_ptr curNode; + std::shared_ptr nextNode; SGGeod curLoc; SGGeod nextLoc; @@ -22,24 +22,24 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed ) Marking* cur_mark = NULL; Lighting* cur_light = NULL; - TG_LOG(SG_GENERAL, SG_DEBUG, " LinearFeature::ConvertContour - Creating a contour with " << src->size() << " nodes"); + TG_LOG(SG_GENERAL, SG_DEBUG, " LinearFeature::ConvertContour - Creating a contour with " << src.size() << " nodes"); // clear anything in the point list points.Erase(); // iterate through each bezier node in the contour - for (unsigned int i=0; i <= src->size()-1; i++) + for (unsigned int i = 0; i <= src.size() - 1; ++i) { - curNode = src->at(i); + curNode = src.at(i); - if (i < src->size() - 1) + if (i < src.size() - 1) { - nextNode = src->at(i+1); + nextNode = src.at(i+1); } else { // for the last node, next is the first. as all contours are closed - nextNode = src->at(0); + nextNode = src.at(0); } //////////////////////////////////////////////////////////////////////////////////// @@ -380,7 +380,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx ) // create the inner and outer boundaries to generate polys // this generates 2 point lists for the contours, and remembers // the start stop points for markings and lights - ConvertContour( &contour, closed ); + ConvertContour( contour, closed ); // now generate the supoerpoly and texparams lists for markings for (unsigned int i=0; i + #include #include #include @@ -46,7 +48,7 @@ public: unsigned int start_idx; unsigned int end_idx; }; -typedef std::vector MarkingList; +typedef std::vector MarkingList; struct Lighting { @@ -65,7 +67,7 @@ public: return 0; } }; -typedef std::vector LightingList; +typedef std::vector LightingList; class LinearFeature { @@ -93,7 +95,7 @@ public: inline std::string GetDescription() { return description; } - void AddNode( BezNode* b ) + void AddNode( std::shared_ptr b ) { contour.push_back( b ); } @@ -111,7 +113,7 @@ private: LightingList lights; Lighting* cur_light; - void ConvertContour( BezContour* src, bool closed ); + void ConvertContour( const BezContour& src, bool closed ); // text description std::string description; @@ -126,6 +128,6 @@ private: tglightcontour_list lighting_polys; }; -typedef std::vector FeatureList; +typedef std::vector> FeatureList; #endif diff --git a/src/Airports/GenAirports850/linked_objects.hxx b/src/Airports/GenAirports850/linked_objects.hxx index c7ddf071..b50f4205 100644 --- a/src/Airports/GenAirports850/linked_objects.hxx +++ b/src/Airports/GenAirports850/linked_objects.hxx @@ -1,6 +1,8 @@ #ifndef _LINKED_OBJECTS_H_ #define _LINKED_OBJECTS_H_ +#include + #include class Windsock @@ -23,7 +25,7 @@ public: } }; -typedef std::vector WindsockList; +typedef std::vector> WindsockList; class Beacon @@ -46,7 +48,7 @@ public: } }; -typedef std::vector BeaconList; +typedef std::vector> BeaconList; class Sign { @@ -81,6 +83,6 @@ public: } }; -typedef std::vector SignList; +typedef std::vector> SignList; #endif diff --git a/src/Airports/GenAirports850/main.cxx b/src/Airports/GenAirports850/main.cxx index b6abdb88..f64705e4 100644 --- a/src/Airports/GenAirports850/main.cxx +++ b/src/Airports/GenAirports850/main.cxx @@ -57,6 +57,8 @@ void setup_default_elevation_sources(string_list& elev_src) { elev_src.push_back( "SRTM-1" ); elev_src.push_back( "SRTM-3" ); elev_src.push_back( "SRTM-30" ); + elev_src.push_back( "SRTMGL1" ); + elev_src.push_back( "SRTMGL3" ); } // Display help and usage @@ -349,7 +351,7 @@ int main(int argc, char **argv) } // Create the scheduler - Scheduler* scheduler = new Scheduler(input_file, work_dir, elev_src); + auto scheduler = std::make_unique(input_file, work_dir, elev_src); // auto scheduler = std::unique_ptr(new Scheduler(input_file, work_dir, elev_src)); // Add any debug diff --git a/src/Airports/GenAirports850/object.hxx b/src/Airports/GenAirports850/object.hxx index 361bd1b9..d819a574 100644 --- a/src/Airports/GenAirports850/object.hxx +++ b/src/Airports/GenAirports850/object.hxx @@ -1,6 +1,8 @@ #ifndef _OBJECT_H_ #define _OBJECT_H_ +#include + #include #include @@ -20,6 +22,6 @@ public: void BuildBtg( tglightcontour_list& lights ); }; -typedef std::vector LightingObjList; +typedef std::vector> LightingObjList; #endif diff --git a/src/Airports/GenAirports850/parser.cxx b/src/Airports/GenAirports850/parser.cxx index 92269fb2..9585774a 100644 --- a/src/Airports/GenAirports850/parser.cxx +++ b/src/Airports/GenAirports850/parser.cxx @@ -236,8 +236,7 @@ void Parser::run() cur_airport->GetCleanupTime( clean_time ); cur_airport->GetTriangulationTime( triangulation_time ); - delete cur_airport; - cur_airport = NULL; + cur_airport = nullptr; } log_time = time(0); @@ -250,12 +249,12 @@ void Parser::run() } } -BezNode* Parser::ParseNode( int type, char* line, BezNode* prevNode ) +std::shared_ptr Parser::ParseNode( int type, char* line, std::shared_ptr prevNode ) { double lat, lon; double ctrl_lat, ctrl_lon; int feat_type1, feat_type2; - BezNode *curNode = NULL; + std::shared_ptr curNode = nullptr; bool hasCtrl = false; bool close = false; @@ -347,15 +346,15 @@ BezNode* Parser::ParseNode( int type, char* line, BezNode* prevNode ) } // if this is a new node, add it - as first part never has prev cp - if (curNode == NULL) + if (curNode == nullptr) { if (hasCtrl) { - curNode = new BezNode(lat, lon, ctrl_lat, ctrl_lon); + curNode = std::make_shared(lat, lon, ctrl_lat, ctrl_lon); } else { - curNode = new BezNode(lat, lon); + curNode = std::make_shared(lat, lon); } } @@ -386,35 +385,35 @@ BezNode* Parser::ParseNode( int type, char* line, BezNode* prevNode ) curNode->SetTerm( term ); curNode->SetClose( close ); - return curNode; + return std::move(curNode); } -LinearFeature* Parser::ParseFeature( char* line ) +std::shared_ptr Parser::ParseFeature( char* line ) { - LinearFeature* feature; + std::shared_ptr feature; if (strlen( line )) { - feature = new LinearFeature(line, 0.0f); + feature = std::make_shared(line, 0.0f); } else { - feature = new LinearFeature(NULL, 0.0f); + feature = std::make_shared(nullptr, 0.0f); } TG_LOG(SG_GENERAL, SG_DEBUG, "Creating Linear Feature with description \"" << line << "\""); - return feature; + return std::move(feature); } -ClosedPoly* Parser::ParsePavement( char* line ) +std::shared_ptr Parser::ParsePavement( char* line ) { - ClosedPoly* poly; + std::shared_ptr poly; int st = 0; // surface type float s = 0.0f; // smoothness float th = 0.0f; // texture heading char desc[256]; // description - char *d = NULL; + char *d = nullptr; int numParams; numParams = sscanf(line, "%d %f %f %s", &st, &s, &th, desc); @@ -429,16 +428,16 @@ ClosedPoly* Parser::ParsePavement( char* line ) TG_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly with st " << st << " smoothness " << s << " texture heading " << th); } - poly = new ClosedPoly(st, s, th, d); + poly = std::make_shared(st, s, th, d); - return poly; + return std::move(poly); } -ClosedPoly* Parser::ParseBoundary( char* line ) +std::shared_ptr Parser::ParseBoundary( char* line ) { - ClosedPoly* poly; + std::shared_ptr poly; char desc[256]; - char *d = NULL; + char *d = nullptr; int numParams; numParams = sscanf(line, "%s", desc); @@ -453,9 +452,9 @@ ClosedPoly* Parser::ParseBoundary( char* line ) } TG_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly for airport boundary : " << d); - poly = new ClosedPoly(d); + poly = std::make_shared(d); - return poly; + return std::move(poly); } int Parser::SetState( int state ) @@ -467,7 +466,7 @@ int Parser::SetState( int state ) TG_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding pavement"); cur_pavement->Finish(); cur_airport->AddPavement( cur_pavement ); - cur_pavement = NULL; + cur_pavement = nullptr; } if ( cur_airport && cur_state == STATE_PARSE_BOUNDARY ) @@ -475,7 +474,7 @@ int Parser::SetState( int state ) TG_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding boundary"); cur_boundary->Finish(); cur_airport->AddBoundary( cur_boundary ); - cur_boundary = NULL; + cur_boundary = nullptr; } cur_state = state; @@ -489,7 +488,7 @@ int Parser::ParseLine(char* line) char* tok; int code; - BezNode* cur_node = NULL; + std::shared_ptr cur_node = nullptr; if (*line != '#') { @@ -509,7 +508,7 @@ int Parser::ParseLine(char* line) { SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing land airport: " << line); - cur_airport = new Airport( code, line ); + cur_airport = std::make_shared( code, line ); } else { @@ -521,7 +520,7 @@ int Parser::ParseLine(char* line) { SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing heliport: " << line); - cur_airport = new Airport( code, line ); + cur_airport = std::make_shared( code, line ); } else { @@ -532,7 +531,7 @@ int Parser::ParseLine(char* line) case LAND_RUNWAY_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing runway: " << line); - cur_runway = new Runway(line); + cur_runway = std::make_shared(line); if (cur_airport) { cur_airport->AddRunway( cur_runway ); @@ -542,7 +541,7 @@ int Parser::ParseLine(char* line) case WATER_RUNWAY_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing water runway: " << line); - cur_waterrunway = new WaterRunway(line); + cur_waterrunway = std::make_shared(line); if (cur_airport) { cur_airport->AddWaterRunway( cur_waterrunway ); @@ -551,7 +550,7 @@ int Parser::ParseLine(char* line) case HELIPAD_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing helipad: " << line); - cur_helipad = new Helipad(line); + cur_helipad = std::make_shared(line); if (cur_airport) { cur_airport->AddHelipad( cur_helipad ); @@ -561,7 +560,7 @@ int Parser::ParseLine(char* line) case TAXIWAY_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway: " << line); - cur_taxiway = new Taxiway(line); + cur_taxiway = std::make_shared(line); if (cur_airport) { cur_airport->AddTaxiway( cur_taxiway ); @@ -658,11 +657,11 @@ int Parser::ParseLine(char* line) cur_feat->Finish( true, cur_airport->NumFeatures() ); cur_airport->AddFeature( cur_feat ); } - cur_feat = NULL; + cur_feat = nullptr; SetState( STATE_PARSE_SIMPLE ); } - prev_node = NULL; - cur_node = NULL; + prev_node = nullptr; + cur_node = nullptr; break; case TERM_NODE_CODE: @@ -696,15 +695,13 @@ int Parser::ParseLine(char* line) else { TG_LOG(SG_GENERAL, SG_ALERT, "Parsing termination node with no previous nodes!!!" ); - - // this feature is bogus... - delete cur_feat; } - cur_feat = NULL; + + cur_feat = nullptr; SetState( STATE_PARSE_SIMPLE ); } - prev_node = NULL; - cur_node = NULL; + prev_node = nullptr; + cur_node = nullptr; break; case AIRPORT_VIEWPOINT_CODE: @@ -718,25 +715,25 @@ int Parser::ParseLine(char* line) case LIGHT_BEACON_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing light beacon: " << line); - cur_beacon = new Beacon(line); + cur_beacon = std::make_shared(line); cur_airport->AddBeacon( cur_beacon ); break; case WINDSOCK_CODE: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing windsock: " << line); - cur_windsock = new Windsock(line); + cur_windsock = std::make_shared(line); cur_airport->AddWindsock( cur_windsock ); break; case TAXIWAY_SIGN: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway sign: " << line); - cur_sign = new Sign(line); + cur_sign = std::make_shared(line); cur_airport->AddSign( cur_sign ); break; case LIGHTING_OBJECT: SetState( STATE_PARSE_SIMPLE ); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing lighting object: " << line); - cur_object = new LightingObj(line); + cur_object = std::make_shared(line); cur_airport->AddObj( cur_object ); break; case COMM_FREQ1_CODE: diff --git a/src/Airports/GenAirports850/parser.hxx b/src/Airports/GenAirports850/parser.hxx index ba6a2561..565a7eb2 100644 --- a/src/Airports/GenAirports850/parser.hxx +++ b/src/Airports/GenAirports850/parser.hxx @@ -3,6 +3,7 @@ #include #include +#include #include @@ -94,19 +95,19 @@ public: work_dir = root; elevation = elev_src; - cur_airport = NULL; - cur_runway = NULL; - cur_waterrunway = NULL; - cur_helipad = NULL; - cur_taxiway = NULL; - cur_pavement = NULL; - cur_boundary = NULL; - cur_feat = NULL; - cur_object = NULL; - cur_windsock = NULL; - cur_beacon = NULL; - cur_sign = NULL; - prev_node = NULL; + cur_airport = nullptr; + cur_runway = nullptr; + cur_waterrunway = nullptr; + cur_helipad = nullptr; + cur_taxiway = nullptr; + cur_pavement = nullptr; + cur_boundary = nullptr; + cur_feat = nullptr; + cur_object = nullptr; + cur_windsock = nullptr; + cur_beacon = nullptr; + cur_sign = nullptr; + prev_node = nullptr; cur_state = STATE_NONE; } @@ -124,14 +125,14 @@ private: int SetState( int state ); - BezNode* ParseNode( int type, char* line, BezNode* prevNode ); - LinearFeature* ParseFeature( char* line ); - ClosedPoly* ParsePavement( char* line ); - ClosedPoly* ParseBoundary( char* line ); + std::shared_ptr ParseNode( int type, char* line, std::shared_ptr prevNode ); + std::shared_ptr ParseFeature( char* line ); + std::shared_ptr ParsePavement( char* line ); + std::shared_ptr ParseBoundary( char* line ); int ParseLine( char* line ); - BezNode* prev_node; + std::shared_ptr prev_node; int cur_state; std::string filename; string_list elevation; @@ -139,18 +140,18 @@ private: // a polygon conists of an array of contours // (first is outside boundry, remaining are holes) - Airport* cur_airport; - Taxiway* cur_taxiway; - Runway* cur_runway; - WaterRunway* cur_waterrunway; - Helipad* cur_helipad; - ClosedPoly* cur_pavement; - ClosedPoly* cur_boundary; - LinearFeature* cur_feat; - LightingObj* cur_object; - Windsock* cur_windsock; - Beacon* cur_beacon; - Sign* cur_sign; + std::shared_ptr cur_airport; + std::shared_ptr cur_taxiway; + std::shared_ptr cur_runway; + std::shared_ptr cur_waterrunway; + std::shared_ptr cur_helipad; + std::shared_ptr cur_pavement; + std::shared_ptr cur_boundary; + std::shared_ptr cur_feat; + std::shared_ptr cur_object; + std::shared_ptr cur_windsock; + std::shared_ptr cur_beacon; + std::shared_ptr cur_sign; // debug std::string debug_path; diff --git a/src/Airports/GenAirports850/runway.hxx b/src/Airports/GenAirports850/runway.hxx index 05424505..b36a7e64 100644 --- a/src/Airports/GenAirports850/runway.hxx +++ b/src/Airports/GenAirports850/runway.hxx @@ -1,6 +1,8 @@ #ifndef _RUNWAY_H_ #define _RUNWAY_H_ +#include + #include #include #include @@ -176,7 +178,7 @@ private: tglightcontour_list gen_malsx( const std::string& kind, bool recip ); }; -typedef std::vector RunwayList; +typedef std::vector > RunwayList; class WaterRunway @@ -203,6 +205,6 @@ private: double lat[2]; double lon[2]; }; -typedef std::vector WaterRunwayList; +typedef std::vector > WaterRunwayList; #endif diff --git a/src/Airports/GenAirports850/scheduler.cxx b/src/Airports/GenAirports850/scheduler.cxx index 25a6a894..039341b1 100644 --- a/src/Airports/GenAirports850/scheduler.cxx +++ b/src/Airports/GenAirports850/scheduler.cxx @@ -4,6 +4,7 @@ #endif #include +#include #include #include @@ -370,7 +371,7 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) case SEA_AIRPORT_CODE: case HELIPORT_CODE: { - Airport* airport = new Airport( code, def ); + auto airport = std::make_unique( code, def ); if (match) { // Start off with given snap value @@ -380,7 +381,6 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) // remember this new apt pos and name, and clear match cur_apt_pos = cur_pos; cur_apt_name = airport->GetIcao(); - delete airport; match = false; } @@ -400,14 +400,13 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) // if the the runway start / end coords are within the rect, // we have a winner { - Runway* runway = new Runway(def); + auto runway = std::make_unique(def); if ( boundingBox->isInside(runway->GetStart()) ) { match = true; } else if ( boundingBox->isInside(runway->GetEnd()) ) { match = true; } - delete runway; } break; @@ -415,14 +414,13 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) // if the the runway start / end coords are within the rect, // we have a winner { - WaterRunway* runway = new WaterRunway(def); + auto runway = std::make_unique(def); if ( boundingBox->isInside(runway->GetStart()) ) { match = true; } else if ( boundingBox->isInside(runway->GetEnd()) ) { match = true; } - delete runway; } break; @@ -430,11 +428,10 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox ) // if the heliport coords are within the rect, we have // a winner { - Helipad* helipad = new Helipad(def); + auto helipad = std::make_unique(def); if ( boundingBox->isInside(helipad->GetLoc()) ) { match = true; } - delete helipad; } break; @@ -496,9 +493,9 @@ void Scheduler::Schedule( int num_threads, std::string& summaryfile ) // csvfile.open( summaryfile.c_str(), std::ios_base::out | std::ios_base::trunc ); // csvfile.close(); - std::vector parsers; + std::vector> parsers; for (int i=0; i( filename, work_dir, elevation ); // parser->set_debug(); parser->start(); parsers.push_back( parser ); @@ -511,6 +508,6 @@ void Scheduler::Schedule( int num_threads, std::string& summaryfile ) // Then wait until they are finished for (unsigned int i=0; ijoin(); - delete parsers[i]; + parsers[i] = nullptr; } } diff --git a/src/Airports/GenAirports850/taxiway.hxx b/src/Airports/GenAirports850/taxiway.hxx index 7da527a6..3ec00aef 100644 --- a/src/Airports/GenAirports850/taxiway.hxx +++ b/src/Airports/GenAirports850/taxiway.hxx @@ -1,6 +1,8 @@ #ifndef _TAXIWAY_H_ #define _TAXIWAY_H_ +#include + #include #include #include @@ -39,6 +41,6 @@ private: void GenLights(tglightcontour_list& rwy_lights); }; -typedef std::vector TaxiwayList; +typedef std::vector> TaxiwayList; #endif diff --git a/src/Lib/terragear/tg_surface.cxx b/src/Lib/terragear/tg_surface.cxx index df8d4652..7a59077d 100644 --- a/src/Lib/terragear/tg_surface.cxx +++ b/src/Lib/terragear/tg_surface.cxx @@ -168,7 +168,7 @@ static void tgCalcElevations( const std::string &root, const string_list elev_sr } } - array.close(); + array.unload(); } else { done = true;