|
1 // Copyright (C) 1999,2000 Bruce Guenter <bruceg@em.ca> |
|
2 // |
|
3 // This program is free software; you can redistribute it and/or modify |
|
4 // it under the terms of the GNU General Public License as published by |
|
5 // the Free Software Foundation; either version 2 of the License, or |
|
6 // (at your option) any later version. |
|
7 // |
|
8 // This program is distributed in the hope that it will be useful, |
|
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 // GNU General Public License for more details. |
|
12 // |
|
13 // You should have received a copy of the GNU General Public License |
|
14 // along with this program; if not, write to the Free Software |
|
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 #ifndef MYSTRING__JOIN__H__ |
|
18 #define MYSTRING__JOIN__H__ |
|
19 |
|
20 class mystringjoin |
|
21 { |
|
22 private: |
|
23 const mystringjoin* prev; |
|
24 mystringrep* rep; |
|
25 const char* str; |
|
26 |
|
27 mystringjoin(); |
|
28 public: |
|
29 mystringjoin(const mystringjoin& j) |
|
30 : prev(j.prev), rep(j.rep), str(j.str) |
|
31 { |
|
32 rep->attach(); |
|
33 } |
|
34 mystringjoin(const mystring& s) |
|
35 : prev(0), rep(s.rep), str(s.rep->buf) |
|
36 { |
|
37 rep->attach(); |
|
38 } |
|
39 mystringjoin(const char* s) |
|
40 : prev(0), rep(0), str(s) |
|
41 { |
|
42 } |
|
43 mystringjoin(const mystringjoin& p, const mystring& s) |
|
44 : prev(&p), rep(s.rep), str(s.rep->buf) |
|
45 { |
|
46 rep->attach(); |
|
47 } |
|
48 mystringjoin(const mystringjoin& p, const char* s) |
|
49 : prev(&p), rep(0), str(s) |
|
50 { |
|
51 } |
|
52 ~mystringjoin() |
|
53 { |
|
54 if(rep) rep->detach(); |
|
55 } |
|
56 mystringrep* traverse() const; |
|
57 }; |
|
58 |
|
59 inline mystring::mystring(const mystringjoin& j) |
|
60 : rep(j.traverse()) |
|
61 { |
|
62 rep->attach(); |
|
63 } |
|
64 |
|
65 inline mystringjoin operator+(const mystringjoin& a, const mystring& b) |
|
66 { |
|
67 return mystringjoin(a, b); |
|
68 } |
|
69 |
|
70 inline mystringjoin operator+(const mystringjoin& a, const char* b) |
|
71 { |
|
72 return mystringjoin(a, b); |
|
73 } |
|
74 |
|
75 #endif |