checkeddelete.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/checkeddelete.h
  3. // Purpose: wxCHECKED_DELETE() macro
  4. // Author: Vadim Zeitlin
  5. // Created: 2009-02-03
  6. // Copyright: (c) 2002-2009 wxWidgets dev team
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_CHECKEDDELETE_H_
  10. #define _WX_CHECKEDDELETE_H_
  11. #include "wx/cpp.h"
  12. // TODO: provide wxCheckedDelete[Array]() template functions too
  13. // ----------------------------------------------------------------------------
  14. // wxCHECKED_DELETE and wxCHECKED_DELETE_ARRAY macros
  15. // ----------------------------------------------------------------------------
  16. /*
  17. checked deleters are used to make sure that the type being deleted is really
  18. a complete type.: otherwise sizeof() would result in a compile-time error
  19. do { ... } while ( 0 ) construct is used to have an anonymous scope
  20. (otherwise we could have name clashes between different "complete"s) but
  21. still force a semicolon after the macro
  22. */
  23. #define wxCHECKED_DELETE(ptr) \
  24. wxSTATEMENT_MACRO_BEGIN \
  25. typedef char complete[sizeof(*ptr)] WX_ATTRIBUTE_UNUSED; \
  26. delete ptr; \
  27. wxSTATEMENT_MACRO_END
  28. #define wxCHECKED_DELETE_ARRAY(ptr) \
  29. wxSTATEMENT_MACRO_BEGIN \
  30. typedef char complete[sizeof(*ptr)] WX_ATTRIBUTE_UNUSED; \
  31. delete [] ptr; \
  32. wxSTATEMENT_MACRO_END
  33. #endif // _WX_CHECKEDDELETE_H_