1 /* -*- Mode: C++ -*- *****************************************************
3 * Written by Durk Talsma. Started July 1999.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
21 /*************************************************************************
23 * SGTimeZone is derived from geocoord, and stores the timezone centerpoint,
24 * as well as the countrycode and the timezone descriptor. The latter is
25 * used in order to get the local time.
27 ************************************************************************/
33 #include <simgear/structure/exception.hxx>
37 SGTimeZone::SGTimeZone(float la, float lo, char* cc, char* desc) :
44 /* Build a timezone object from a textline in zone.tab */
45 SGTimeZone::SGTimeZone(const char *infoString) :
49 while (infoString[i] != '\t')
53 strncpy(buffer, infoString, i);
58 while (infoString[i] != '\t') {
62 strncpy(latlon, (&infoString[start]), size);
66 strncpy(buffer, &latlon[1], 2);
69 strncpy(buffer, &latlon[3], 2);
71 lat += (atof(buffer) / 60);
73 if (strlen(latlon) > 12) {
75 strncpy(buffer, &latlon[5], 2);
77 lat += (atof(buffer) / 3600.0);
85 sign = latlon[nextPos];
87 strncpy(buffer, &latlon[nextPos], 3);
91 strncpy(buffer, &latlon[nextPos], 2);
94 lon += (atof(buffer) / 60);
95 if (strlen(latlon) > 12) {
97 strncpy(buffer, &latlon[nextPos], 2);
99 lon += (atof (buffer) / 3600.00);
106 while (!((infoString[i] == '\t') || (infoString[i] == '\n'))) {
110 strncpy(buffer, (&infoString[start]), size);
115 /* the copy constructor */
116 SGTimeZone::SGTimeZone(const SGTimeZone& other)
118 lat = other.getLat();
119 lon = other.getLon();
120 countryCode = other.countryCode;
121 descriptor = other.descriptor;
125 /********* Member functions for SGTimeZoneContainer class ********/
127 SGTimeZoneContainer::SGTimeZoneContainer(const char *filename)
130 FILE* infile = fopen(filename, "rb");
132 string e = "Unable to open time zone file '";
133 throw sg_exception(e + filename + '\'');
139 fgets(buffer, 256, infile);
143 for (char *p = buffer; *p; p++) {
150 data.push_back(new SGTimeZone(buffer));
154 perror( "SGTimeZoneContainer()" );
161 SGTimeZoneContainer::~SGTimeZoneContainer()