//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TACString.h // = Version : ver2.0 // = Author : xlc // = CreateDate : 2002-09-09 // = Description: 类的声明 // = Maintainers: // //-----------------------------------------------------------------------------+ #ifndef _TACSTRING_H_ #define _TACSTRING_H_ #ifndef _UNICODE #define TCString TACString #define tstrchr_new StrchrNew #define tstrnew StrNew #endif class GEOAPI TACString { public: TACString(int len = 256); TACString(const TACString &src); TACString(const char *format, ...); ~TACString(); int operator ! () const; int operator == (const char *src) const; int operator == (const TACString &src) const; int operator != (const char *src) const; int operator != (const TACString &src) const; // str的空间要足够大; TACString & operator << (const char *s); TACString & operator << (int i); TACString & operator << (long i); TACString & operator << (double r); TACString & operator << (double * pt); // TACString & operator = (int nLength); TACString & operator = (const TACString & src); TACString & operator = (const char * src); operator const char * () const; operator char * (); char & operator [] (int index); const char & operator [] (int index) const; #ifndef _UNICODE TACString(const CString &src); TACString & operator = (const CString &src); TACString & operator << (const CString &src); int operator == (const CString &src) const; int operator != (const CString &src) const; #endif int Length(); char * StrChr(char c); public: char *str; }; inline TACString::TACString(int len) { if (len <= 0) { exit(1); } str = new char [len]; str[0] = 0; } inline TACString::TACString(const TACString &src) : str(NULL) { (*this) = src.str; } inline TACString::~TACString() { if (str) { delete [] str; } } #ifndef _UNICODE inline TACString::TACString(const CString &src) : str(NULL) { (*this) = (const char *)src; } inline TACString & TACString::operator = (const CString &src) { return ((*this) = (const char *)src); } inline TACString & TACString::operator << (const CString &src) { // str的空间要足够大 return ((*this) << (const char *)src); } inline int TACString::operator == (const CString &src) const { return ((*this) == (const char *)src); } inline int TACString::operator != (const CString &src) const { return ((*this) != (const char *)src); } #endif inline int TACString::Length() { if (str) { return static_cast(strlen(str)); } else { return 0; } } inline char * TACString::StrChr(char c) { return strchr(str,c); } inline TACString::operator const char * () const { return str; } inline TACString::operator char * () { return str; } inline char& TACString::operator [] (int index) { return str[index]; } inline const char& TACString::operator [] (int index) const { return str[index]; } inline TACString& TACString::operator << (const char *s) { // str的空间要足够大 if (!str) { str = new char [256]; str[0] = 0; } strcat(str, s); return *this; } inline TACString& TACString::operator << (int i) { if (!str) { str = new char [256]; str[0] = 0; } char s[30]; sprintf(s, "%d", i); strcat(str, s); return *this; } inline TACString & TACString::operator << (long i) { if (!str) { str = new char [256]; str[0] = 0; } char s[30]; sprintf(s,"%ld", i); strcat(str, s); return *this; } inline TACString & TACString::operator << (double r) { if (!str) { str = new char [256]; str[0] = 0; } char s[60]; sprintf(s, "%g", r); strcat(str, s); return *this; } inline TACString & TACString::operator << (double * pt) { if (!str) { str = new char [256]; str[0] = 0; } char s[120]; sprintf(s, "(%g,%g,%g)", pt[0], pt[1], pt[2]); strcat(str, s); return *this; } inline int TACString::operator !() const { return (!str || !str[0]) ? 1 : 0; } inline int TACString::operator == (const char *src) const { if (!str || !src) { exit(1); } return !strcmp(str, src); } inline int TACString::operator != (const char *src) const { if (!str || !src) { exit(1); } return strcmp(str, src); } inline int TACString::operator == (const TACString &src) const { if (!str || !src.str) { exit(1); } return !strcmp(str, src.str); } inline int TACString::operator != (const TACString &src) const { if (!str || !src.str) { exit(1); } return strcmp(str, src.str); } #endif