home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / dreamscape / source / Dreamscape / Headers / utils / h / defdelete < prev    next >
Encoding:
Text File  |  1996-09-22  |  1.4 KB  |  62 lines

  1.  
  2. // utils.h.defdelete
  3.  
  4. // Dreamscape - C++ class library for RISC OS
  5. // Copyright (c) 1996 Mark Seaborn <mseaborn@argonet.co.uk>
  6. //
  7. // This library is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU Library General Public
  9. // License as published by the Free Software Foundation; either
  10. // version 2 of the License, or (at your option) any later version.
  11. // See the Dreamscape documentation for more information.
  12.  
  13. #ifndef dreamscape_defdelete_H
  14. #define dreamscape_defdelete_H
  15.  
  16. #include "nullevent.h"
  17.  
  18. template <class Type>
  19. class DeferredDeleteInternal: public Command {
  20.   Type *object;
  21. public:
  22.   DeferredDeleteInternal(Type *o): object(o) {}
  23.   void execute()
  24.     { delete object;
  25.       delete this; }
  26. };
  27.  
  28. template <class Type>
  29. class DeferredDeleteAInternal: public Command {
  30.   Type *objects;
  31.  
  32. public:
  33.   DeferredDeleteAInternal(Type *o): object(o) {}
  34.   void execute()
  35.     { delete [] objects;
  36.       delete this; }
  37. };
  38.  
  39. template <class Type>
  40. inline void deferred_delete(Type *object)
  41. {
  42.   NullEventHandler::add_call_once_handler(new
  43.     DeferredDeleteInternal<Type>(object));
  44. }
  45.  
  46. template <class Type>
  47. inline void deferred_delete_a(Type *objects)
  48. {
  49.   NullEventHandler::add_call_once_handler(new
  50.     DeferredDeleteAInternal<Type>(objects));
  51. }
  52.  
  53. template <class Type>
  54. class DeferredDeleteObjectCommand: public Command {
  55.   Type *object;
  56. public:
  57.   DeferredDeleteObjectCommand(Type *o): object(o) {}
  58.   void execute() { deferred_delete(object); }
  59. };
  60.  
  61. #endif
  62.