OLD | NEW |
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_SYSTEM_MEMORY_H_ | 5 #ifndef MOJO_SYSTEM_MEMORY_H_ |
6 #define MOJO_SYSTEM_MEMORY_H_ | 6 #define MOJO_SYSTEM_MEMORY_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> // For |memcpy()|. | 10 #include <string.h> // For |memcpy()|. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 template <typename Type> | 84 template <typename Type> |
85 class UserPointer { | 85 class UserPointer { |
86 private: | 86 private: |
87 typedef typename internal::VoidToChar<Type>::type NonVoidType; | 87 typedef typename internal::VoidToChar<Type>::type NonVoidType; |
88 | 88 |
89 public: | 89 public: |
90 // Instead of explicitly using these constructors, you can often use | 90 // Instead of explicitly using these constructors, you can often use |
91 // |MakeUserPointer()| (or |NullUserPointer()| for null pointers). (The common | 91 // |MakeUserPointer()| (or |NullUserPointer()| for null pointers). (The common |
92 // exception is when you have, e.g., a |char*| and want to get a | 92 // exception is when you have, e.g., a |char*| and want to get a |
93 // |UserPointer<void>|.) | 93 // |UserPointer<void>|.) |
94 UserPointer() : pointer_(NULL) {} | 94 UserPointer() : pointer_(nullptr) {} |
95 explicit UserPointer(Type* pointer) : pointer_(pointer) {} | 95 explicit UserPointer(Type* pointer) : pointer_(pointer) {} |
96 // Allow implicit conversion from the "null user pointer". | 96 // Allow implicit conversion from the "null user pointer". |
97 UserPointer(NullUserPointer) : pointer_(NULL) {} | 97 UserPointer(NullUserPointer) : pointer_(nullptr) {} |
98 ~UserPointer() {} | 98 ~UserPointer() {} |
99 | 99 |
100 // Allow assignment from the "null user pointer". | 100 // Allow assignment from the "null user pointer". |
101 UserPointer<Type>& operator=(NullUserPointer) { | 101 UserPointer<Type>& operator=(NullUserPointer) { |
102 pointer_ = NULL; | 102 pointer_ = nullptr; |
103 return *this; | 103 return *this; |
104 } | 104 } |
105 | 105 |
106 // Allow conversion to a "non-const" |UserPointer|. | 106 // Allow conversion to a "non-const" |UserPointer|. |
107 operator UserPointer<const Type>() const { | 107 operator UserPointer<const Type>() const { |
108 return UserPointer<const Type>(pointer_); | 108 return UserPointer<const Type>(pointer_); |
109 } | 109 } |
110 | 110 |
111 bool IsNull() const { return !pointer_; } | 111 bool IsNull() const { return !pointer_; } |
112 | 112 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 size_t count_; | 368 size_t count_; |
369 scoped_ptr<Type[]> buffer_; | 369 scoped_ptr<Type[]> buffer_; |
370 | 370 |
371 DISALLOW_COPY_AND_ASSIGN(UserPointerReaderWriter); | 371 DISALLOW_COPY_AND_ASSIGN(UserPointerReaderWriter); |
372 }; | 372 }; |
373 | 373 |
374 } // namespace system | 374 } // namespace system |
375 } // namespace mojo | 375 } // namespace mojo |
376 | 376 |
377 #endif // MOJO_SYSTEM_MEMORY_H_ | 377 #endif // MOJO_SYSTEM_MEMORY_H_ |
OLD | NEW |