]> err.no Git - sope/blob - sope-xml/libxmlSAXDriver/TableCallbacks.m
renamed test tools
[sope] / sope-xml / libxmlSAXDriver / TableCallbacks.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
6   SOPE is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with SOPE; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include "TableCallbacks.h"
23 #include "common.h"
24
25 //#define NSNonOwnedCStringMapKeyCallBacks NSNonOwnedPointerMapKeyCallBacks
26
27 /* From Aho, Sethi & Ullman: Principles of compiler design. */
28 static unsigned __hashCString(void *table, const void *aString) {
29   register const char* p = (char*)aString;
30   register unsigned hash = 0, hash2;
31   register int i, n;
32   
33   n = aString ? strlen(aString) : 0;
34   for(i=0; i < n; i++) {
35     hash <<= 4;
36     hash += *p++;
37     if((hash2 = hash & 0xf0000000))
38       hash ^= (hash2 >> 24) ^ hash2;
39   }
40   return hash;
41 }
42
43 static BOOL __compareCString(void *table, 
44                                const void *anObject1,
45                                const void *anObject2)
46 {
47   if (anObject1 == NULL && anObject2 == NULL) return YES;
48   if (anObject1 == NULL || anObject2 == NULL) return NO;
49   return strcmp((char*)anObject1, (char*)anObject2) == 0;
50 }
51
52 static void __retain(void *table, const void *anObject) {}
53 static void __release(void *table, void *anObject) {}
54
55 static NSString *__describe(void *table, const void *anObject) {
56     return [NSString stringWithFormat:@"%p", anObject];
57 }
58
59 const NSMapTableKeyCallBacks libxmlNonOwnedCStringMapKeyCallBacks =  {
60     (unsigned(*)(NSMapTable *, const void *))__hashCString,
61     (BOOL(*)(NSMapTable *, const void *, const void *))__compareCString,
62     (void (*)(NSMapTable *, const void *anObject))__retain,
63     (void (*)(NSMapTable *, void *anObject))__release,
64     (NSString *(*)(NSMapTable *, const void *))__describe,
65     (const void *)NULL
66 };