OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SERVICES_MEDIA_FRAMEWORK_SAFE_CLONE_H_ |
| 6 #define SERVICES_MEDIA_FRAMEWORK_SAFE_CLONE_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <vector> |
| 10 |
| 11 namespace mojo { |
| 12 namespace media { |
| 13 |
| 14 template<typename T> |
| 15 std::unique_ptr<T> SafeClone(const std::unique_ptr<T>& t_ptr) { |
| 16 return t_ptr ? t_ptr.get()->Clone() : nullptr; |
| 17 } |
| 18 |
| 19 template<typename T> |
| 20 std::unique_ptr<std::vector<std::unique_ptr<T>>> SafeClone( |
| 21 const std::unique_ptr<std::vector<std::unique_ptr<T>>>& vec) { |
| 22 if (vec == nullptr) { |
| 23 return nullptr; |
| 24 } |
| 25 |
| 26 std::unique_ptr<std::vector<std::unique_ptr<T>>> result = |
| 27 std::unique_ptr<std::vector<std::unique_ptr<T>>>( |
| 28 new std::vector<std::unique_ptr<T>>(vec->size())); |
| 29 |
| 30 for (const std::unique_ptr<T>& t_ptr : *vec.get()) { |
| 31 result->push_back(SafeClone(t_ptr)); |
| 32 } |
| 33 |
| 34 return result; |
| 35 } |
| 36 |
| 37 } // namespace media |
| 38 } // namespace mojo |
| 39 |
| 40 #endif // SERVICES_MEDIA_FRAMEWORK_SAFE_CLONE_H_ |
OLD | NEW |