ScopeDestroyer.h 658 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_UTIL_SCOPE_DESTROYER_H
  6. #define ANKI_UTIL_SCOPE_DESTROYER_H
  7. namespace anki {
  8. /// @addtogroup util_containers
  9. /// @{
  10. /// A class that destroys other instances when it get out of scope.
  11. template<typename TInstance, typename TAlloc>
  12. class ScopeDestroyer
  13. {
  14. public:
  15. TInstance* m_inst;
  16. TAlloc m_alloc;
  17. ScopeDestroyer(TInstance* inst, TAlloc alloc)
  18. : m_inst(inst),
  19. m_alloc(alloc)
  20. {}
  21. ~ScopeDestroyer()
  22. {
  23. m_inst->destroy(m_alloc);
  24. }
  25. };
  26. /// @}
  27. } // end namespace anki
  28. #endif