Path: blob/devel/ElmerGUI/netgen/libsrc/general/mystring.hpp
3206 views
1//**************************************************************2//3// filename: mystring.h4//5// project: doctoral thesis, program smart6//7// autor: Dipl.-Ing. Gerstmayr Johannes8//9// generated: 20.12.9810// last change: 20.12.9811// description: base class for strings12// remarks: string with n characters has13// 0..n-1 characters and at pos n a 014//15//**************************************************************161718#ifndef MYSTRING__H19#define MYSTRING__H2021class Point3d;22class Vec3d;232425// extract string str which is enclosed by the given character encl from a given string in26void ReadEnclString(istream & in, string & str, const char encl);272829class MyStr;3031MyStr operator + (const MyStr &, const MyStr &);32int operator == (const MyStr &, const MyStr &);33int operator < (const MyStr &, const MyStr &);34int operator <= (const MyStr &, const MyStr &);35int operator > (const MyStr &, const MyStr &);36int operator >= (const MyStr &, const MyStr &);37int operator != (const MyStr &, const MyStr &);38ostream& operator << (ostream &, const MyStr &);39istream& operator >> (istream &, MyStr &);4041class MyStr42{43public:44MyStr();45MyStr(const char *);46MyStr(char);47MyStr(const MyStr &);48MyStr(int);49MyStr(void *);50MyStr(long);51MyStr(double);52MyStr(const Point3d& p);53MyStr(const Vec3d& p);54MyStr(const string & st);5556~MyStr();57MyStr Left(unsigned);58MyStr Right(unsigned);59MyStr& InsertAt(unsigned, const MyStr &);60MyStr& WriteAt(unsigned, const MyStr &);61unsigned Length() const;62int Find(const char);63int Find(const char *);64int Find(const MyStr &);65MyStr& operator = (const MyStr &);66friend MyStr operator + (const MyStr &, const MyStr &);67void operator += (const MyStr &);68char* c_str();69string cpp_string(void) const;7071//change every ',' -> ';', '.' -> ','72void ConvertTextToExcel();73//change every ','->'.', ';'->','74void ConvertExcelToText();7576MyStr operator () (unsigned, unsigned);77operator int();78operator double();79operator long();80operator char *();81char& operator [] (unsigned int);82char operator [] (unsigned int) const;8384friend int operator == (const MyStr &, const MyStr &);85friend int operator < (const MyStr &, const MyStr &);86friend int operator <= (const MyStr &, const MyStr &);87friend int operator > (const MyStr &, const MyStr &);88friend int operator >= (const MyStr &, const MyStr &);89friend int operator != (const MyStr &, const MyStr &);90friend ostream& operator << (ostream &, const MyStr &);91friend istream& operator >> (istream &, MyStr &);92static void SetToErrHandler(void (*)());93private:94MyStr(unsigned, int);95char *str;96unsigned length;97enum { SHORTLEN = 24 };98char shortstr[SHORTLEN+1];99static void(*ErrHandler)();100};101102103inline MyStr::MyStr()104{105length = 0;106str = shortstr;107str[0] = 0;108}109110inline MyStr::MyStr(char s)111{112length = 1;113str = shortstr;114str[0] = s;115str[1] = (char)0;116}117118inline MyStr::~MyStr()119{120if (length > SHORTLEN)121delete [] str;122}123124inline unsigned MyStr::Length() const125{126return length;127}128129inline int MyStr::Find(const char c)130{131char *pos = strchr(str, int(c));132return pos ? int(pos - str) : -1;133}134135inline int MyStr::Find(const MyStr &s)136{137char *pos = strstr(str, s.str);138return pos ? int(pos - str) : -1;139}140141inline int MyStr::Find(const char *s)142{143char *pos = strstr(str, s);144return pos ? int(pos - str) : -1;145}146147inline MyStr::operator int()148{149return atoi(str);150}151152inline MyStr::operator double()153{154return atof(str);155}156157inline MyStr::operator long()158{159return atol(str);160}161162inline MyStr::operator char *()163{164return str;165}166167inline char* MyStr::c_str()168{169return str;170}171172173inline int operator == (const MyStr &s1, const MyStr& s2)174{175return strcmp(s1.str, s2.str) == 0;176}177178inline int operator < (const MyStr &s1, const MyStr& s2)179{180return strcmp(s1.str, s2.str) < 0;181}182183inline int operator <= (const MyStr &s1, const MyStr& s2)184{185return strcmp(s1.str, s2.str) <= 0;186}187188inline int operator > (const MyStr &s1, const MyStr& s2)189{190return strcmp(s1.str, s2.str) > 0;191}192193inline int operator >= (const MyStr &s1, const MyStr& s2)194{195return strcmp(s1.str, s2.str) >= 0;196}197198inline int operator != (const MyStr &s1, const MyStr& s2)199{200return !(s1 == s2);201}202203inline ostream& operator << (ostream& os, const MyStr& s)204{205return os << s.str;206}207208inline void MyStr::SetToErrHandler(void (*Handler)())209{210ErrHandler = Handler;211};212213#endif214215216217218