3 * $Id: dspool.h,v 1.1 1999/05/21 22:15:26 mdw Exp $
5 * Provide pools of strings
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the mLib utilities library.
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 1999/05/21 22:15:26 mdw
33 * Dynamic string pool system, based on an idea from the `sw-tools'
34 * project. Could do with more work to make it really good.
45 /*----- Header files ------------------------------------------------------*/
50 /*----- Data structures ---------------------------------------------------*/
52 typedef struct dspoolstr
{
54 struct dspoolstr
*next
;
57 typedef struct dspool
{
62 /*----- Functions provided ------------------------------------------------*/
64 /* --- @dspool_create@ --- *
66 * Arguments: @dspool *p@ = address of pool to create
67 * @size_t isz@ = initial size of new strings
71 * Use: Initializes a dynamic string pool.
74 extern void dspool_create(dspool */
*p*/
, size_t /*isz*/);
76 /* --- @dspool_destroy@ --- *
78 * Arguments: @dspool *p@ = pool to destroy
82 * Use: Releases all of the strings left in the pool. Any strings
83 * not put back into the pool aren't freed. However, the pool
84 * is still valid, and the active strings can be put back and
88 extern void dspool_destroy(dspool */
*p*/
);
90 /* --- @dspool_get@ --- *
92 * Arguments: @dspool *p@ = pointer to a string pool
94 * Returns: Pointer to a dynamic string.
96 * Use: Fetches a string from the pool. The string has space for at
97 * least @isz@ characters (where @isz@ is the size passed to
98 * @dspool_create@ for the pool).
101 extern dstr
*dspool_get(dspool */
*p*/
);
103 #define DSGET(p, d) do { \
108 _p->free = _s->next; \
110 _s = CREATE(dspoolstr); \
113 DENSURE(&_s->ds, _p->isz); \
118 /* --- @dspool_put@ --- *
120 * Arguments: @dspool *p@ = pointer to a string pool
121 * @dstr *d@ = pointer to a dynamic string from a string pool
125 * Use: Releases a dynamic string back into a string pool. It
126 * doesn't have to be the same pool the string actually came
127 * from, although it does have to have come from some string
131 extern void dspool_put(dspool */
*p*/
, dstr */
*d*/
);
133 #define DSPUT(p, d) do { \
135 dspoolstr *_s = (dspoolstr *)(d); \
137 _s->next = _p->free; \
141 /*----- That's all, folks -------------------------------------------------*/