head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.41; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.59; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.05; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.22.02; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# timezone.cxx

    00001 /* -*- Mode: C++ -*- *****************************************************
    00002  * timezone.cc
    00003  * Written by Durk Talsma. Started July 1999.
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public
    00007  * License as published by the Free Software Foundation; either
    00008  * version 2 of the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful,
    00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public
    00016  * License along with this library; if not, write to the
    00017  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  * Boston, MA  02111-1307, USA.
    00019  *
    00020  **************************************************************************/
    00021
    00022 /*************************************************************************
    00023  *
    00024  * Timezone is derived from geocoord, and stores the timezone centerpoint,
    00025  * as well as the countrycode and the timezone descriptor. The latter is
    00026  * used in order to get the local time.
    00027  *
    00028  ************************************************************************/
    00029
    00030 #include <errno.h>
    00031 #include <string.h>
    00032 #include <stdio.h>
    00033 #include "timezone.h"
    00034
    00035 Timezone::Timezone(float la, float lo, char* cc, char* desc) :
    00036     GeoCoord(la, lo)
    00037 {
    00038     countryCode = strdup(cc);
    00039     descriptor = strdup(desc);
    00040 }
    00041
    00042 /* Build a timezone object from a textline in zone.tab */
    00043 Timezone::Timezone(const char *infoString) :
    00044     GeoCoord()
    00045 {
    00046     int i = 0;
    00047     while (infoString[i] != '\t')
    00048         i++;
    00049     char buffer[128];
    00050     char latlon[128];
    00051     strncpy(buffer, infoString, i);
    00052     buffer[i] = 0;
    00053     countryCode = strdup(buffer);
    00054     i ++;
    00055     int start = i;
    00056     while (infoString[i] != '\t') {
    00057         i++;
    00058     }
    00059     int size = i - start;
    00060     strncpy(latlon, (&infoString[start]), size);
    00061     latlon[size] = 0;
    00062     char sign;
    00063     sign = latlon[0];
    00064     strncpy(buffer, &latlon[1], 2);
    00065     buffer[2] = 0;
    00066     lat = atof(buffer);
    00067     strncpy(buffer, &latlon[3], 2);
    00068     buffer[2] = 0;
    00069     lat += (atof(buffer) / 60);
    00070     int nextPos;
    00071     if (strlen(latlon) > 12) {
    00072         nextPos = 7;
    00073         strncpy(buffer, &latlon[5], 2);
    00074         buffer[2] = 0;
    00075         lat += (atof(buffer) / 3600.0);
    00076     } else {
    00077         nextPos = 5;
    00078     }
    00079     if (sign == '-') {
    00080         lat = -lat;
    00081     }
    00082
    00083     sign = latlon[nextPos];
    00084     nextPos++;
    00085     strncpy(buffer, &latlon[nextPos], 3);
    00086     buffer[3] = 0;
    00087     lon = atof(buffer);
    00088     nextPos += 3;
    00089     strncpy(buffer, &latlon[nextPos], 2);
    00090     buffer[2] = 0;
    00091
    00092     lon  += (atof(buffer) / 60);
    00093     if (strlen(latlon) > 12) {
    00094         nextPos += 2;
    00095         strncpy(buffer, &latlon[nextPos], 2);
    00096         buffer[2] = 0;
    00097         lon +=  (atof (buffer) / 3600.00);
    00098     }
    00099     if (sign == '-') {
    00100         lon = -lon;
    00101     }
    00102     i ++;
    00103     start = i;
    00104     while (!((infoString[i] == '\t') || (infoString[i] == '\n'))) {
    00105         i++;
    00106     }
    00107     size = i - start;
    00108     strncpy(buffer, (&infoString[start]), size);
    00109     buffer[size] = 0;
    00110     descriptor = strdup(buffer);
    00111 }
    00112
    00113 /* the copy constructor */
    00114 Timezone::Timezone(const Timezone& other)
    00115 {
    00116     lat = other.getLat();
    00117     lon = other.getLon();
    00118     countryCode = strdup(other.countryCode);
    00119     descriptor = strdup(other.descriptor);
    00120 }
    00121
    00122
    00123 /********* Member functions for TimezoneContainer class ********/
    00124
    00125 TimezoneContainer::TimezoneContainer(const char *filename)
    00126 {
    00127     char buffer[256];
    00128     FILE* infile = fopen(filename, "rb");
    00129     if (!(infile)) {
    00130         fprintf(stderr, "Unable to open file %s\n", filename);
    00131         exit(1);
    00132     } else {
    00133         errno = 0;
    00134
    00135         while (1) {
    00136             fgets(buffer, 256, infile);
    00137             if (feof(infile)) {
    00138                 break;
    00139             }
    00140             for (char *p = buffer; *p; p++) {
    00141                 if (*p == '#') {
    00142                     *p = 0;
    00143                     break;
    00144                 }
    00145             }
    00146             if (buffer[0]) {
    00147                 data.push_back(new Timezone(buffer));
    00148             }
    00149         }
    00150         if ( errno ) {
    00151             perror( "TimezoneContainer()" );
    00152             errno = 0;
    00153         }
    00154     }
    00155 }
    00156
    00157 TimezoneContainer::~TimezoneContainer()
    00158 {
    00159 }

@ 1.3 log @Oops, try again. @ text @d168 1 a168 1