Path: blob/master/dependencies/all/iniparser/dictionary.h
774 views
/*-------------------------------------------------------------------------*/1/**2@file dictionary.h3@author N. Devillard4@brief Implements a dictionary for string variables.56This module implements a simple dictionary object, i.e. a list7of string/string associations. This object is useful to store e.g.8informations retrieved from a configuration file (ini files).9*/10/*--------------------------------------------------------------------------*/1112#ifndef _DICTIONARY_H_13#define _DICTIONARY_H_1415/*---------------------------------------------------------------------------16Includes17---------------------------------------------------------------------------*/1819#include <stdio.h>20#include <stdlib.h>21#include <string.h>22#if !_WIN3223#include <unistd.h>24#endif2526#ifdef __cplusplus27extern "C" {28#endif2930/*---------------------------------------------------------------------------31New types32---------------------------------------------------------------------------*/333435/*-------------------------------------------------------------------------*/36/**37@brief Dictionary object3839This object contains a list of string/string associations. Each40association is identified by a unique string key. Looking up values41in the dictionary is speeded up by the use of a (hopefully collision-free)42hash function.43*/44/*-------------------------------------------------------------------------*/45typedef struct _dictionary_ {46int n ; /** Number of entries in dictionary */47size_t size ; /** Storage size */48char ** val ; /** List of string values */49char ** key ; /** List of string keys */50unsigned * hash ; /** List of hash values for keys */51} dictionary ;525354/*---------------------------------------------------------------------------55Function prototypes56---------------------------------------------------------------------------*/575859unsigned dictionary_hash(const char * key);606162dictionary * dictionary_new(size_t size);636465void dictionary_del(dictionary * vd);666768const char * dictionary_get(const dictionary * d, const char * key, const char * def);69707172int dictionary_set(dictionary * vd, const char * key, const char * val);737475void dictionary_unset(dictionary * d, const char * key);767778void dictionary_dump(const dictionary * d, FILE * out);7980#ifdef __cplusplus81}82#endif8384#endif8586