]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/hashcomp.cpp
Making sure this is compatible with GCC3.4/4.x
[user/henk/code/inspircd.git] / src / hashcomp.cpp
1 #include <string>
2 #include "inspircd.h"
3 #include "hashcomp.h"
4 #include "helperfuncs.h"
5 #ifdef GCC3
6 #include <ext/hash_map>
7 #else
8 #include <hash_map>
9 #endif
10
11 #ifdef GCC3
12 #define nspace __gnu_cxx
13 #else
14 #define nspace std
15 #endif
16
17 using namespace std;
18
19 #ifdef GCC34
20 size_t hash<in_addr>::operator()(const struct in_addr &a) const
21 #else
22 size_t nspace::hash<in_addr>::operator()(const struct in_addr &a) const
23 #endif
24 {
25         size_t q;
26         memcpy(&q,&a,sizeof(size_t));
27         return q;
28 }
29
30 #ifdef GCC34
31 size_t hash<string>::operator()(const string &s) const
32 #else
33 size_t nspace::hash<string>::operator()(const string &s) const
34 #endif
35 {
36         char a[MAXBUF];
37         static struct hash<const char *> strhash;
38         strlcpy(a,s.c_str(),MAXBUF);
39         strlower(a);
40         return strhash(a);
41 }
42
43 bool StrHashComp::operator()(const string& s1, const string& s2) const
44 {
45         char a[MAXBUF],b[MAXBUF];
46         strlcpy(a,s1.c_str(),MAXBUF);
47         strlcpy(b,s2.c_str(),MAXBUF);
48         strlower(a);
49         strlower(b);
50         return (strcasecmp(a,b) == 0);
51 }
52
53 bool InAddr_HashComp::operator()(const in_addr &s1, const in_addr &s2) const
54 {
55         size_t q;
56         size_t p;
57
58         memcpy(&q,&s1,sizeof(size_t));
59         memcpy(&p,&s2,sizeof(size_t));
60
61         return (q == p);
62 }
63