dict.h 4.04 KB
Newer Older
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
/*
	belle-sip - SIP (RFC3261) library.
	Copyright (C) 2010  Belledonne Communications SARL

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DICT_H
#define DICT_H

#include <sys/types.h>

#include "object.h"

26
BELLE_SIP_BEGIN_DECLS
27 28 29 30 31 32 33 34 35 36

typedef struct belle_sip_dict belle_sip_dict_t;
#define BELLE_SIP_DICT(obj) BELLE_SIP_CAST(obj,belle_sip_dict_t)

/**
 * @brief belle_sip_dict_create
 * @return an instance of a belle_sip_dict_t object.
 * @note The object is not owned by default.
 * @note all belle_sip_dict_set_* functions will overwrite existing values.
 */
37
BELLESIP_EXPORT belle_sip_dict_t* belle_sip_dict_create();
38 39 40 41 42 43 44

/**
 * @brief belle_sip_dict_set_int stores an integer into the dictionary
 * @param obj the dictionary instance
 * @param key the name of the integer to store
 * @param value value to store
 */
45
BELLESIP_EXPORT void belle_sip_dict_set_int(belle_sip_dict_t* obj, const char* key, int value);
46 47 48 49 50 51 52 53

/**
 * @brief belle_sip_dict_get_int retrieves an integer from the dictionary
 * @param obj the dictionary instance
 * @param key name of the integer to retrieve
 * @param default_value value to return if the key is not found
 * @return the searched integer if the key exists, default_value if not found
 */
54
BELLESIP_EXPORT int belle_sip_dict_get_int(belle_sip_dict_t* obj, const char* key, int default_value);
55 56 57 58 59 60 61

/**
 * @brief belle_sip_dict_set_string stores a string into the dictionary
 * @param obj the dictionary instance
 * @param key the name of the string to store
 * @param value value to store
 */
62
BELLESIP_EXPORT void belle_sip_dict_set_string(belle_sip_dict_t* obj, const char* key, const char*value);
63 64 65 66 67 68 69
/**
 * @brief belle_sip_dict_get_string retrieves a string from the dictionary
 * @param obj the dictionary instance
 * @param key the name of the string to retrieve
 * @param default_value
 * @return the searched string if the key exists, default_value if not found
 */
70
BELLESIP_EXPORT const char* belle_sip_dict_get_string(belle_sip_dict_t* obj, const char* key, const char* default_value);
71 72 73 74 75 76 77

/**
 * @brief belle_sip_dict_set_int64 stores an int64 in the dictionary
 * @param obj the dictionary instance
 * @param key the name of the integer to store
 * @param value value to store
 */
78
BELLESIP_EXPORT void belle_sip_dict_set_int64(belle_sip_dict_t* obj, const char* key, int64_t value);
79 80 81 82 83 84 85 86

/**
 * @brief belle_sip_dict_get_int64 retrieves an int64 from the dictionary
 * @param obj the dictionary instance
 * @param key the name of the integer to retrieve
 * @param default_value value to return if the key is not found
 * @return the searched int64 if the key exists, default_value if not found
 */
87
BELLESIP_EXPORT int64_t belle_sip_dict_get_int64(belle_sip_dict_t* obj, const char* key, int64_t default_value);
88 89 90 91 92 93 94

/**
 * @brief belle_sip_dict_remove will erase the value for a key
 * @param obj the dictionary instance
 * @param key the name of the integer to remove
 * @return 0 if the key was found, 1 otherwise
 */
95
BELLESIP_EXPORT int belle_sip_dict_remove(belle_sip_dict_t* obj, const char* key);
96 97 98 99 100

/**
 * @brief belle_sip_dict_clear will clear the object's dictionary.
 * @param obj the dictionary instance
 */
101
BELLESIP_EXPORT void belle_sip_dict_clear(belle_sip_dict_t* obj);
102 103 104 105 106 107 108 109

/**
 * @brief belle_sip_dict_haskey tells if a key exists in the dictionary.
 * @param obj the dictionary instance
 * @param key the key to look for
 * @return 1 if the key exists, 0 otherwise
 * @todo create unit test
 */
110 111 112
BELLESIP_EXPORT int belle_sip_dict_haskey(belle_sip_dict_t* obj, const char* key);

BELLE_SIP_END_DECLS
113 114

#endif // DICT_H