2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
24 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
25 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
26 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
27 /*%% $XConsortium: tttk2free.h /main/3 1995/10/23 10:33:17 rswiston $ */
29 * @(#)tttk2free.h 1.3 93/09/07
31 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
36 #include "api/c/tt_c.h"
37 #include "util/tt_new.h"
38 #include "tttk/tttk.h"
41 // An instance of this class will automatically destroy() a message or
42 // tt_free() a pointer when the instance goes out of scope. This lets
43 // you avoid having to repetitively code the destroy() or free() right
44 // before every possible return from the scope. Typical usage:
46 // TtDtItem2Free item;
47 // Tt_message msg = tt_message_create();
50 // if (error) return error; // msg is automatically destroyed here
52 // item = 0; // now, msg won't be destroyed on return
55 // This class actually uses ttDtDestroy() instead of tt_message_destroy().
57 class _TttkItem2Free : public _Tt_allocated {
71 Tt_message operator =(
74 Tt_pattern operator =(
95 // This class is an array of _TttkItem2Free's. Its main benefit is
96 // that the ::flush() method lets you defuse all the items at once
97 // (typically, right before returning successfully from a scope).
99 // A malloc() is only done at constructor-time, so that you need not
100 // check if the +=() method failed due to malloc() failure. Thus,
101 // you have to know the max size of your list at constructor-time.
102 // Overflow items are ignored, and are thus potential memory leaks.
104 class _TttkList2Free : public _Tt_allocated {
107 unsigned int maxElems
111 Tt_message operator +=(
112 Tt_message msg2Destroy
114 Tt_pattern operator +=(
115 Tt_pattern pat2Destroy
123 _TttkItem2Free &_item(
130 _TttkItem2Free *_items;
132 _TttkItem2Free **_items;