Doxygen comments
[yaz-moved-to-github.git] / include / yaz / nmem.h
1 /*
2  * Copyright (c) 1995-2007, Index Data
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Index Data nor the names of its contributors
13  *       may be used to endorse or promote products derived from this
14  *       software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 /* $Id: nmem.h,v 1.26 2007-11-14 21:03:59 adam Exp $ */
28
29 /**
30  * \file
31  * \brief Header for Nibble Memory functions
32  *
33  * This is a simple and fairly wasteful little module for nibble memory
34  * allocation. Eventually we'll put in something better.
35  */
36 #ifndef NMEM_H
37 #define NMEM_H
38
39 #include <stddef.h>
40 #include <yaz/yconfig.h>
41
42 YAZ_BEGIN_CDECL
43
44 /** \brief NMEM handle (an opaque pointer to memory) */
45 typedef struct nmem_control *NMEM;
46
47 /** \brief releases memory associaged with an NMEM handle 
48     \param n NMEM handle
49 */
50 YAZ_EXPORT void nmem_reset(NMEM n);
51
52 /** \brief returns size in bytes of memory for NMEM handle
53     \returns number of bytes
54  */
55 YAZ_EXPORT int nmem_total(NMEM n);
56
57 /** \brief allocates string on NMEM handle (similar strdup) 
58     \param mem HNEM handle
59     \param src string
60     \returns duplicated string
61  */
62 YAZ_EXPORT char *nmem_strdup(NMEM mem, const char *src);
63 /** \brief allocates string on NMEM handle - allows NULL ptr buffer
64     \param mem HNEM handle
65     \param src string
66     \returns duplicated string or NULL if src was NULL
67  */
68 YAZ_EXPORT char *nmem_strdup_null(NMEM mem, const char *src);
69
70 /** \brief allocates string of certain size on NMEM handle
71     \param mem NMEM handle
72     \param src string
73     \param n size of string
74     \returns duplicated string (0 terminated)
75  */
76 YAZ_EXPORT char *nmem_strdupn(NMEM mem, const char *src, size_t n);
77
78 /** \brief allocates sub strings out of string using certain delimitors
79     \param nmem NMEM handle
80     \param delim delimitor chars (splits on each char in there) 
81     \param dstr string to be split
82     \param darray result string array for each sub string
83     \param num number of result strings
84 */
85 YAZ_EXPORT void nmem_strsplit(NMEM nmem, const char *delim,
86                               const char *dstr,
87                               char ***darray, int *num);
88
89 /** \brief splits string into sub strings delimited by blanks
90     \param nmem NMEM handle
91     \param dstr string to be split
92     \param darray result string array for each sub string
93     \param num number of result strings
94 */
95 YAZ_EXPORT void nmem_strsplit_blank(NMEM nmem, const char *dstr,
96                                     char ***darray, int *num);
97
98 /** \brief allocates integer for NMEM
99     \param nmem NMEM handle
100     \param v integer value
101     \returns pointer to created integer
102 */
103 YAZ_EXPORT int *nmem_intdup(NMEM nmem, int v);
104
105 /** \brief transfers memory from one NMEM handle to another
106     \param src source NMEM handle
107     \param dst destination NMEM handle
108  */
109 YAZ_EXPORT void nmem_transfer(NMEM dst, NMEM src);
110
111 /** \brief returns new NMEM handle 
112     \returns NMEM handle
113  */
114 YAZ_EXPORT NMEM nmem_create(void);
115
116 /** \brief destroys NMEM handle and memory associated with it
117     \param n NMEM handle
118  */
119 YAZ_EXPORT void nmem_destroy(NMEM n);
120
121 /** \brief allocates memory block on NMEM handle
122     \param n NMEM handle
123     \param size number of bytes to be allocated
124     \returns pointer to allocated memory
125  */
126 YAZ_EXPORT void *nmem_malloc(NMEM n, int size);
127
128 YAZ_EXPORT int yaz_errno(void);
129 YAZ_EXPORT void yaz_set_errno (int v);
130 YAZ_EXPORT void yaz_strerror(char *buf, int max);
131
132 YAZ_END_CDECL
133
134 #endif
135 /*
136  * Local variables:
137  * c-basic-offset: 4
138  * indent-tabs-mode: nil
139  * End:
140  * vim: shiftwidth=4 tabstop=8 expandtab
141  */
142