X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Ftiming%2Ftimezone.cxx;h=0b2e74c6c5ad0094a2fcaff6841b5c78f2a56fe8;hb=a25e859fa773c9463e4bec042b8d0b39041c29ad;hp=41c596e852f7a4f8c571426a2ab9bb26652c7fbb;hpb=2253b82304626cbe7b38e42c35d12f1ce871351e;p=simgear.git diff --git a/simgear/timing/timezone.cxx b/simgear/timing/timezone.cxx index 41c596e8..0b2e74c6 100644 --- a/simgear/timing/timezone.cxx +++ b/simgear/timing/timezone.cxx @@ -12,16 +12,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * **************************************************************************/ /************************************************************************* * - * Timezone is derived from geocoord, and stores the timezone centerpoint, + * SGTimeZone is derived from geocoord, and stores the timezone centerpoint, * as well as the countrycode and the timezone descriptor. The latter is * used in order to get the local time. * @@ -30,18 +29,21 @@ #include #include #include + +#include + #include "timezone.h" -Timezone::Timezone(float la, float lo, char* cc, char* desc) : - GeoCoord(la, lo) +SGTimeZone::SGTimeZone(float la, float lo, char* cc, char* desc) : + SGGeoCoord(la, lo) { - countryCode = strdup(cc); - descriptor = strdup(desc); + countryCode = cc; + descriptor = desc; } /* Build a timezone object from a textline in zone.tab */ -Timezone::Timezone(const char *infoString) : - GeoCoord() +SGTimeZone::SGTimeZone(const char *infoString) : + SGGeoCoord() { int i = 0; while (infoString[i] != '\t') @@ -50,7 +52,7 @@ Timezone::Timezone(const char *infoString) : char latlon[128]; strncpy(buffer, infoString, i); buffer[i] = 0; - countryCode = strdup(buffer); + countryCode = buffer; i ++; int start = i; while (infoString[i] != '\t') { @@ -107,28 +109,29 @@ Timezone::Timezone(const char *infoString) : size = i - start; strncpy(buffer, (&infoString[start]), size); buffer[size] = 0; - descriptor = strdup(buffer); + descriptor = buffer; } /* the copy constructor */ -Timezone::Timezone(const Timezone& other) +SGTimeZone::SGTimeZone(const SGTimeZone& other) { lat = other.getLat(); lon = other.getLon(); - countryCode = strdup(other.countryCode); - descriptor = strdup(other.descriptor); + countryCode = other.countryCode; + descriptor = other.descriptor; } -/********* Member functions for TimezoneContainer class ********/ +/********* Member functions for SGTimeZoneContainer class ********/ -TimezoneContainer::TimezoneContainer(const char *filename) +SGTimeZoneContainer::SGTimeZoneContainer(const char *filename) { char buffer[256]; FILE* infile = fopen(filename, "rb"); if (!(infile)) { - fprintf(stderr, "Unable to open file %s\n", filename); - exit(1); + string e = "Unable to open time zone file '"; + throw sg_exception(e + filename + '\''); + } else { errno = 0; @@ -144,16 +147,17 @@ TimezoneContainer::TimezoneContainer(const char *filename) } } if (buffer[0]) { - data.push_back(new Timezone(buffer)); + data.push_back(new SGTimeZone(buffer)); } } if ( errno ) { - perror( "TimezoneContainer()" ); + perror( "SGTimeZoneContainer()" ); errno = 0; } } + fclose(infile); } -TimezoneContainer::~TimezoneContainer() +SGTimeZoneContainer::~SGTimeZoneContainer() { }