Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/general/mystring.hpp
3206 views
1
2
//**************************************************************
3
//
4
// filename: mystring.h
5
//
6
// project: doctoral thesis, program smart
7
//
8
// autor: Dipl.-Ing. Gerstmayr Johannes
9
//
10
// generated: 20.12.98
11
// last change: 20.12.98
12
// description: base class for strings
13
// remarks: string with n characters has
14
// 0..n-1 characters and at pos n a 0
15
//
16
//**************************************************************
17
18
19
#ifndef MYSTRING__H
20
#define MYSTRING__H
21
22
class Point3d;
23
class Vec3d;
24
25
26
// extract string str which is enclosed by the given character encl from a given string in
27
void ReadEnclString(istream & in, string & str, const char encl);
28
29
30
class MyStr;
31
32
MyStr operator + (const MyStr &, const MyStr &);
33
int operator == (const MyStr &, const MyStr &);
34
int operator < (const MyStr &, const MyStr &);
35
int operator <= (const MyStr &, const MyStr &);
36
int operator > (const MyStr &, const MyStr &);
37
int operator >= (const MyStr &, const MyStr &);
38
int operator != (const MyStr &, const MyStr &);
39
ostream& operator << (ostream &, const MyStr &);
40
istream& operator >> (istream &, MyStr &);
41
42
class MyStr
43
{
44
public:
45
MyStr();
46
MyStr(const char *);
47
MyStr(char);
48
MyStr(const MyStr &);
49
MyStr(int);
50
MyStr(void *);
51
MyStr(long);
52
MyStr(double);
53
MyStr(const Point3d& p);
54
MyStr(const Vec3d& p);
55
MyStr(const string & st);
56
57
~MyStr();
58
MyStr Left(unsigned);
59
MyStr Right(unsigned);
60
MyStr& InsertAt(unsigned, const MyStr &);
61
MyStr& WriteAt(unsigned, const MyStr &);
62
unsigned Length() const;
63
int Find(const char);
64
int Find(const char *);
65
int Find(const MyStr &);
66
MyStr& operator = (const MyStr &);
67
friend MyStr operator + (const MyStr &, const MyStr &);
68
void operator += (const MyStr &);
69
char* c_str();
70
string cpp_string(void) const;
71
72
//change every ',' -> ';', '.' -> ','
73
void ConvertTextToExcel();
74
//change every ','->'.', ';'->','
75
void ConvertExcelToText();
76
77
MyStr operator () (unsigned, unsigned);
78
operator int();
79
operator double();
80
operator long();
81
operator char *();
82
char& operator [] (unsigned int);
83
char operator [] (unsigned int) const;
84
85
friend int operator == (const MyStr &, const MyStr &);
86
friend int operator < (const MyStr &, const MyStr &);
87
friend int operator <= (const MyStr &, const MyStr &);
88
friend int operator > (const MyStr &, const MyStr &);
89
friend int operator >= (const MyStr &, const MyStr &);
90
friend int operator != (const MyStr &, const MyStr &);
91
friend ostream& operator << (ostream &, const MyStr &);
92
friend istream& operator >> (istream &, MyStr &);
93
static void SetToErrHandler(void (*)());
94
private:
95
MyStr(unsigned, int);
96
char *str;
97
unsigned length;
98
enum { SHORTLEN = 24 };
99
char shortstr[SHORTLEN+1];
100
static void(*ErrHandler)();
101
};
102
103
104
inline MyStr::MyStr()
105
{
106
length = 0;
107
str = shortstr;
108
str[0] = 0;
109
}
110
111
inline MyStr::MyStr(char s)
112
{
113
length = 1;
114
str = shortstr;
115
str[0] = s;
116
str[1] = (char)0;
117
}
118
119
inline MyStr::~MyStr()
120
{
121
if (length > SHORTLEN)
122
delete [] str;
123
}
124
125
inline unsigned MyStr::Length() const
126
{
127
return length;
128
}
129
130
inline int MyStr::Find(const char c)
131
{
132
char *pos = strchr(str, int(c));
133
return pos ? int(pos - str) : -1;
134
}
135
136
inline int MyStr::Find(const MyStr &s)
137
{
138
char *pos = strstr(str, s.str);
139
return pos ? int(pos - str) : -1;
140
}
141
142
inline int MyStr::Find(const char *s)
143
{
144
char *pos = strstr(str, s);
145
return pos ? int(pos - str) : -1;
146
}
147
148
inline MyStr::operator int()
149
{
150
return atoi(str);
151
}
152
153
inline MyStr::operator double()
154
{
155
return atof(str);
156
}
157
158
inline MyStr::operator long()
159
{
160
return atol(str);
161
}
162
163
inline MyStr::operator char *()
164
{
165
return str;
166
}
167
168
inline char* MyStr::c_str()
169
{
170
return str;
171
}
172
173
174
inline int operator == (const MyStr &s1, const MyStr& s2)
175
{
176
return strcmp(s1.str, s2.str) == 0;
177
}
178
179
inline int operator < (const MyStr &s1, const MyStr& s2)
180
{
181
return strcmp(s1.str, s2.str) < 0;
182
}
183
184
inline int operator <= (const MyStr &s1, const MyStr& s2)
185
{
186
return strcmp(s1.str, s2.str) <= 0;
187
}
188
189
inline int operator > (const MyStr &s1, const MyStr& s2)
190
{
191
return strcmp(s1.str, s2.str) > 0;
192
}
193
194
inline int operator >= (const MyStr &s1, const MyStr& s2)
195
{
196
return strcmp(s1.str, s2.str) >= 0;
197
}
198
199
inline int operator != (const MyStr &s1, const MyStr& s2)
200
{
201
return !(s1 == s2);
202
}
203
204
inline ostream& operator << (ostream& os, const MyStr& s)
205
{
206
return os << s.str;
207
}
208
209
inline void MyStr::SetToErrHandler(void (*Handler)())
210
{
211
ErrHandler = Handler;
212
};
213
214
#endif
215
216
217
218