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.9 by root, Mon Sep 4 11:07:59 2006 UTC vs.
Revision 1.14 by root, Mon Apr 23 16:07:00 2007 UTC

1#ifndef SHSTR_H__ 1#ifndef SHSTR_H__
2#define SHSTR_H__ 2#define SHSTR_H__
3
4#include <sstream>
3 5
4#include "util.h" 6#include "util.h"
5 7
6extern int buf_overflow (const char *buf1, const char *buf2, int bufsize); 8extern int buf_overflow (const char *buf1, const char *buf2, int bufsize);
7 9
82 else 84 else
83 s = intern (str); 85 s = intern (str);
84 86
85 return *this; 87 return *this;
86 } 88 }
89
90 bool operator ==(const shstr &b)
91 {
92 return s == b.s;
93 }
94
95 bool operator !=(const shstr &b)
96 {
97 return !(*this == b);
98 }
87}; 99};
88 100
89inline int strlen (const shstr &sh) 101inline int strlen (const shstr &sh)
90{ 102{
91 return sh.length (); 103 return sh.length ();
92} 104}
93 105
106inline int strcmp (const shstr &a, const shstr &b)
107{
108 // TODO: use this to find all the occurences of people using strcmp
109 // all uses should be bogus, as we should be never interested in
110 // comparing shstr's alphabetically
111#if 0
112 extern void do_not_use_strcmp_to_compare_shstr_values ();
113 do_not_use_strcmp_to_compare_shstr_values ();
114#endif
115 return a != b;
116}
117
118static std::ostream &operator <<(std::ostream &o, const shstr &sh)
119{
120 o.write (sh.s, sh.length ());
121 return o;
122}
123
124// only good for mass comparisons to shstr objects
125struct shstr_cmp
126{
127 const char *s;
128
129 explicit shstr_cmp (const char *s)
130 : s (shstr::find (s))
131 {
132 }
133
134 shstr_cmp (const shstr_cmp &sh)
135 : s (sh.s)
136 {
137 }
138
139 shstr_cmp &operator =(const shstr_cmp sh) { s = sh.s; return *this; }
140 operator const char *() const { return s; }
141};
142
94inline bool operator ==(const shstr &a, const shstr &b) 143inline bool operator ==(const shstr_cmp &a, const shstr &b)
95{ 144{
96 return a.s == b.s; 145 return a.s == b.s;
97} 146}
98 147
99inline bool operator !=(const shstr &a, const shstr &b) 148inline bool operator ==(const shstr &a, const shstr_cmp &b)
100{ 149{
101 return !(a == b); 150 return b == a;
102} 151}
103 152
104extern const shstr undead_name; /* Used in hit_player() in main.c */ 153extern const shstr undead_name; /* Used in hit_player() in main.c */
105 154
106#endif 155#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines