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