From 4e23b3dff57d9de08e659c89c46e271d2f17fbc3 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 8 Aug 2000 03:20:02 +0000 Subject: [PATCH] Clean up constructor a bit. --- simgear/timing/sg_time.cxx | 38 +++++++++++++++++++++++++------------- simgear/timing/sg_time.hxx | 1 + 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/simgear/timing/sg_time.cxx b/simgear/timing/sg_time.cxx index 3aa89d92..0013d3b0 100644 --- a/simgear/timing/sg_time.cxx +++ b/simgear/timing/sg_time.cxx @@ -75,18 +75,23 @@ SGTime::SGTime( double lon, double lat, const string& root ) // cout << "Current local time = " // << asctime(localtime(&cur_time)) << endl; - FGPath zone( root ); - zone.append( "zone.tab" ); - FG_LOG( FG_EVENT, FG_DEBUG, "Reading timezone info from: " << zone.str() ); - tzContainer = new TimezoneContainer( zone.c_str() ); - - GeoCoord location( RAD_TO_DEG * lat, RAD_TO_DEG * lon ); - GeoCoord* nearestTz = tzContainer->getNearest(location); - - FGPath name( root ); - name.append( nearestTz->getDescription() ); - zonename = strdup( name.c_str() ); - // cout << "Using zonename = " << zonename << endl; + if ( root != "" ) { + FGPath zone( root ); + zone.append( "zone.tab" ); + FG_LOG( FG_EVENT, FG_DEBUG, "Reading timezone info from: " + << zone.str() ); + tzContainer = new TimezoneContainer( zone.c_str() ); + + GeoCoord location( RAD_TO_DEG * lat, RAD_TO_DEG * lon ); + GeoCoord* nearestTz = tzContainer->getNearest(location); + + FGPath name( root ); + name.append( nearestTz->getDescription() ); + zonename = strdup( name.c_str() ); + // cout << "Using zonename = " << zonename << endl; + } else { + tzContainer = NULL; + } } @@ -95,9 +100,16 @@ SGTime::SGTime( const string& root ) { } +SGTime::SGTime() { + SGTime( 0.0, 0.0, "" ); +} + + SGTime::~SGTime() { - delete tzContainer; + if ( tzContainer != NULL ) { + delete tzContainer; + } if ( zonename != NULL ) { delete zonename; diff --git a/simgear/timing/sg_time.hxx b/simgear/timing/sg_time.hxx index 9c143b18..0c0f0408 100644 --- a/simgear/timing/sg_time.hxx +++ b/simgear/timing/sg_time.hxx @@ -86,6 +86,7 @@ public: SGTime( double lon, double lat, const string& root ); SGTime( const string& root ); + SGTime(); ~SGTime(); // Update the time related variables -- 2.39.5