ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/shstr.h
(Generate patch)

Comparing deliantra/server/include/shstr.h (file contents):
Revision 1.6 by root, Sun Sep 3 07:57:56 2006 UTC vs.
Revision 1.7 by root, Sun Sep 3 09:00:09 2006 UTC

5 5
6struct shstr 6struct shstr
7{ 7{
8 const char *s; 8 const char *s;
9 9
10 int &refcnt () 10 static int &refcnt (const char *s)
11 { 11 {
12 return *((int *)s - 1); 12 return *((int *)s - 1);
13 }
14
15 static int &length (const char *s)
16 {
17 return *((int *)s - 2);
18 }
19
20 int &refcnt () const
21 {
22 return refcnt (s);
23 }
24
25 int length () const
26 {
27 return s ? length (s) : 0;
13 } 28 }
14 29
15 static const char *find (const char *s); 30 static const char *find (const char *s);
16 static const char *intern (const char *s); 31 static const char *intern (const char *s);
17 32
20 // this is used for informational messages and the like 35 // this is used for informational messages and the like
21 const char *operator &() const { return s ? s : "<nil>"; } 36 const char *operator &() const { return s ? s : "<nil>"; }
22 37
23 const char &operator [](int i) const { return s[i]; } 38 const char &operator [](int i) const { return s[i]; }
24 operator const char *() const { return s; } 39 operator const char *() const { return s; }
25
26 int length () const
27 {
28 return s ? *((int *)s - 2) : 0;
29 }
30 40
31 shstr () 41 shstr ()
32 : s (0) 42 : s (0)
33 { 43 {
34 } 44 }
40 } 50 }
41 51
42 explicit shstr (const char *s) 52 explicit shstr (const char *s)
43 : s (intern (s)) 53 : s (intern (s))
44 { 54 {
45 if (s) ++refcnt ();
46 } 55 }
47 56
48 ~shstr () 57 ~shstr ()
49 { 58 {
50 if (s) --refcnt (); 59 if (s) --refcnt ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines