]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/hashcomp.h
Added comments for doxygen
[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 /** This class returns true if two strings match.
57  * Case sensitivity is ignored, and the RFC 'character set'
58  * is adhered to
59  */
60 struct StrHashComp
61 {
62         /** The operator () does the actual comparison in hash_map
63          */
64         bool operator()(const string& s1, const string& s2) const;
65 };
66
67 /** This class returns true if two in_addr structs match.
68  * Checking is done by copying both into a size_t then doing a
69  * numeric comparison of the two.
70  */
71 struct InAddr_HashComp
72 {
73         /** The operator () does the actual comparison in hash_map
74          */
75         bool operator()(const in_addr &s1, const in_addr &s2) const;
76 };
77
78 /** The irc namespace contains a number of helper classes.
79  */
80 namespace irc
81 {
82         /** The irc_char_traits class is used for RFC-style comparison of strings.
83          * This class is used to implement irc::string, a case-insensitive, RFC-
84          * comparing string class.
85          */
86         struct irc_char_traits : std::char_traits<char> {
87
88                 /** Check if two chars match
89                  */
90                 static bool eq(char c1st, char c2nd);
91
92                 /** Check if two chars do NOT match
93                  */
94                 static bool ne(char c1st, char c2nd);
95
96                 /** Check if one char is less than another
97                  */
98                 static bool lt(char c1st, char c2nd);
99
100                 /** Compare two strings of size n
101                  */
102                 static int compare(const char* str1, const char* str2, size_t n);
103
104                 /** Find a char within a string up to position n
105                  */
106                 static const char* find(const char* s1, int  n, char c);
107         };
108
109         /** This typedef declares irc::string based upon irc_char_traits
110          */
111         typedef basic_string<char, irc_char_traits, allocator<char> > string;
112 }
113
114 #endif