xref: /Universal-ctags/main/trashbox.h (revision b19b9175e2f7092f37ad64a02fe56b47d042b07b)
1 /*
2 *
3 *   Copyright (c) 2017, Red Hat, Inc.
4 *   Copyright (c) 2017, Masatake YAMATO
5 *
6 *   This source code is released for free distribution under the terms of the
7 *   GNU General Public License version 2 or (at your option) any later version.
8 *
9 *   Facility for delayed memory releasing, inspired from AutoreleasePool
10 *   of OpenStep.
11 */
12 
13 #ifndef CTAGS_MAIN_TRASH_H
14 #define CTAGS_MAIN_TRASH_H
15 
16 /*
17 *   INCLUDE FILES
18 */
19 
20 #include "general.h"  /* must always come first */
21 
22 
23 /*
24 *   DATA DECLARATIONS
25 */
26 
27 typedef void (* TrashBoxDestroyItemProc) (void *);
28 typedef struct sTrashBox TrashBox;
29 
30 /*
31 *   MACROS
32 */
33 
34 #define DEFAULT_TRASH_BOX(PTR,PROC) trashBoxPut(NULL,PTR,(TrashBoxDestroyItemProc)PROC)
35 #define DEFAULT_TRASH_BOX_TAKE_BACK(PTR) trashBoxTakeBack(NULL,PTR)
36 
37 #define PARSER_TRASH_BOX(PTR,PROC) parserTrashBoxPut(PTR,(TrashBoxDestroyItemProc)PROC)
38 #define PARSER_TRASH_BOX_TAKE_BACK(PTR) parserTrashBoxTakeBack(PTR)
39 
40 
41 /*
42 *   FUNCTION PROTOTYPES
43 */
44 
45 extern TrashBox* trashBoxNew       (void);
46 extern TrashBox* trashBoxStack     (TrashBox* trash_box);
47 extern void      trashBoxDelete    (TrashBox* trash_box);
48 extern void*     trashBoxPut       (TrashBox* trash_box, void* item, TrashBoxDestroyItemProc destroy);
49 extern TrashBoxDestroyItemProc trashBoxTakeBack  (TrashBox* trash_box, void* item);
50 extern void      trashBoxFree      (TrashBox* trash_box, void* item);
51 extern void      trashBoxMakeEmpty (TrashBox* trash_box);
52 
53 /* A parser trash box is prepared when `parser' method of a parser is called.
54  * The parser can register a pair of a memory object and destructor for the object to
55  * the trash box with parserTrashBoxPut ().
56  *
57  * The registered memory objects are destructed after `parser' method is finished in
58  * the main side. You can delay the destruction with parserTrashBoxPut ().
59  *
60  * You can unregister the pair in the `parser' method with parserTrashBoxTakeBack ().
61  * In that case, specify the memory object of the pair as the argument.
62  */
63 extern void* parserTrashBoxPut  (void* item, TrashBoxDestroyItemProc destroy);
64 extern TrashBoxDestroyItemProc parserTrashBoxTakeBack  (void* item);
65 
66 #endif /* CTAGS_MAIN_TRASH_H */
67