]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/hashcomp.h
b4652642bca350462c2a64caee1de3a25e6ce0fe
[user/henk/code/inspircd.git] / include / hashcomp.h
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 #ifndef _HASHCOMP_H_
18 #define _HASHCOMP_H_
19
20 #include "inspircd_config.h"
21
22 #ifdef GCC3
23 #include <ext/hash_map>
24 #else
25 #include <hash_map>
26 #endif
27
28 #ifdef GCC3
29 #define nspace __gnu_cxx
30 #else
31 #define nspace std
32 #endif
33
34 using namespace std;
35
36 namespace nspace
37 {
38 #ifdef GCC34
39         template<> struct hash<in_addr>
40 #else
41         template<> struct nspace::hash<in_addr>
42 #endif
43         {
44                 size_t operator()(const struct in_addr &a) const;
45         };
46 #ifdef GCC34
47         template<> struct hash<string>
48 #else
49         template<> struct nspace::hash<string>
50 #endif
51         {
52                 size_t operator()(const string &s) const;
53         };
54 }
55
56 /** The irc namespace contains a number of helper classes.
57  */
58 namespace irc
59 {
60
61         /** This class returns true if two strings match.
62          * Case sensitivity is ignored, and the RFC 'character set'
63          * is adhered to
64          */
65         struct StrHashComp
66         {
67                 /** The operator () does the actual comparison in hash_map
68                  */
69                 bool operator()(const std::string& s1, const std::string& s2) const;
70         };
71
72
73         /** This class returns true if two in_addr structs match.
74          * Checking is done by copying both into a size_t then doing a
75          * numeric comparison of the two.
76          */
77         struct InAddr_HashComp
78         {
79                 /** The operator () does the actual comparison in hash_map
80                  */
81                 bool operator()(const in_addr &s1, const in_addr &s2) const;
82         };
83
84
85         /** The irc_char_traits class is used for RFC-style comparison of strings.
86          * This class is used to implement irc::string, a case-insensitive, RFC-
87          * comparing string class.
88          */
89         struct irc_char_traits : std::char_traits<char> {
90
91                 /** Check if two chars match
92                  */
93                 static bool eq(char c1st, char c2nd);
94
95                 /** Check if two chars do NOT match
96                  */
97                 static bool ne(char c1st, char c2nd);
98
99                 /** Check if one char is less than another
100                  */
101                 static bool lt(char c1st, char c2nd);
102
103                 /** Compare two strings of size n
104                  */
105                 static int compare(const char* str1, const char* str2, size_t n);
106
107                 /** Find a char within a string up to position n
108                  */
109                 static const char* find(const char* s1, int  n, char c);
110         };
111
112         /** This typedef declares irc::string based upon irc_char_traits
113          */
114         typedef basic_string<char, irc_char_traits, allocator<char> > string;
115 }
116
117 #endif