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 Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 **************************************************************************/
22 /*************************************************************************
24 * SGTimeZone is derived from geocoord, and stores the timezone centerpoint,
25 * as well as the countrycode and the timezone descriptor. The latter is
26 * used in order to get the local time.
28 ************************************************************************/
35 SGTimeZone::SGTimeZone(float la, float lo, char* cc, char* desc) :
42 /* Build a timezone object from a textline in zone.tab */
43 SGTimeZone::SGTimeZone(const char *infoString) :
47 while (infoString[i] != '\t')
51 strncpy(buffer, infoString, i);
56 while (infoString[i] != '\t') {
60 strncpy(latlon, (&infoString[start]), size);
64 strncpy(buffer, &latlon[1], 2);
67 strncpy(buffer, &latlon[3], 2);
69 lat += (atof(buffer) / 60);
71 if (strlen(latlon) > 12) {
73 strncpy(buffer, &latlon[5], 2);
75 lat += (atof(buffer) / 3600.0);
83 sign = latlon[nextPos];
85 strncpy(buffer, &latlon[nextPos], 3);
89 strncpy(buffer, &latlon[nextPos], 2);
92 lon += (atof(buffer) / 60);
93 if (strlen(latlon) > 12) {
95 strncpy(buffer, &latlon[nextPos], 2);
97 lon += (atof (buffer) / 3600.00);
104 while (!((infoString[i] == '\t') || (infoString[i] == '\n'))) {
108 strncpy(buffer, (&infoString[start]), size);
113 /* the copy constructor */
114 SGTimeZone::SGTimeZone(const SGTimeZone& other)
116 lat = other.getLat();
117 lon = other.getLon();
118 countryCode = other.countryCode;
119 descriptor = other.descriptor;
123 /********* Member functions for SGTimeZoneContainer class ********/
125 SGTimeZoneContainer::SGTimeZoneContainer(const char *filename)
128 FILE* infile = fopen(filename, "rb");
130 fprintf(stderr, "Unable to open file %s\n", filename);
136 fgets(buffer, 256, infile);
140 for (char *p = buffer; *p; p++) {
147 data.push_back(new SGTimeZone(buffer));
151 perror( "SGTimeZoneContainer()" );
157 SGTimeZoneContainer::~SGTimeZoneContainer()