File: hashtable.i

package info (click to toggle)
mapserver 5.0.3-3%2Blenny7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,556 kB
  • ctags: 12,645
  • sloc: ansic: 168,024; cs: 8,534; python: 4,618; sh: 4,213; cpp: 4,059; perl: 2,781; makefile: 787; lex: 564; java: 415; yacc: 334; tcl: 158; ruby: 53
file content (82 lines) | stat: -rw-r--r-- 1,970 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* $Id: hashtable.i 4424 2005-02-18 20:10:01Z sean $
 */

%{
#include "../../maphash.h"
%}

/* ========================================================================
 * Include maphash header, first stating declarations to ignore
 * ======================================================================== */

/* ignore the hashObj struct */
%ignore hashObj;

/* ignore items and make numitems immutable */
%ignore items;
%immutable numitems;

%include "../../maphash.h"

/* ======================================================================== 
 * Extension methods
 * ======================================================================== */

%extend hashTableObj {
    
    /* New instance */
#if defined(SWIGJAVA) || defined(SWIGCSHARP)
    hashTableObj() {
#else
    hashTableObj(void) {
#endif
        return msCreateHashTable();
    }

    /* Destroy instance */
    ~hashTableObj() {
        msFreeHashTable(self);
    }

    /* set a hash item given key and value */
    int set(char *key, char *value) {
        if (msInsertHashTable(self, key, value) == NULL) {
	        return MS_FAILURE;
        }
        return MS_SUCCESS;
    }

    /* get value from item by its key */
    char *get(char *key, char *default_value=NULL) {
        char *value = NULL;
        if (!key) {
            msSetError(MS_HASHERR, "NULL key", "get");
        }
     
        value = (char *) msLookupHashTable(self, key);
        if (!value) {
            return default_value;
        }
        return value;
    }

    /* Remove one item from hash table */
    int remove(char *key) {
        return msRemoveHashTable(self, key);
    }

    /* Clear all items in hash table (to NULL) */
    void clear(void) {
        msFreeHashItems(self);
        initHashTable(self);
    }

    /* Return the next key or first key if prevkey == NULL */
    const char *nextKey(char *prevkey=NULL) {
        return msNextKeyFromHashTable(self, (const char *) prevkey);
    }
    
}