//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : XAString.h // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: 类的声明 // = Maintainers: // //-----------------------------------------------------------------------------+ #ifndef _XASTRING_H_ #define _XASTRING_H_ #ifndef _UNICODE #define XString XAString #define tstrchr_new strchr_new #define tstrnew strnew #endif class GEOAPI XAString { public: XAString(int len = 256); XAString(const XAString &src); XAString(const char *format, ...); ~XAString(); int operator ! () const; int operator == (const char *src) const; int operator == (const XAString &src) const; int operator != (const char *src) const; int operator != (const XAString &src) const; // str的空间要足够大; XAString & operator << (const char *s); XAString & operator << (int i); XAString & operator << (long i); XAString & operator << (double r); XAString & operator << (double * pt); // XAString & operator = (int nLength); XAString & operator = (const XAString & src); XAString & operator = (const char * src); operator const char * () const; operator char * (); char & operator [] (int index); const char & operator [] (int index) const; #ifndef _UNICODE XAString(const CString &src); XAString & operator = (const CString &src); XAString & 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 XAString::XAString(int len) { if (len <= 0) { exit(1); } str = new char [len]; str[0] = 0; } inline XAString::XAString(const XAString &src) : str(NULL) { (*this) = src.str; } inline XAString::~XAString() { if (str) { delete [] str; } } #ifndef _UNICODE inline XAString::XAString(const CString &src) : str(NULL) { (*this) = (const char *)src; } inline XAString & XAString::operator = (const CString &src) { return ((*this) = (const char *)src); } inline XAString & XAString::operator << (const CString &src) { // str的空间要足够大 return ((*this) << (const char *)src); } inline int XAString::operator == (const CString &src) const { return ((*this) == (const char *)src); } inline int XAString::operator != (const CString &src) const { return ((*this) != (const char *)src); } #endif inline int XAString::Length() { if (str) { return static_cast(strlen(str)); } else { return 0; } } inline char * XAString::StrChr(char c) { return strchr(str,c); } inline XAString::operator const char * () const { return str; } inline XAString::operator char * () { return str; } inline char& XAString::operator [] (int index) { return str[index]; } inline const char& XAString::operator [] (int index) const { return str[index]; } inline XAString& XAString::operator << (const char *s) { // str的空间要足够大 if (!str) { str = new char [256]; str[0] = 0; } strcat(str, s); return *this; } inline XAString& XAString::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 XAString & XAString::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 XAString & XAString::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 XAString & XAString::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 XAString::operator !() const { return (!str || !str[0]) ? 1 : 0; } inline int XAString::operator == (const char *src) const { if (!str || !src) { exit(1); } return !strcmp(str, src); } inline int XAString::operator != (const char *src) const { if (!str || !src) { exit(1); } return strcmp(str, src); } inline int XAString::operator == (const XAString &src) const { if (!str || !src.str) { exit(1); } return !strcmp(str, src.str); } inline int XAString::operator != (const XAString &src) const { if (!str || !src.str) { exit(1); } return strcmp(str, src.str); } #endif