1
0
Fork 0

genapt: Resolve memory leaks.

Reclaimed 1,419,778 bytes in 6,419 blocks.
genapt memory stability : Good.
This commit is contained in:
Scott Giese 2019-01-20 18:02:41 -06:00
parent 3ec0a1eabb
commit 1716820c16
18 changed files with 196 additions and 202 deletions

View file

@ -93,59 +93,59 @@ Airport::Airport( int c, char* def)
Airport::~Airport() Airport::~Airport()
{ {
for (unsigned int i=0; i<features.size(); i++) for (auto feature : features)
{ {
delete features[i]; feature = nullptr;
} }
for (unsigned int i=0; i<helipads.size(); i++) for (auto helipad : helipads)
{ {
delete helipads[i]; helipad = nullptr;
} }
for (unsigned int i=0; i<runways.size(); i++) for (auto runway : runways)
{ {
delete runways[i]; runway = nullptr;
} }
for (unsigned int i=0; i<waterrunways.size(); i++) for (auto waterrunway : waterrunways)
{ {
delete waterrunways[i]; waterrunway = nullptr;
} }
for (unsigned int i=0; i<pavements.size(); i++) for (auto pavement : pavements)
{ {
delete pavements[i]; pavement = nullptr;
} }
for (unsigned int i=0; i<taxiways.size(); i++) for (auto taxiway : taxiways)
{ {
delete taxiways[i]; taxiway = nullptr;
} }
for (unsigned int i=0; i<lightobjects.size(); i++) for (auto lightobject : lightobjects)
{ {
delete lightobjects[i]; lightobject = nullptr;
} }
for (unsigned int i=0; i<windsocks.size(); i++) for (auto windsock : windsocks)
{ {
delete windsocks[i]; windsock = nullptr;
} }
for (unsigned int i=0; i<beacons.size(); i++) for (auto beacon : beacons)
{ {
delete beacons[i]; beacon = nullptr;
} }
for (unsigned int i=0; i<signs.size(); i++) for (auto sign : signs)
{ {
delete signs[i]; sign = nullptr;
} }
for (unsigned int i=0; i<boundary.size(); i++) for (auto boundaryItem : boundary)
{ {
delete boundary[i]; boundaryItem = nullptr;
} }
} }

View file

@ -1,6 +1,8 @@
#ifndef _AIRPORT_H_ #ifndef _AIRPORT_H_
#define _AIRPORT_H_ #define _AIRPORT_H_
#include <memory>
#include <simgear/timing/timestamp.hxx> #include <simgear/timing/timestamp.hxx>
#include <simgear/math/sg_types.hxx> #include <simgear/math/sg_types.hxx>
#include <simgear/threads/SGThread.hxx> #include <simgear/threads/SGThread.hxx>
@ -20,46 +22,46 @@ public:
Airport( int c, char* def); Airport( int c, char* def);
~Airport(); ~Airport();
void AddRunway( Runway* runway ) void AddRunway( std::shared_ptr<Runway> runway )
{ {
runways.push_back( runway ); runways.push_back( runway );
} }
void AddWaterRunway( WaterRunway* waterrunway ) void AddWaterRunway( std::shared_ptr<WaterRunway> waterrunway )
{ {
waterrunways.push_back( waterrunway ); waterrunways.push_back( waterrunway );
} }
void AddObj( LightingObj* lightobj ) void AddObj( std::shared_ptr<LightingObj> lightobj )
{ {
lightobjects.push_back( lightobj ); lightobjects.push_back( lightobj );
} }
void AddHelipad( Helipad* helipad ) void AddHelipad( std::shared_ptr<Helipad> helipad )
{ {
helipads.push_back( helipad ); helipads.push_back( helipad );
} }
void AddTaxiway( Taxiway* taxiway ) void AddTaxiway( std::shared_ptr<Taxiway> taxiway )
{ {
taxiways.push_back( taxiway ); taxiways.push_back( taxiway );
} }
void AddPavement( ClosedPoly* pavement ) void AddPavement( std::shared_ptr<ClosedPoly> pavement )
{ {
pavements.push_back( pavement ); pavements.push_back( pavement );
} }
void AddFeature( LinearFeature* feature ) void AddFeature( std::shared_ptr<LinearFeature> feature )
{ {
features.push_back( feature ); features.push_back( feature );
} }
void AddFeatures( FeatureList* feature_list ) void AddFeatures( FeatureList feature_list )
{ {
for (unsigned int i=0; i<feature_list->size(); 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(); return features.size();
} }
void AddBoundary( ClosedPoly* bndry ) void AddBoundary( std::shared_ptr<ClosedPoly> bndry )
{ {
boundary.push_back( bndry ); boundary.push_back( bndry );
} }
void AddWindsock( Windsock* windsock ) void AddWindsock( std::shared_ptr<Windsock> windsock )
{ {
windsocks.push_back( windsock ); windsocks.push_back( windsock );
} }
void AddBeacon( Beacon* beacon ) void AddBeacon( std::shared_ptr<Beacon> beacon )
{ {
beacons.push_back( beacon ); beacons.push_back( beacon );
} }
void AddSign( Sign* sign ) void AddSign( std::shared_ptr<Sign> sign )
{ {
signs.push_back( sign ); signs.push_back( sign );
} }
@ -163,6 +165,6 @@ private:
debug_map debug_features; debug_map debug_features;
}; };
typedef std::vector <Airport *> AirportList; typedef std::vector<std::shared_ptr<Airport>> AirportList;
#endif #endif

View file

@ -4,6 +4,7 @@
#include <vector> #include <vector>
#include <string.h> #include <string.h>
#include <float.h> #include <float.h>
#include <memory>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/math/SGMath.hxx> #include <simgear/math/SGMath.hxx>
@ -282,8 +283,8 @@ private:
// array of BezNodes make a contour // array of BezNodes make a contour
typedef std::vector <BezNode *> BezContour; typedef std::vector<std::shared_ptr<BezNode>> BezContour;
typedef std::vector <BezContour *> BezContourArray; typedef std::vector<BezContour> BezContourArray;
#endif #endif

View file

@ -37,9 +37,8 @@ ClosedPoly::ClosedPoly( char* desc )
description = "none"; description = "none";
} }
boundary = NULL; boundary.clear();
cur_contour = NULL; cur_contour.clear();
cur_feature = NULL;
} }
ClosedPoly::ClosedPoly( int st, float s, float th, char* desc ) 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"; description = "none";
} }
boundary = NULL; boundary.clear();
cur_contour = NULL; cur_contour.clear();
cur_feature = NULL;
} }
ClosedPoly::~ClosedPoly() ClosedPoly::~ClosedPoly()
@ -72,14 +70,9 @@ ClosedPoly::~ClosedPoly()
TG_LOG( SG_GENERAL, SG_DEBUG, "Deleting ClosedPoly " << description ); TG_LOG( SG_GENERAL, SG_DEBUG, "Deleting ClosedPoly " << description );
} }
void ClosedPoly::AddNode( BezNode* node ) void ClosedPoly::AddNode( std::shared_ptr<BezNode> node )
{ {
// if this is the first node of the contour - create a new contour cur_contour.push_back( node );
if (!cur_contour)
{
cur_contour = new BezContour;
}
cur_contour->push_back( node );
TG_LOG(SG_GENERAL, SG_DEBUG, "CLOSEDPOLY::ADDNODE : " << node->GetLoc() ); TG_LOG(SG_GENERAL, SG_DEBUG, "CLOSEDPOLY::ADDNODE : " << node->GetLoc() );
@ -89,7 +82,7 @@ void ClosedPoly::AddNode( BezNode* node )
if (!cur_feature) if (!cur_feature)
{ {
std::string feature_desc = description + " - "; std::string feature_desc = description + " - ";
if (boundary) if (boundary.size() == 0)
{ {
feature_desc += "hole"; 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); 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<LinearFeature>(feature_desc, 1.0f);
} }
cur_feature->AddNode( node ); cur_feature->AddNode( node );
} }
@ -122,26 +115,26 @@ void ClosedPoly::CloseCurContour()
// add the contour to the poly - first one is the outer boundary // add the contour to the poly - first one is the outer boundary
// subsequent contours are holes // subsequent contours are holes
if ( boundary == NULL ) if ( boundary.size() == 0 )
{ {
boundary = cur_contour; boundary = cur_contour;
// generate the convex hull from the bezcontour node locations // generate the convex hull from the bezcontour node locations
// CreateConvexHull(); // CreateConvexHull();
cur_contour = NULL; cur_contour.clear();
} }
else else
{ {
holes.push_back( cur_contour ); 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; std::shared_ptr<BezNode> curNode;
BezNode* nextNode; std::shared_ptr<BezNode> nextNode;
SGGeod curLoc; SGGeod curLoc;
SGGeod nextLoc; SGGeod nextLoc;
@ -152,25 +145,25 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst )
double total_dist; double total_dist;
int num_segs = BEZIER_DETAIL; 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 // clear anything in this point list
dst.Erase(); dst.Erase();
// iterate through each bezier node in the contour // 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"); TG_LOG(SG_GENERAL, SG_DEBUG, "\nHandling Node " << i << "\n\n");
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 else
{ {
// for the last node, next is the first. as all contours are closed // 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 // now determine how we will iterate from current node to next node
@ -337,14 +330,14 @@ void ClosedPoly::Finish()
tgContour dst_contour; tgContour dst_contour;
// error handling // error handling
if (boundary == NULL) if (boundary.size() == 0)
{ {
TG_LOG(SG_GENERAL, SG_ALERT, "no boundary"); TG_LOG(SG_GENERAL, SG_ALERT, "no boundary");
} }
TG_LOG(SG_GENERAL, SG_DEBUG, "Converting a poly with " << holes.size() << " holes"); TG_LOG(SG_GENERAL, SG_DEBUG, "Converting a poly with " << holes.size() << " holes");
if (boundary != NULL) if (boundary.size() != 0)
{ {
// create the boundary // create the boundary
ConvertContour( boundary, dst_contour ); ConvertContour( boundary, dst_contour );
@ -367,22 +360,9 @@ void ClosedPoly::Finish()
} }
// save memory by deleting unneeded resources // save memory by deleting unneeded resources
for (unsigned int i=0; i<boundary->size(); i++) boundary.clear();
{
delete boundary->at(i);
}
delete boundary;
boundary = NULL;
// and the hole contours // and the hole contours
for (unsigned int i=0; i<holes.size(); i++)
{
for (unsigned int j=0; j<holes[i]->size(); j++)
{
delete holes[i]->at(j);
}
}
holes.clear(); holes.clear();
} }

View file

@ -1,6 +1,8 @@
#ifndef _BEZPOLY_H_ #ifndef _BEZPOLY_H_
#define _BEZPOLY_H_ #define _BEZPOLY_H_
#include <memory>
#include <terragear/tg_polygon.hxx> #include <terragear/tg_polygon.hxx>
#include "beznode.hxx" #include "beznode.hxx"
@ -14,7 +16,7 @@ public:
~ClosedPoly(); ~ClosedPoly();
inline std::string GetDescription() { return description; } inline std::string GetDescription() { return description; }
void AddNode( BezNode* node ); void AddNode( std::shared_ptr<BezNode> node );
void CloseCurContour(); void CloseCurContour();
void Finish(); void Finish();
@ -36,15 +38,15 @@ public:
tgAccumulator& accum, tgAccumulator& accum,
std::string& shapefile_name ); std::string& shapefile_name );
FeatureList* GetFeatures() FeatureList& GetFeatures()
{ {
return &features; return features;
} }
private: private:
// convert the BezierPoly to a normal Poly (adding nodes for the curves) // convert the BezierPoly to a normal Poly (adding nodes for the curves)
void CreateConvexHull( void ); void CreateConvexHull( void );
void ConvertContour( BezContour* src, tgContour& dst ); void ConvertContour( const BezContour& src, tgContour& dst );
std::string GetMaterial( int surface ); std::string GetMaterial( int surface );
@ -58,13 +60,13 @@ private:
std::string description; std::string description;
// outer boundary definition as bezier nodes // outer boundary definition as bezier nodes
BezContour* boundary; BezContour boundary;
// holes // holes
BezContourArray holes; BezContourArray holes;
// contour that nodes will be added until done // contour that nodes will be added until done
BezContour* cur_contour; BezContour cur_contour;
// Converted polygon after parsing complete // Converted polygon after parsing complete
tgPolygon pre_tess; tgPolygon pre_tess;
@ -73,10 +75,10 @@ private:
tgpolygon_list shoulder_polys; tgpolygon_list shoulder_polys;
// pavement definitions have multiple linear features (markings and lights for each contour) // pavement definitions have multiple linear features (markings and lights for each contour)
LinearFeature* cur_feature; std::shared_ptr<LinearFeature> cur_feature;
FeatureList features; FeatureList features;
}; };
typedef std::vector <ClosedPoly *> PavementList; typedef std::vector<std::shared_ptr<ClosedPoly>> PavementList;
#endif #endif

View file

@ -109,7 +109,7 @@ double tgAverageElevation( const std::string &root, const string_list elev_src,
} }
} }
array.close(); array.unload();
} else { } else {
done = true; done = true;
} }

View file

@ -16,6 +16,8 @@
#ifndef _HELIPAD_HXX #ifndef _HELIPAD_HXX
#define _HELIPAD_HXX #define _HELIPAD_HXX
#include <memory>
#include <terragear/tg_polygon.hxx> #include <terragear/tg_polygon.hxx>
#include <terragear/tg_accumulator.hxx> #include <terragear/tg_accumulator.hxx>
#include <terragear/tg_light.hxx> #include <terragear/tg_light.hxx>
@ -91,6 +93,6 @@ private:
}; };
typedef std::vector <Helipad *> HelipadList; typedef std::vector<std::shared_ptr<Helipad>> HelipadList;
#endif #endif

View file

@ -4,10 +4,10 @@
#include "beznode.hxx" #include "beznode.hxx"
#include "linearfeature.hxx" #include "linearfeature.hxx"
void LinearFeature::ConvertContour( BezContour* src, bool closed ) void LinearFeature::ConvertContour( const BezContour& src, bool closed )
{ {
BezNode* curNode; std::shared_ptr<BezNode> curNode;
BezNode* nextNode; std::shared_ptr<BezNode> nextNode;
SGGeod curLoc; SGGeod curLoc;
SGGeod nextLoc; SGGeod nextLoc;
@ -22,24 +22,24 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
Marking* cur_mark = NULL; Marking* cur_mark = NULL;
Lighting* cur_light = 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 // clear anything in the point list
points.Erase(); points.Erase();
// iterate through each bezier node in the contour // 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 else
{ {
// for the last node, next is the first. as all contours are closed // 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 // create the inner and outer boundaries to generate polys
// this generates 2 point lists for the contours, and remembers // this generates 2 point lists for the contours, and remembers
// the start stop points for markings and lights // the start stop points for markings and lights
ConvertContour( &contour, closed ); ConvertContour( contour, closed );
// now generate the supoerpoly and texparams lists for markings // now generate the supoerpoly and texparams lists for markings
for (unsigned int i=0; i<marks.size(); i++) for (unsigned int i=0; i<marks.size(); i++)

View file

@ -1,6 +1,8 @@
#ifndef _LINEARFEATURE_H_ #ifndef _LINEARFEATURE_H_
#define _LINEARFEATURE_H_ #define _LINEARFEATURE_H_
#include <memory>
#include <terragear/tg_polygon.hxx> #include <terragear/tg_polygon.hxx>
#include <terragear/tg_accumulator.hxx> #include <terragear/tg_accumulator.hxx>
#include <terragear/tg_light.hxx> #include <terragear/tg_light.hxx>
@ -46,7 +48,7 @@ public:
unsigned int start_idx; unsigned int start_idx;
unsigned int end_idx; unsigned int end_idx;
}; };
typedef std::vector <Marking*> MarkingList; typedef std::vector<Marking*> MarkingList;
struct Lighting struct Lighting
{ {
@ -65,7 +67,7 @@ public:
return 0; return 0;
} }
}; };
typedef std::vector <Lighting*> LightingList; typedef std::vector<Lighting*> LightingList;
class LinearFeature class LinearFeature
{ {
@ -93,7 +95,7 @@ public:
inline std::string GetDescription() { return description; } inline std::string GetDescription() { return description; }
void AddNode( BezNode* b ) void AddNode( std::shared_ptr<BezNode> b )
{ {
contour.push_back( b ); contour.push_back( b );
} }
@ -111,7 +113,7 @@ private:
LightingList lights; LightingList lights;
Lighting* cur_light; Lighting* cur_light;
void ConvertContour( BezContour* src, bool closed ); void ConvertContour( const BezContour& src, bool closed );
// text description // text description
std::string description; std::string description;
@ -126,6 +128,6 @@ private:
tglightcontour_list lighting_polys; tglightcontour_list lighting_polys;
}; };
typedef std::vector <LinearFeature *> FeatureList; typedef std::vector<std::shared_ptr<LinearFeature>> FeatureList;
#endif #endif

View file

@ -1,6 +1,8 @@
#ifndef _LINKED_OBJECTS_H_ #ifndef _LINKED_OBJECTS_H_
#define _LINKED_OBJECTS_H_ #define _LINKED_OBJECTS_H_
#include <memory>
#include <terragear/tg_polygon.hxx> #include <terragear/tg_polygon.hxx>
class Windsock class Windsock
@ -23,7 +25,7 @@ public:
} }
}; };
typedef std::vector <Windsock *> WindsockList; typedef std::vector<std::shared_ptr<Windsock>> WindsockList;
class Beacon class Beacon
@ -46,7 +48,7 @@ public:
} }
}; };
typedef std::vector <Beacon *> BeaconList; typedef std::vector<std::shared_ptr<Beacon>> BeaconList;
class Sign class Sign
{ {
@ -81,6 +83,6 @@ public:
} }
}; };
typedef std::vector <Sign *> SignList; typedef std::vector<std::shared_ptr<Sign>> SignList;
#endif #endif

View file

@ -57,6 +57,8 @@ void setup_default_elevation_sources(string_list& elev_src) {
elev_src.push_back( "SRTM-1" ); elev_src.push_back( "SRTM-1" );
elev_src.push_back( "SRTM-3" ); elev_src.push_back( "SRTM-3" );
elev_src.push_back( "SRTM-30" ); elev_src.push_back( "SRTM-30" );
elev_src.push_back( "SRTMGL1" );
elev_src.push_back( "SRTMGL3" );
} }
// Display help and usage // Display help and usage
@ -349,7 +351,7 @@ int main(int argc, char **argv)
} }
// Create the scheduler // Create the scheduler
Scheduler* scheduler = new Scheduler(input_file, work_dir, elev_src); auto scheduler = std::make_unique<Scheduler>(input_file, work_dir, elev_src);
// auto scheduler = std::unique_ptr<Scheduler>(new Scheduler(input_file, work_dir, elev_src)); // auto scheduler = std::unique_ptr<Scheduler>(new Scheduler(input_file, work_dir, elev_src));
// Add any debug // Add any debug

View file

@ -1,6 +1,8 @@
#ifndef _OBJECT_H_ #ifndef _OBJECT_H_
#define _OBJECT_H_ #define _OBJECT_H_
#include <memory>
#include <terragear/tg_light.hxx> #include <terragear/tg_light.hxx>
#include <terragear/tg_polygon.hxx> #include <terragear/tg_polygon.hxx>
@ -20,6 +22,6 @@ public:
void BuildBtg( tglightcontour_list& lights ); void BuildBtg( tglightcontour_list& lights );
}; };
typedef std::vector <LightingObj *> LightingObjList; typedef std::vector<std::shared_ptr<LightingObj>> LightingObjList;
#endif #endif

View file

@ -236,8 +236,7 @@ void Parser::run()
cur_airport->GetCleanupTime( clean_time ); cur_airport->GetCleanupTime( clean_time );
cur_airport->GetTriangulationTime( triangulation_time ); cur_airport->GetTriangulationTime( triangulation_time );
delete cur_airport; cur_airport = nullptr;
cur_airport = NULL;
} }
log_time = time(0); log_time = time(0);
@ -250,12 +249,12 @@ void Parser::run()
} }
} }
BezNode* Parser::ParseNode( int type, char* line, BezNode* prevNode ) std::shared_ptr<BezNode> Parser::ParseNode( int type, char* line, std::shared_ptr<BezNode> prevNode )
{ {
double lat, lon; double lat, lon;
double ctrl_lat, ctrl_lon; double ctrl_lat, ctrl_lon;
int feat_type1, feat_type2; int feat_type1, feat_type2;
BezNode *curNode = NULL; std::shared_ptr<BezNode> curNode = nullptr;
bool hasCtrl = false; bool hasCtrl = false;
bool close = 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 this is a new node, add it - as first part never has prev cp
if (curNode == NULL) if (curNode == nullptr)
{ {
if (hasCtrl) if (hasCtrl)
{ {
curNode = new BezNode(lat, lon, ctrl_lat, ctrl_lon); curNode = std::make_shared<BezNode>(lat, lon, ctrl_lat, ctrl_lon);
} }
else else
{ {
curNode = new BezNode(lat, lon); curNode = std::make_shared<BezNode>(lat, lon);
} }
} }
@ -386,35 +385,35 @@ BezNode* Parser::ParseNode( int type, char* line, BezNode* prevNode )
curNode->SetTerm( term ); curNode->SetTerm( term );
curNode->SetClose( close ); curNode->SetClose( close );
return curNode; return std::move(curNode);
} }
LinearFeature* Parser::ParseFeature( char* line ) std::shared_ptr<LinearFeature> Parser::ParseFeature( char* line )
{ {
LinearFeature* feature; std::shared_ptr<LinearFeature> feature;
if (strlen( line )) if (strlen( line ))
{ {
feature = new LinearFeature(line, 0.0f); feature = std::make_shared<LinearFeature>(line, 0.0f);
} }
else else
{ {
feature = new LinearFeature(NULL, 0.0f); feature = std::make_shared<LinearFeature>(nullptr, 0.0f);
} }
TG_LOG(SG_GENERAL, SG_DEBUG, "Creating Linear Feature with description \"" << line << "\""); 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<ClosedPoly> Parser::ParsePavement( char* line )
{ {
ClosedPoly* poly; std::shared_ptr<ClosedPoly> poly;
int st = 0; // surface type int st = 0; // surface type
float s = 0.0f; // smoothness float s = 0.0f; // smoothness
float th = 0.0f; // texture heading float th = 0.0f; // texture heading
char desc[256]; // description char desc[256]; // description
char *d = NULL; char *d = nullptr;
int numParams; int numParams;
numParams = sscanf(line, "%d %f %f %s", &st, &s, &th, desc); 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); 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<ClosedPoly>(st, s, th, d);
return poly; return std::move(poly);
} }
ClosedPoly* Parser::ParseBoundary( char* line ) std::shared_ptr<ClosedPoly> Parser::ParseBoundary( char* line )
{ {
ClosedPoly* poly; std::shared_ptr<ClosedPoly> poly;
char desc[256]; char desc[256];
char *d = NULL; char *d = nullptr;
int numParams; int numParams;
numParams = sscanf(line, "%s", desc); 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); TG_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly for airport boundary : " << d);
poly = new ClosedPoly(d); poly = std::make_shared<ClosedPoly>(d);
return poly; return std::move(poly);
} }
int Parser::SetState( int state ) int Parser::SetState( int state )
@ -467,7 +466,7 @@ int Parser::SetState( int state )
TG_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding pavement"); TG_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding pavement");
cur_pavement->Finish(); cur_pavement->Finish();
cur_airport->AddPavement( cur_pavement ); cur_airport->AddPavement( cur_pavement );
cur_pavement = NULL; cur_pavement = nullptr;
} }
if ( cur_airport && cur_state == STATE_PARSE_BOUNDARY ) 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"); TG_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding boundary");
cur_boundary->Finish(); cur_boundary->Finish();
cur_airport->AddBoundary( cur_boundary ); cur_airport->AddBoundary( cur_boundary );
cur_boundary = NULL; cur_boundary = nullptr;
} }
cur_state = state; cur_state = state;
@ -489,7 +488,7 @@ int Parser::ParseLine(char* line)
char* tok; char* tok;
int code; int code;
BezNode* cur_node = NULL; std::shared_ptr<BezNode> cur_node = nullptr;
if (*line != '#') if (*line != '#')
{ {
@ -509,7 +508,7 @@ int Parser::ParseLine(char* line)
{ {
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing land airport: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing land airport: " << line);
cur_airport = new Airport( code, line ); cur_airport = std::make_shared<Airport>( code, line );
} }
else else
{ {
@ -521,7 +520,7 @@ int Parser::ParseLine(char* line)
{ {
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing heliport: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing heliport: " << line);
cur_airport = new Airport( code, line ); cur_airport = std::make_shared<Airport>( code, line );
} }
else else
{ {
@ -532,7 +531,7 @@ int Parser::ParseLine(char* line)
case LAND_RUNWAY_CODE: case LAND_RUNWAY_CODE:
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing runway: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing runway: " << line);
cur_runway = new Runway(line); cur_runway = std::make_shared<Runway>(line);
if (cur_airport) if (cur_airport)
{ {
cur_airport->AddRunway( cur_runway ); cur_airport->AddRunway( cur_runway );
@ -542,7 +541,7 @@ int Parser::ParseLine(char* line)
case WATER_RUNWAY_CODE: case WATER_RUNWAY_CODE:
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing water runway: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing water runway: " << line);
cur_waterrunway = new WaterRunway(line); cur_waterrunway = std::make_shared<WaterRunway>(line);
if (cur_airport) if (cur_airport)
{ {
cur_airport->AddWaterRunway( cur_waterrunway ); cur_airport->AddWaterRunway( cur_waterrunway );
@ -551,7 +550,7 @@ int Parser::ParseLine(char* line)
case HELIPAD_CODE: case HELIPAD_CODE:
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing helipad: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing helipad: " << line);
cur_helipad = new Helipad(line); cur_helipad = std::make_shared<Helipad>(line);
if (cur_airport) if (cur_airport)
{ {
cur_airport->AddHelipad( cur_helipad ); cur_airport->AddHelipad( cur_helipad );
@ -561,7 +560,7 @@ int Parser::ParseLine(char* line)
case TAXIWAY_CODE: case TAXIWAY_CODE:
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway: " << line);
cur_taxiway = new Taxiway(line); cur_taxiway = std::make_shared<Taxiway>(line);
if (cur_airport) if (cur_airport)
{ {
cur_airport->AddTaxiway( cur_taxiway ); cur_airport->AddTaxiway( cur_taxiway );
@ -658,11 +657,11 @@ int Parser::ParseLine(char* line)
cur_feat->Finish( true, cur_airport->NumFeatures() ); cur_feat->Finish( true, cur_airport->NumFeatures() );
cur_airport->AddFeature( cur_feat ); cur_airport->AddFeature( cur_feat );
} }
cur_feat = NULL; cur_feat = nullptr;
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
} }
prev_node = NULL; prev_node = nullptr;
cur_node = NULL; cur_node = nullptr;
break; break;
case TERM_NODE_CODE: case TERM_NODE_CODE:
@ -696,15 +695,13 @@ int Parser::ParseLine(char* line)
else else
{ {
TG_LOG(SG_GENERAL, SG_ALERT, "Parsing termination node with no previous nodes!!!" ); 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 ); SetState( STATE_PARSE_SIMPLE );
} }
prev_node = NULL; prev_node = nullptr;
cur_node = NULL; cur_node = nullptr;
break; break;
case AIRPORT_VIEWPOINT_CODE: case AIRPORT_VIEWPOINT_CODE:
@ -718,25 +715,25 @@ int Parser::ParseLine(char* line)
case LIGHT_BEACON_CODE: case LIGHT_BEACON_CODE:
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing light beacon: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing light beacon: " << line);
cur_beacon = new Beacon(line); cur_beacon = std::make_shared<Beacon>(line);
cur_airport->AddBeacon( cur_beacon ); cur_airport->AddBeacon( cur_beacon );
break; break;
case WINDSOCK_CODE: case WINDSOCK_CODE:
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing windsock: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing windsock: " << line);
cur_windsock = new Windsock(line); cur_windsock = std::make_shared<Windsock>(line);
cur_airport->AddWindsock( cur_windsock ); cur_airport->AddWindsock( cur_windsock );
break; break;
case TAXIWAY_SIGN: case TAXIWAY_SIGN:
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway sign: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway sign: " << line);
cur_sign = new Sign(line); cur_sign = std::make_shared<Sign>(line);
cur_airport->AddSign( cur_sign ); cur_airport->AddSign( cur_sign );
break; break;
case LIGHTING_OBJECT: case LIGHTING_OBJECT:
SetState( STATE_PARSE_SIMPLE ); SetState( STATE_PARSE_SIMPLE );
TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing lighting object: " << line); TG_LOG(SG_GENERAL, SG_DEBUG, "Parsing lighting object: " << line);
cur_object = new LightingObj(line); cur_object = std::make_shared<LightingObj>(line);
cur_airport->AddObj( cur_object ); cur_airport->AddObj( cur_object );
break; break;
case COMM_FREQ1_CODE: case COMM_FREQ1_CODE:

View file

@ -3,6 +3,7 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <memory>
#include <simgear/threads/SGThread.hxx> #include <simgear/threads/SGThread.hxx>
@ -94,19 +95,19 @@ public:
work_dir = root; work_dir = root;
elevation = elev_src; elevation = elev_src;
cur_airport = NULL; cur_airport = nullptr;
cur_runway = NULL; cur_runway = nullptr;
cur_waterrunway = NULL; cur_waterrunway = nullptr;
cur_helipad = NULL; cur_helipad = nullptr;
cur_taxiway = NULL; cur_taxiway = nullptr;
cur_pavement = NULL; cur_pavement = nullptr;
cur_boundary = NULL; cur_boundary = nullptr;
cur_feat = NULL; cur_feat = nullptr;
cur_object = NULL; cur_object = nullptr;
cur_windsock = NULL; cur_windsock = nullptr;
cur_beacon = NULL; cur_beacon = nullptr;
cur_sign = NULL; cur_sign = nullptr;
prev_node = NULL; prev_node = nullptr;
cur_state = STATE_NONE; cur_state = STATE_NONE;
} }
@ -124,14 +125,14 @@ private:
int SetState( int state ); int SetState( int state );
BezNode* ParseNode( int type, char* line, BezNode* prevNode ); std::shared_ptr<BezNode> ParseNode( int type, char* line, std::shared_ptr<BezNode> prevNode );
LinearFeature* ParseFeature( char* line ); std::shared_ptr<LinearFeature> ParseFeature( char* line );
ClosedPoly* ParsePavement( char* line ); std::shared_ptr<ClosedPoly> ParsePavement( char* line );
ClosedPoly* ParseBoundary( char* line ); std::shared_ptr<ClosedPoly> ParseBoundary( char* line );
int ParseLine( char* line ); int ParseLine( char* line );
BezNode* prev_node; std::shared_ptr<BezNode> prev_node;
int cur_state; int cur_state;
std::string filename; std::string filename;
string_list elevation; string_list elevation;
@ -139,18 +140,18 @@ private:
// a polygon conists of an array of contours // a polygon conists of an array of contours
// (first is outside boundry, remaining are holes) // (first is outside boundry, remaining are holes)
Airport* cur_airport; std::shared_ptr<Airport> cur_airport;
Taxiway* cur_taxiway; std::shared_ptr<Taxiway> cur_taxiway;
Runway* cur_runway; std::shared_ptr<Runway> cur_runway;
WaterRunway* cur_waterrunway; std::shared_ptr<WaterRunway> cur_waterrunway;
Helipad* cur_helipad; std::shared_ptr<Helipad> cur_helipad;
ClosedPoly* cur_pavement; std::shared_ptr<ClosedPoly> cur_pavement;
ClosedPoly* cur_boundary; std::shared_ptr<ClosedPoly> cur_boundary;
LinearFeature* cur_feat; std::shared_ptr<LinearFeature> cur_feat;
LightingObj* cur_object; std::shared_ptr<LightingObj> cur_object;
Windsock* cur_windsock; std::shared_ptr<Windsock> cur_windsock;
Beacon* cur_beacon; std::shared_ptr<Beacon> cur_beacon;
Sign* cur_sign; std::shared_ptr<Sign> cur_sign;
// debug // debug
std::string debug_path; std::string debug_path;

View file

@ -1,6 +1,8 @@
#ifndef _RUNWAY_H_ #ifndef _RUNWAY_H_
#define _RUNWAY_H_ #define _RUNWAY_H_
#include <memory>
#include <terragear/tg_polygon.hxx> #include <terragear/tg_polygon.hxx>
#include <terragear/tg_accumulator.hxx> #include <terragear/tg_accumulator.hxx>
#include <terragear/tg_light.hxx> #include <terragear/tg_light.hxx>
@ -176,7 +178,7 @@ private:
tglightcontour_list gen_malsx( const std::string& kind, bool recip ); tglightcontour_list gen_malsx( const std::string& kind, bool recip );
}; };
typedef std::vector <Runway *> RunwayList; typedef std::vector <std::shared_ptr<Runway>> RunwayList;
class WaterRunway class WaterRunway
@ -203,6 +205,6 @@ private:
double lat[2]; double lat[2];
double lon[2]; double lon[2];
}; };
typedef std::vector <WaterRunway *> WaterRunwayList; typedef std::vector <std::shared_ptr<WaterRunway>> WaterRunwayList;
#endif #endif

View file

@ -4,6 +4,7 @@
#endif #endif
#include <cstring> #include <cstring>
#include <memory>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/io/iostreams/sgstream.hxx> #include <simgear/io/iostreams/sgstream.hxx>
@ -370,7 +371,7 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox )
case SEA_AIRPORT_CODE: case SEA_AIRPORT_CODE:
case HELIPORT_CODE: case HELIPORT_CODE:
{ {
Airport* airport = new Airport( code, def ); auto airport = std::make_unique<Airport>( code, def );
if (match) if (match)
{ {
// Start off with given snap value // 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 // remember this new apt pos and name, and clear match
cur_apt_pos = cur_pos; cur_apt_pos = cur_pos;
cur_apt_name = airport->GetIcao(); cur_apt_name = airport->GetIcao();
delete airport;
match = false; 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, // if the the runway start / end coords are within the rect,
// we have a winner // we have a winner
{ {
Runway* runway = new Runway(def); auto runway = std::make_unique<Runway>(def);
if ( boundingBox->isInside(runway->GetStart()) ) { if ( boundingBox->isInside(runway->GetStart()) ) {
match = true; match = true;
} }
else if ( boundingBox->isInside(runway->GetEnd()) ) { else if ( boundingBox->isInside(runway->GetEnd()) ) {
match = true; match = true;
} }
delete runway;
} }
break; break;
@ -415,14 +414,13 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox )
// if the the runway start / end coords are within the rect, // if the the runway start / end coords are within the rect,
// we have a winner // we have a winner
{ {
WaterRunway* runway = new WaterRunway(def); auto runway = std::make_unique<WaterRunway>(def);
if ( boundingBox->isInside(runway->GetStart()) ) { if ( boundingBox->isInside(runway->GetStart()) ) {
match = true; match = true;
} }
else if ( boundingBox->isInside(runway->GetEnd()) ) { else if ( boundingBox->isInside(runway->GetEnd()) ) {
match = true; match = true;
} }
delete runway;
} }
break; break;
@ -430,11 +428,10 @@ bool Scheduler::AddAirports( long start_pos, tgRectangle* boundingBox )
// if the heliport coords are within the rect, we have // if the heliport coords are within the rect, we have
// a winner // a winner
{ {
Helipad* helipad = new Helipad(def); auto helipad = std::make_unique<Helipad>(def);
if ( boundingBox->isInside(helipad->GetLoc()) ) { if ( boundingBox->isInside(helipad->GetLoc()) ) {
match = true; match = true;
} }
delete helipad;
} }
break; 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.open( summaryfile.c_str(), std::ios_base::out | std::ios_base::trunc );
// csvfile.close(); // csvfile.close();
std::vector<Parser *> parsers; std::vector<std::shared_ptr<Parser>> parsers;
for (int i=0; i<num_threads; i++) { for (int i=0; i<num_threads; i++) {
Parser* parser = new Parser( filename, work_dir, elevation ); auto parser = std::make_shared<Parser>( filename, work_dir, elevation );
// parser->set_debug(); // parser->set_debug();
parser->start(); parser->start();
parsers.push_back( parser ); parsers.push_back( parser );
@ -511,6 +508,6 @@ void Scheduler::Schedule( int num_threads, std::string& summaryfile )
// Then wait until they are finished // Then wait until they are finished
for (unsigned int i=0; i<parsers.size(); i++) { for (unsigned int i=0; i<parsers.size(); i++) {
parsers[i]->join(); parsers[i]->join();
delete parsers[i]; parsers[i] = nullptr;
} }
} }

View file

@ -1,6 +1,8 @@
#ifndef _TAXIWAY_H_ #ifndef _TAXIWAY_H_
#define _TAXIWAY_H_ #define _TAXIWAY_H_
#include <memory>
#include <terragear/tg_light.hxx> #include <terragear/tg_light.hxx>
#include <terragear/tg_polygon.hxx> #include <terragear/tg_polygon.hxx>
#include <terragear/tg_accumulator.hxx> #include <terragear/tg_accumulator.hxx>
@ -39,6 +41,6 @@ private:
void GenLights(tglightcontour_list& rwy_lights); void GenLights(tglightcontour_list& rwy_lights);
}; };
typedef std::vector <Taxiway *> TaxiwayList; typedef std::vector<std::shared_ptr<Taxiway>> TaxiwayList;
#endif #endif

View file

@ -168,7 +168,7 @@ static void tgCalcElevations( const std::string &root, const string_list elev_sr
} }
} }
array.close(); array.unload();
} else { } else {
done = true; done = true;