home *** CD-ROM | disk | FTP | other *** search
-
- // utils.h.defdelete
-
- // Dreamscape - C++ class library for RISC OS
- // Copyright (c) 1996 Mark Seaborn <mseaborn@argonet.co.uk>
- //
- // This library is free software; you can redistribute it and/or
- // modify it under the terms of the GNU Library General Public
- // License as published by the Free Software Foundation; either
- // version 2 of the License, or (at your option) any later version.
- // See the Dreamscape documentation for more information.
-
- #ifndef dreamscape_defdelete_H
- #define dreamscape_defdelete_H
-
- #include "nullevent.h"
-
- template <class Type>
- class DeferredDeleteInternal: public Command {
- Type *object;
- public:
- DeferredDeleteInternal(Type *o): object(o) {}
- void execute()
- { delete object;
- delete this; }
- };
-
- template <class Type>
- class DeferredDeleteAInternal: public Command {
- Type *objects;
-
- public:
- DeferredDeleteAInternal(Type *o): object(o) {}
- void execute()
- { delete [] objects;
- delete this; }
- };
-
- template <class Type>
- inline void deferred_delete(Type *object)
- {
- NullEventHandler::add_call_once_handler(new
- DeferredDeleteInternal<Type>(object));
- }
-
- template <class Type>
- inline void deferred_delete_a(Type *objects)
- {
- NullEventHandler::add_call_once_handler(new
- DeferredDeleteAInternal<Type>(objects));
- }
-
- template <class Type>
- class DeferredDeleteObjectCommand: public Command {
- Type *object;
- public:
- DeferredDeleteObjectCommand(Type *o): object(o) {}
- void execute() { deferred_delete(object); }
- };
-
- #endif
-