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

View file

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

View file

@ -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<BezNode> 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<LinearFeature>(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<BezNode> curNode;
std::shared_ptr<BezNode> 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; i<boundary->size(); i++)
{
delete boundary->at(i);
}
delete boundary;
boundary = NULL;
boundary.clear();
// 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();
}

View file

@ -1,6 +1,8 @@
#ifndef _BEZPOLY_H_
#define _BEZPOLY_H_
#include <memory>
#include <terragear/tg_polygon.hxx>
#include "beznode.hxx"
@ -14,7 +16,7 @@ public:
~ClosedPoly();
inline std::string GetDescription() { return description; }
void AddNode( BezNode* node );
void AddNode( std::shared_ptr<BezNode> 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<LinearFeature> cur_feature;
FeatureList features;
};
typedef std::vector <ClosedPoly *> PavementList;
typedef std::vector<std::shared_ptr<ClosedPoly>> PavementList;
#endif

View file

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

View file

@ -16,6 +16,8 @@
#ifndef _HELIPAD_HXX
#define _HELIPAD_HXX
#include <memory>
#include <terragear/tg_polygon.hxx>
#include <terragear/tg_accumulator.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

View file

@ -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<BezNode> curNode;
std::shared_ptr<BezNode> 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<marks.size(); i++)

View file

@ -1,6 +1,8 @@
#ifndef _LINEARFEATURE_H_
#define _LINEARFEATURE_H_
#include <memory>
#include <terragear/tg_polygon.hxx>
#include <terragear/tg_accumulator.hxx>
#include <terragear/tg_light.hxx>
@ -46,7 +48,7 @@ public:
unsigned int start_idx;
unsigned int end_idx;
};
typedef std::vector <Marking*> MarkingList;
typedef std::vector<Marking*> MarkingList;
struct Lighting
{
@ -65,7 +67,7 @@ public:
return 0;
}
};
typedef std::vector <Lighting*> LightingList;
typedef std::vector<Lighting*> LightingList;
class LinearFeature
{
@ -93,7 +95,7 @@ public:
inline std::string GetDescription() { return description; }
void AddNode( BezNode* b )
void AddNode( std::shared_ptr<BezNode> 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 <LinearFeature *> FeatureList;
typedef std::vector<std::shared_ptr<LinearFeature>> FeatureList;
#endif

View file

@ -1,6 +1,8 @@
#ifndef _LINKED_OBJECTS_H_
#define _LINKED_OBJECTS_H_
#include <memory>
#include <terragear/tg_polygon.hxx>
class Windsock
@ -23,7 +25,7 @@ public:
}
};
typedef std::vector <Windsock *> WindsockList;
typedef std::vector<std::shared_ptr<Windsock>> WindsockList;
class Beacon
@ -46,7 +48,7 @@ public:
}
};
typedef std::vector <Beacon *> BeaconList;
typedef std::vector<std::shared_ptr<Beacon>> BeaconList;
class Sign
{
@ -81,6 +83,6 @@ public:
}
};
typedef std::vector <Sign *> SignList;
typedef std::vector<std::shared_ptr<Sign>> SignList;
#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-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<Scheduler>(input_file, work_dir, elev_src);
// auto scheduler = std::unique_ptr<Scheduler>(new Scheduler(input_file, work_dir, elev_src));
// Add any debug

View file

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

View file

@ -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<BezNode> Parser::ParseNode( int type, char* line, std::shared_ptr<BezNode> prevNode )
{
double lat, lon;
double ctrl_lat, ctrl_lon;
int feat_type1, feat_type2;
BezNode *curNode = NULL;
std::shared_ptr<BezNode> 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<BezNode>(lat, lon, ctrl_lat, ctrl_lon);
}
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->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 ))
{
feature = new LinearFeature(line, 0.0f);
feature = std::make_shared<LinearFeature>(line, 0.0f);
}
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 << "\"");
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
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<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 *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<ClosedPoly>(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<BezNode> 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<Airport>( 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<Airport>( 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<Runway>(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<WaterRunway>(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<Helipad>(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<Taxiway>(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<Beacon>(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<Windsock>(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<Sign>(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<LightingObj>(line);
cur_airport->AddObj( cur_object );
break;
case COMM_FREQ1_CODE:

View file

@ -3,6 +3,7 @@
#include <iostream>
#include <fstream>
#include <memory>
#include <simgear/threads/SGThread.hxx>
@ -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<BezNode> ParseNode( int type, char* line, std::shared_ptr<BezNode> prevNode );
std::shared_ptr<LinearFeature> ParseFeature( char* line );
std::shared_ptr<ClosedPoly> ParsePavement( char* line );
std::shared_ptr<ClosedPoly> ParseBoundary( char* line );
int ParseLine( char* line );
BezNode* prev_node;
std::shared_ptr<BezNode> 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<Airport> cur_airport;
std::shared_ptr<Taxiway> cur_taxiway;
std::shared_ptr<Runway> cur_runway;
std::shared_ptr<WaterRunway> cur_waterrunway;
std::shared_ptr<Helipad> cur_helipad;
std::shared_ptr<ClosedPoly> cur_pavement;
std::shared_ptr<ClosedPoly> cur_boundary;
std::shared_ptr<LinearFeature> cur_feat;
std::shared_ptr<LightingObj> cur_object;
std::shared_ptr<Windsock> cur_windsock;
std::shared_ptr<Beacon> cur_beacon;
std::shared_ptr<Sign> cur_sign;
// debug
std::string debug_path;

View file

@ -1,6 +1,8 @@
#ifndef _RUNWAY_H_
#define _RUNWAY_H_
#include <memory>
#include <terragear/tg_polygon.hxx>
#include <terragear/tg_accumulator.hxx>
#include <terragear/tg_light.hxx>
@ -176,7 +178,7 @@ private:
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
@ -203,6 +205,6 @@ private:
double lat[2];
double lon[2];
};
typedef std::vector <WaterRunway *> WaterRunwayList;
typedef std::vector <std::shared_ptr<WaterRunway>> WaterRunwayList;
#endif

View file

@ -4,6 +4,7 @@
#endif
#include <cstring>
#include <memory>
#include <simgear/debug/logstream.hxx>
#include <simgear/io/iostreams/sgstream.hxx>
@ -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<Airport>( 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<Runway>(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<WaterRunway>(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<Helipad>(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<Parser *> parsers;
std::vector<std::shared_ptr<Parser>> parsers;
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->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; i<parsers.size(); i++) {
parsers[i]->join();
delete parsers[i];
parsers[i] = nullptr;
}
}

View file

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

View file

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