txOwningArray.h 973 B

123456789101112131415161718192021222324252627282930313233
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:set ts=2 sw=2 sts=2 et cindent: */
  3. /* This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #ifndef txOwningArray_h__
  7. #define txOwningArray_h__
  8. // Class acting like a nsTArray except that it deletes its objects
  9. // on destruction. It does not however delete its objects on operations
  10. // like RemoveElementsAt or on |array[i] = bar|.
  11. template<class E>
  12. class txOwningArray : public nsTArray<E*>
  13. {
  14. public:
  15. typedef nsTArray<E*> base_type;
  16. typedef typename base_type::elem_type elem_type;
  17. ~txOwningArray()
  18. {
  19. elem_type* iter = base_type::Elements();
  20. elem_type* end = iter + base_type::Length();
  21. for (; iter < end; ++iter) {
  22. delete *iter;
  23. }
  24. }
  25. };
  26. #endif // txOwningArray_h__