//double getAngle(const GeoCoord& other) const;
virtual void print() {} ;
- virtual char *getDescription() {return 0;};
+ virtual const char * getDescription() {return 0;};
};
typedef vector<GeoCoord*> GeoCoordVector;
# include <stdlib.h>
#endif
+#include <string>
+
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h> // for get/setitimer, gettimeofday, struct timeval
#endif
#include "timezone.h"
#include "lowleveltime.h"
-
#define DEGHR(x) ((x)/15.)
#define RADHR(x) DEGHR(x*SGD_RADIANS_TO_DEGREES)
SGPath name( root );
name.append( nearestTz->getDescription() );
- zonename = strdup( name.c_str() );
+ zonename = name.str();
SG_LOG( SG_EVENT, SG_INFO, "Using zonename = " << zonename );
} else {
SG_LOG( SG_EVENT, SG_INFO, "*** NO TIME ZONE NAME ***" );
tzContainer = NULL;
- zonename = NULL;
+ zonename.erase();
}
}
tzContainer = NULL;
delete tmp;
}
-
- if ( zonename != NULL ) {
- char *tmp = zonename;
- zonename = NULL;
- free(tmp);
- }
}
GeoCoord* nearestTz = tzContainer->getNearest(location);
SGPath zone( root );
zone.append ( nearestTz->getDescription() );
- if ( zonename ) {
- char *ptr = zonename;
- zonename = NULL;
- free(ptr);
- }
- zonename = strdup( zone.c_str() );
+ zonename = zone.str();
//Avoid troubles when zone.tab hasn't got the right line endings
- if (zonename[strlen(zonename)-1] == '\r')
+ if (zonename[zonename.size()-1] == '\r')
{
- zonename[strlen(zonename)-1]=0;
+ zonename[zonename.size()-1]=0;
zone.set( zonename );
}
TimezoneContainer* tzContainer;
// Points to the current local timezone name;
- char *zonename;
+ string zonename;
// Unix "calendar" time in seconds
time_t cur_time;
inline time_t get_cur_time() const { return cur_time; };
/** @return time zone name for your current position*/
- inline char* get_zonename() const { return zonename; }
+ inline const char * get_zonename() const { return zonename.c_str(); }
/** @return GMT in a "brokent down" tm structure */
#if defined(_MSC_VER) || defined(__MINGW32__)
Timezone::Timezone(float la, float lo, char* cc, char* desc) :
GeoCoord(la, lo)
{
- countryCode = strdup(cc);
- descriptor = strdup(desc);
+ countryCode = cc;
+ descriptor = desc;
}
/* Build a timezone object from a textline in zone.tab */
char latlon[128];
strncpy(buffer, infoString, i);
buffer[i] = 0;
- countryCode = strdup(buffer);
+ countryCode = buffer;
i ++;
int start = i;
while (infoString[i] != '\t') {
size = i - start;
strncpy(buffer, (&infoString[start]), size);
buffer[size] = 0;
- descriptor = strdup(buffer);
+ descriptor = buffer;
}
/* the copy constructor */
{
lat = other.getLat();
lon = other.getLon();
- countryCode = strdup(other.countryCode);
- descriptor = strdup(other.descriptor);
+ countryCode = other.countryCode;
+ descriptor = other.descriptor;
}
class Timezone : public GeoCoord
{
private:
- char* countryCode;
- char* descriptor;
+ string countryCode;
+ string descriptor;
public:
Timezone() :
GeoCoord()
{
- countryCode = 0;
- descriptor = 0;
+ countryCode.erase();
+ descriptor.erase();
};
Timezone(float la, float lo, char* cc, char* desc);
Timezone(const char *infoString);
Timezone(const Timezone &other);
- virtual ~Timezone() { delete [] countryCode; delete [] descriptor; };
+ virtual ~Timezone() { };
- virtual void print() { printf("%s", descriptor);};
- virtual char * getDescription() { return descriptor; };
+ virtual void print() { printf("%s", descriptor.c_str());};
+ virtual const char * getDescription() { return descriptor.c_str(); };
};
/************************************************************************