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::vector<std::unique_ptr<T>>* result = | |
johngro
2016/02/08 22:33:36
why not just wrap result in a std::unique_ptr to b
dalesat
2016/02/09 00:34:11
This seemed simpler, but I don't really care one w
| |
27 new std::vector<std::unique_ptr<T>>(vec->size()); | |
28 for (const std::unique_ptr<T>& t_ptr : *vec.get()) { | |
29 result->push_back(SafeClone(t_ptr)); | |
30 } | |
31 | |
32 return std::unique_ptr<std::vector<std::unique_ptr<T>>>(result); | |
33 } | |
34 | |
35 } // namespace media | |
36 } // namespace mojo | |
37 | |
38 #endif // SERVICES_MEDIA_FRAMEWORK_SAFE_CLONE_H_ | |
OLD | NEW |