![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * Garbage collector object * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 *********************************************************************************/ 00022 #ifndef FXGARBAGECOLLECTOR_H 00023 #define FXGARBAGECOLLECTOR_H 00024 00025 namespace FXEX { 00026 00027 /** 00028 * Garbage Collector 00029 * 00030 * Assign your dynamically created objects to this object. It will delete them when 00031 * it goes out of scope. 00032 * 00033 * Idea taken from CGarbage from the DlgEdit program from Martin Welch 00034 */ 00035 class FXAPI FXGarbageCollector { 00036 00037 private: 00038 FXArray<FXObject*> objects; 00039 FXArray<FXStream*> streams; 00040 FXArray<FXException*> exceptions; 00041 00042 public: 00043 /// give me a garbage collector 00044 FXGarbageCollector() {} 00045 00046 /// Number of objects in garbage collector 00047 FXint no() { return objects.no() + streams.no() + exceptions.no(); } 00048 00049 /// assignment or addition just adds the object to the garbage collector 00050 void operator= (FXObject *o) { objects.append(o); } 00051 void operator= (FXStream *s) { streams.append(s); } 00052 void operator= (FXException *e) { exceptions.append(e); } 00053 00054 /// assignment or addition just adds the object to the garbage collector 00055 void operator+= (FXObject *o) { objects.append(o); } 00056 void operator+= (FXStream *s) { streams.append(s); } 00057 void operator+= (FXException *e) { exceptions.append(e); } 00058 00059 /// we just add the object to the garbage collector 00060 void add(FXObject *o) { objects.append(o); } 00061 void add(FXStream *s) { streams.append(s); } 00062 void add(FXException *e) { exceptions.append(e); } 00063 00064 /// when we destruct, we garbage collect 00065 ~FXGarbageCollector(); 00066 }; 00067 00068 } // namespace FXEX 00069 #endif // FXGARBAGECOLLECTOR_H 00070