Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / api / c / api_storage.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
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: api_storage.h /main/3 1995/10/23 09:55:04 rswiston $                                                         */
28 /* -*-C++-*-
29  *
30  * api_storage.h
31  *
32  * Copyright (c) 1990 by Sun Microsystems, Inc.
33  * 
34  * mark/release storage management for storage returned over api
35  */
36 #if !defined(_API_STORAGE_H)
37 #define _API_STORAGE_H
38
39 #include <stdlib.h>
40 #include <malloc.h>
41 #include "util/tt_object.h"
42 #include "util/tt_list.h"
43
44 declare_list_of(_Tt_api_stg_stack_elm)
45 declare_ptr_to(_Tt_api_stg_stack)
46
47 class _Tt_api_stg_stack_elm : public _Tt_object {
48       public:
49         _Tt_api_stg_stack_elm() {};
50         ~_Tt_api_stg_stack_elm();
51         enum {STACK_MARK, STACK_STORAGE}        entry_type;
52         caddr_t                                 addr;
53         void            print(FILE *fs = stdout) const;
54 };
55
56 class _Tt_api_stg_stack : public _Tt_object {
57       public:
58         _Tt_api_stg_stack();
59         virtual ~_Tt_api_stg_stack();
60         int                     mark();
61         void                    release(int mark);
62 #ifdef  _DEBUG_MALLOC_INC
63         caddr_t                 debug_malloc(char *fname,int lnum,size_t size);
64 #else
65         caddr_t                 malloc(size_t size);
66 #endif
67         // take(p,s) is for taking a normally ::malloc'ed chunk of
68         // storage and putting it under mark/release control.
69         caddr_t                 take(caddr_t addr);
70 #ifdef  _DEBUG_MALLOC_INC
71         void                    debug_free(char *fname,int lnum,caddr_t addr);
72 #else
73         void                    free(caddr_t addr);
74 #endif
75         void            print(FILE *fs = stdout) const;
76       private:
77         _Tt_api_stg_stack_elm_list_ptr stack;
78         int                     mark_counter;
79 };
80
81 #endif