#include <stdlib.h>
#include <stdio.h>
#include <libpmemobj.h>
#include "map.h"
#define ABORT_NOT_IMPLEMENTED(mapc, func)\
if ((mapc)->ops->func == NULL) {\
fprintf(stderr, "error: '%s'"\
" function not implemented\n", #func);\
exit(1);\
}
struct map_ctx *
map_ctx_init(const struct map_ops *ops, PMEMobjpool *pop)
{
if (!ops)
return NULL;
struct map_ctx *mapc = (struct map_ctx *)calloc(1, sizeof(*mapc));
if (!mapc)
return NULL;
mapc->ops = ops;
mapc->pop = pop;
return mapc;
}
void
map_ctx_free(struct map_ctx *mapc)
{
free(mapc);
}
int
map_create(struct map_ctx *mapc, TOID(struct map) *map, void *arg)
{
ABORT_NOT_IMPLEMENTED(mapc, create);
return mapc->ops->create(mapc->pop, map, arg);
}
int
map_destroy(struct map_ctx *mapc, TOID(struct map) *map)
{
ABORT_NOT_IMPLEMENTED(mapc, destroy);
return mapc->ops->destroy(mapc->pop, map);
}
int
map_init(struct map_ctx *mapc, TOID(struct map) map)
{
ABORT_NOT_IMPLEMENTED(mapc, init);
return mapc->ops->init(mapc->pop, map);
}
int
map_check(struct map_ctx *mapc, TOID(struct map) map)
{
ABORT_NOT_IMPLEMENTED(mapc, check);
return mapc->ops->check(mapc->pop, map);
}
int
map_insert(struct map_ctx *mapc, TOID(struct map) map,
uint64_t key, PMEMoid value)
{
ABORT_NOT_IMPLEMENTED(mapc, insert);
return mapc->ops->insert(mapc->pop, map, key, value);
}
int
map_insert_new(struct map_ctx *mapc, TOID(struct map) map,
uint64_t key, size_t size, unsigned type_num,
void (*constructor)(PMEMobjpool *pop, void *ptr, void *arg),
void *arg)
{
ABORT_NOT_IMPLEMENTED(mapc, insert_new);
return mapc->ops->insert_new(mapc->pop, map, key, size,
type_num, constructor, arg);
}
PMEMoid
map_remove(struct map_ctx *mapc, TOID(struct map) map, uint64_t key)
{
ABORT_NOT_IMPLEMENTED(mapc, remove);
return mapc->ops->remove(mapc->pop, map, key);
}
int
map_remove_free(struct map_ctx *mapc, TOID(struct map) map, uint64_t key)
{
ABORT_NOT_IMPLEMENTED(mapc, remove_free);
return mapc->ops->remove_free(mapc->pop, map, key);
}
int
map_clear(struct map_ctx *mapc, TOID(struct map) map)
{
ABORT_NOT_IMPLEMENTED(mapc, clear);
return mapc->ops->clear(mapc->pop, map);
}
PMEMoid
map_get(struct map_ctx *mapc, TOID(struct map) map, uint64_t key)
{
ABORT_NOT_IMPLEMENTED(mapc, get);
return mapc->ops->get(mapc->pop, map, key);
}
int
map_lookup(struct map_ctx *mapc, TOID(struct map) map, uint64_t key)
{
ABORT_NOT_IMPLEMENTED(mapc, lookup);
return mapc->ops->lookup(mapc->pop, map, key);
}
int
map_foreach(struct map_ctx *mapc, TOID(struct map) map,
int (*cb)(uint64_t key, PMEMoid value, void *arg),
void *arg)
{
ABORT_NOT_IMPLEMENTED(mapc, foreach);
return mapc->ops->foreach(mapc->pop, map, cb, arg);
}
int
map_is_empty(struct map_ctx *mapc, TOID(struct map) map)
{
ABORT_NOT_IMPLEMENTED(mapc, is_empty);
return mapc->ops->is_empty(mapc->pop, map);
}
size_t
map_count(struct map_ctx *mapc, TOID(struct map) map)
{
ABORT_NOT_IMPLEMENTED(mapc, count);
return mapc->ops->count(mapc->pop, map);
}
int
map_cmd(struct map_ctx *mapc, TOID(struct map) map, unsigned cmd, uint64_t arg)
{
ABORT_NOT_IMPLEMENTED(mapc, cmd);
return mapc->ops->cmd(mapc->pop, map, cmd, arg);
}