aboutsummaryrefslogtreecommitdiff
path: root/src/Map.cc
blob: c4d6070ca39e38aef0450325af4b0b41f0b07713 (plain)
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
#include <map>
#include <string>

#include "httpd_Map.h"

typedef std::map<std::string,void *> iMap;

extern "C" {

uMap Httpd_MapCreate(void)
{
  return new iMap;
}

void * Httpd_MapData(uMap map, size_t keylen, const char * key)
{
  iMap& imap(*static_cast<iMap*>(map));
  const std::string ikey(key, keylen);
  iMap::iterator it(imap.find(ikey));

  if(it != imap.end())
    return it->second;
  else
    return NULL;
}

int Httpd_MapStore(uMap map, size_t keylen, const char * key, void * data)
{
  iMap& imap(*static_cast<iMap*>(map));
  const std::string ikey(key, keylen);
  iMap::iterator it(imap.find(ikey));

  if(it != imap.end())
    it->second = data;
  else
    imap[ikey] = data;

  return 0;
}

void Httpd_MapDestroy(uMap map, void (*destroy)(void *))
{
  iMap& imap(*static_cast<iMap*>(map));
  for(iMap::iterator it = imap.begin() ; it != imap.end() ; ++it)
    destroy(it->second);
  delete &imap;
}

}