OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 REMOTING_BASE_TYPED_BUFFER_H_ | 5 #ifndef REMOTING_BASE_TYPED_BUFFER_H_ |
6 #define REMOTING_BASE_TYPED_BUFFER_H_ | 6 #define REMOTING_BASE_TYPED_BUFFER_H_ |
7 | 7 |
8 #include <assert.h> | 8 #include <assert.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/move.h" |
15 | 15 |
16 namespace remoting { | 16 namespace remoting { |
17 | 17 |
18 // A scoper for a variable-length structure such as SID, SECURITY_DESCRIPTOR and | 18 // A scoper for a variable-length structure such as SID, SECURITY_DESCRIPTOR and |
19 // similar. These structures typically consist of a header followed by variable- | 19 // similar. These structures typically consist of a header followed by variable- |
20 // length data, so the size may not match sizeof(T). The class supports | 20 // length data, so the size may not match sizeof(T). The class supports |
21 // move-only semantics and typed buffer getters. | 21 // move-only semantics and typed buffer getters. |
22 template <typename T> | 22 template <typename T> |
23 class TypedBuffer { | 23 class TypedBuffer { |
| 24 MOVE_ONLY_TYPE_FOR_CPP_03(TypedBuffer) |
| 25 |
24 public: | 26 public: |
25 TypedBuffer() : TypedBuffer(0) {} | 27 TypedBuffer() : TypedBuffer(0) {} |
26 | 28 |
27 // Creates an instance of the object allocating a buffer of the given size. | 29 // Creates an instance of the object allocating a buffer of the given size. |
28 explicit TypedBuffer(uint32_t length) : buffer_(NULL), length_(length) { | 30 explicit TypedBuffer(uint32_t length) : buffer_(NULL), length_(length) { |
29 if (length_ > 0) | 31 if (length_ > 0) |
30 buffer_ = reinterpret_cast<T*>(new uint8_t[length_]); | 32 buffer_ = reinterpret_cast<T*>(new uint8_t[length_]); |
31 } | 33 } |
32 | 34 |
33 TypedBuffer(TypedBuffer&& rvalue) : TypedBuffer() { Swap(rvalue); } | 35 TypedBuffer(TypedBuffer&& rvalue) : TypedBuffer() { Swap(rvalue); } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 std::swap(buffer_, other.buffer_); | 76 std::swap(buffer_, other.buffer_); |
75 std::swap(length_, other.length_); | 77 std::swap(length_, other.length_); |
76 } | 78 } |
77 | 79 |
78 private: | 80 private: |
79 // Points to the owned buffer. | 81 // Points to the owned buffer. |
80 T* buffer_; | 82 T* buffer_; |
81 | 83 |
82 // Length of the owned buffer in bytes. | 84 // Length of the owned buffer in bytes. |
83 uint32_t length_; | 85 uint32_t length_; |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(TypedBuffer); | |
86 }; | 86 }; |
87 | 87 |
88 } // namespace remoting | 88 } // namespace remoting |
89 | 89 |
90 #endif // REMOTING_BASE_TYPED_BUFFER_H_ | 90 #endif // REMOTING_BASE_TYPED_BUFFER_H_ |
OLD | NEW |