Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: mojo/public/cpp/bindings/array.h

Issue 828373008: Allow constructing {Interface,Struct}Ptr from nullptr (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_
7 7
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "mojo/public/cpp/bindings/lib/array_internal.h" 14 #include "mojo/public/cpp/bindings/lib/array_internal.h"
15 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" 15 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
16 #include "mojo/public/cpp/bindings/lib/template_util.h" 16 #include "mojo/public/cpp/bindings/lib/template_util.h"
17 #include "mojo/public/cpp/bindings/type_converter.h" 17 #include "mojo/public/cpp/bindings/type_converter.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 20
21 template <typename T> 21 template <typename T>
22 class Array { 22 class Array {
23 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(Array, RValue) 23 MOJO_MOVE_ONLY_TYPE(Array)
24 public: 24 public:
25 typedef internal::ArrayTraits<T, internal::IsMoveOnlyType<T>::value> Traits; 25 typedef internal::ArrayTraits<T, internal::IsMoveOnlyType<T>::value> Traits;
26 typedef typename Traits::ConstRefType ConstRefType; 26 typedef typename Traits::ConstRefType ConstRefType;
27 typedef typename Traits::RefType RefType; 27 typedef typename Traits::RefType RefType;
28 typedef typename Traits::StorageType StorageType; 28 typedef typename Traits::StorageType StorageType;
29 typedef typename Traits::ForwardType ForwardType; 29 typedef typename Traits::ForwardType ForwardType;
30 30
31 typedef internal::Array_Data<typename internal::WrapperTraits<T>::DataType> 31 typedef internal::Array_Data<typename internal::WrapperTraits<T>::DataType>
32 Data_; 32 Data_;
33 33
34 Array() : is_null_(true) {} 34 Array() : is_null_(true) {}
35 explicit Array(size_t size) : vec_(size), is_null_(false) { 35 explicit Array(size_t size) : vec_(size), is_null_(false) {
36 Traits::Initialize(&vec_); 36 Traits::Initialize(&vec_);
37 } 37 }
38 ~Array() { Traits::Finalize(&vec_); } 38 ~Array() { Traits::Finalize(&vec_); }
39 39
40 Array(RValue other) : is_null_(true) { Take(other.object); } 40 Array(Array&& other) : is_null_(true) { Take(&other); }
41 Array& operator=(RValue other) { 41 Array& operator=(Array&& other) {
42 Take(other.object); 42 Take(&other);
43 return *this; 43 return *this;
44 } 44 }
45 45
46 static Array New(size_t size) { return Array(size).Pass(); } 46 static Array New(size_t size) { return Array(size).Pass(); }
47 47
48 template <typename U> 48 template <typename U>
49 static Array From(const U& other) { 49 static Array From(const U& other) {
50 return TypeConverter<Array, U>::Convert(other); 50 return TypeConverter<Array, U>::Convert(other);
51 } 51 }
52 52
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 for (size_t i = 0; i < input.size(); ++i) 155 for (size_t i = 0; i < input.size(); ++i)
156 result[i] = TypeConverter<E, T>::Convert(input[i]); 156 result[i] = TypeConverter<E, T>::Convert(input[i]);
157 } 157 }
158 return result; 158 return result;
159 } 159 }
160 }; 160 };
161 161
162 } // namespace mojo 162 } // namespace mojo
163 163
164 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ 164 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/interface_ptr.h » ('j') | mojo/public/cpp/bindings/struct_ptr.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698