2014-08-25 17:51:09 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#ifndef CRASHPAD_UTIL_STDLIB_POINTER_CONTAINER_H_
|
|
|
|
|
#define CRASHPAD_UTIL_STDLIB_POINTER_CONTAINER_H_
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2016-01-06 12:22:50 -05:00
|
|
|
|
#include "base/macros.h"
|
2014-08-25 17:51:09 -04:00
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
2017-02-07 16:04:41 -05:00
|
|
|
|
//! \brief Allows a `std::vector` to “own” pointer elements stored in it.
|
2014-10-29 11:33:34 -04:00
|
|
|
|
//!
|
2017-02-07 16:04:41 -05:00
|
|
|
|
//! When the vector is destroyed, `delete` will be called on its pointer
|
2014-10-29 11:33:34 -04:00
|
|
|
|
//! elements.
|
|
|
|
|
//!
|
|
|
|
|
//! \note No attempt is made to `delete` elements that are removed from the
|
2017-02-07 16:04:41 -05:00
|
|
|
|
//! vector by other means, such as replacement or `clear()`.
|
|
|
|
|
template <typename T>
|
|
|
|
|
class PointerVector : public std::vector<T*> {
|
2014-08-25 17:51:09 -04:00
|
|
|
|
public:
|
2017-02-07 16:04:41 -05:00
|
|
|
|
PointerVector() : std::vector<T*>() {}
|
2014-08-25 17:51:09 -04:00
|
|
|
|
|
2017-02-07 16:04:41 -05:00
|
|
|
|
~PointerVector() {
|
|
|
|
|
for (T* item : *this)
|
|
|
|
|
delete item;
|
|
|
|
|
}
|
2014-08-25 17:51:09 -04:00
|
|
|
|
|
|
|
|
|
private:
|
2017-02-07 16:04:41 -05:00
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(PointerVector);
|
2014-08-25 17:51:09 -04:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
|
|
#endif // CRASHPAD_UTIL_STDLIB_POINTER_CONTAINER_H_
|