]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/hashcomp.cpp
GCC 3.4/4.0 fixes
[user/henk/code/inspircd.git] / src / hashcomp.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2005 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <string>
18 #include "inspircd.h"
19 #include "hashcomp.h"
20 #include "helperfuncs.h"
21 #ifdef GCC3
22 #include <ext/hash_map>
23 #else
24 #include <hash_map>
25 #endif
26
27 #ifdef GCC3
28 #define nspace __gnu_cxx
29 #else
30 #define nspace std
31 #endif
32
33 using namespace std;
34
35 size_t nspace::hash<in_addr>::operator()(const struct in_addr &a) const
36 {
37         size_t q;
38         memcpy(&q,&a,sizeof(size_t));
39         return q;
40 }
41
42 size_t nspace::hash<string>::operator()(const string &s) const
43 {
44         char a[MAXBUF];
45         static struct hash<const char *> strhash;
46         strlcpy(a,s.c_str(),MAXBUF);
47         strlower(a);
48         return strhash(a);
49 }
50
51 bool StrHashComp::operator()(const string& s1, const string& s2) const
52 {
53         char a[MAXBUF],b[MAXBUF];
54         strlcpy(a,s1.c_str(),MAXBUF);
55         strlcpy(b,s2.c_str(),MAXBUF);
56         strlower(a);
57         strlower(b);
58         return (strcasecmp(a,b) == 0);
59 }
60
61 bool InAddr_HashComp::operator()(const in_addr &s1, const in_addr &s2) const
62 {
63         size_t q;
64         size_t p;
65
66         memcpy(&q,&s1,sizeof(size_t));
67         memcpy(&p,&s2,sizeof(size_t));
68
69         return (q == p);
70 }
71