remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / cinelerra / garbage.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef GARBAGE_H
23 #define GARBAGE_H
24
25
26 #include "arraylist.h"
27 #include "garbage.inc"
28 #include "mutex.inc"
29
30 // Garbage collection
31 // The objects inherit from GarbageObject.
32 // The constructor sets users to 1 so the caller must call
33 // Garbage::remove_user when it's done.
34 // Other users of the object must call add_user to increment the user count
35 // and Garbage::remove_user to decriment the user count.
36 // The object is only deleted if a call to Garbage::delete_object is made and
37 // the user count is 0.  returns 0 when no more users, 1 if still in use.
38
39 // Can't make graphics elements inherit because they must be deleted
40 // when the window is locked and they change their parent pointers.
41
42 // Elements of link lists must first be unlinked with remove_pointer and then
43 // passed to delete_object.
44
45 // ArrayList objects must be deleted one at a time with delete_object.
46 // Then the pointers must be deleted with remove_all.
47 //
48 // NOTE: Garbage must be first base class or this!=0 test is broken
49
50 class Garbage
51 {
52 public:
53         Garbage(const char *title);
54         virtual ~Garbage();
55
56 // Called when user begins to use the object.
57         void add_user();
58         int remove_user();
59
60         int users;
61         int deleted;
62         char *title;
63         Mutex *lock;
64 };
65
66
67
68 // class Garbage
69 // {
70 // public:
71 //      Garbage();
72 //      ~Garbage();
73 //
74 // // Called by GarbageObject constructor
75 // //   void add_object(GarbageObject *ptr);
76 //
77 // // Called by user to delete the object.
78 // // Flags the object for deletion as soon as it has no users.
79 //      static void delete_object(GarbageObject *ptr);
80 //
81 //
82 // // Called by remove_user and delete_object
83 // //   static void remove_expired();
84 //      Mutex *lock;
85 // //   ArrayList<GarbageObject*> objects;
86 //
87 // // Global garbage collector
88 //      static Garbage *garbage;
89 // };
90
91
92
93 #endif