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 ************************************************************************/
34 SGTimeZone::SGTimeZone(float la, float lo, char* cc, char* desc) :
41 /* Build a timezone object from a textline in zone.tab */
42 SGTimeZone::SGTimeZone(const char *infoString) :
46 while (infoString[i] != '\t')
50 strncpy(buffer, infoString, i);
55 while (infoString[i] != '\t') {
59 strncpy(latlon, (&infoString[start]), size);
63 strncpy(buffer, &latlon[1], 2);
66 strncpy(buffer, &latlon[3], 2);
68 lat += (atof(buffer) / 60);
70 if (strlen(latlon) > 12) {
72 strncpy(buffer, &latlon[5], 2);
74 lat += (atof(buffer) / 3600.0);
82 sign = latlon[nextPos];
84 strncpy(buffer, &latlon[nextPos], 3);
88 strncpy(buffer, &latlon[nextPos], 2);
91 lon += (atof(buffer) / 60);
92 if (strlen(latlon) > 12) {
94 strncpy(buffer, &latlon[nextPos], 2);
96 lon += (atof (buffer) / 3600.00);
103 while (!((infoString[i] == '\t') || (infoString[i] == '\n'))) {
107 strncpy(buffer, (&infoString[start]), size);
112 /* the copy constructor */
113 SGTimeZone::SGTimeZone(const SGTimeZone& other)
115 lat = other.getLat();
116 lon = other.getLon();
117 countryCode = other.countryCode;
118 descriptor = other.descriptor;
122 /********* Member functions for SGTimeZoneContainer class ********/
124 SGTimeZoneContainer::SGTimeZoneContainer(const char *filename)
127 FILE* infile = fopen(filename, "rb");
129 fprintf(stderr, "Unable to open file %s\n", filename);
135 fgets(buffer, 256, infile);
139 for (char *p = buffer; *p; p++) {
146 data.push_back(new SGTimeZone(buffer));
150 perror( "SGTimeZoneContainer()" );
157 SGTimeZoneContainer::~SGTimeZoneContainer()