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

Side by Side Diff: remoting/base/typed_buffer.h

Issue 1407443002: Remove old C++03 move emulation code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 2 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 (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 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/logging.h"
13 #include "base/move.h" 14 #include "base/move.h"
14 15
15 namespace remoting { 16 namespace remoting {
16 17
17 // 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
18 // similar. These structures typically consist of a header followed by variable- 19 // similar. These structures typically consist of a header followed by variable-
19 // 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
20 // move-only semantics and typed buffer getters. 21 // move-only semantics and typed buffer getters.
21 template <typename T> 22 template <typename T>
22 class TypedBuffer { 23 class TypedBuffer {
23 MOVE_ONLY_TYPE_FOR_CPP_03(TypedBuffer, RValue) 24 MOVE_ONLY_TYPE_FOR_CPP_03(TypedBuffer)
24 25
25 public: 26 public:
26 TypedBuffer() : buffer_(NULL), length_(0) { 27 TypedBuffer() : TypedBuffer(0) {}
27 }
28 28
29 // 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.
30 explicit TypedBuffer(uint32 length) : buffer_(NULL), length_(length) { 30 explicit TypedBuffer(uint32 length) : buffer_(NULL), length_(length) {
31 if (length_ > 0) 31 if (length_ > 0)
32 buffer_ = reinterpret_cast<T*>(new uint8[length_]); 32 buffer_ = reinterpret_cast<T*>(new uint8[length_]);
33 } 33 }
34 34
35 // Move constructor for C++03 move emulation of this type. 35 TypedBuffer(TypedBuffer&& rvalue) : TypedBuffer() { Swap(rvalue); }
36 TypedBuffer(RValue rvalue) : buffer_(NULL), length_(0) {
37 TypedBuffer temp;
dcheng 2015/10/13 21:03:09 I'm not quite sure what the purpose of the temp he
dcheng 2015/10/13 21:03:39 should *not* be possible
38 temp.Swap(*rvalue.object);
39 Swap(temp);
40 }
41 36
42 ~TypedBuffer() { 37 ~TypedBuffer() {
43 if (buffer_) { 38 if (buffer_) {
44 delete[] reinterpret_cast<uint8*>(buffer_); 39 delete[] reinterpret_cast<uint8*>(buffer_);
45 buffer_ = NULL; 40 buffer_ = NULL;
46 } 41 }
47 } 42 }
48 43
49 // Move operator= for C++03 move emulation of this type. 44 TypedBuffer& operator=(TypedBuffer&& rvalue) {
50 TypedBuffer& operator=(RValue rvalue) { 45 DCHECK_NE(this, &rvalue);
danakj 2015/10/15 23:35:06 Swap would handle *this ok? No dcheck?
dcheng 2015/10/16 00:40:01 Done.
51 TypedBuffer temp; 46 Swap(rvalue);
dcheng 2015/10/13 21:03:09 I opted to just DCHECK that this is not a self-mov
52 temp.Swap(*rvalue.object);
53 Swap(temp);
54 return *this; 47 return *this;
55 } 48 }
56 49
57 // Accessors to get the owned buffer. 50 // Accessors to get the owned buffer.
58 // operator* and operator-> will assert() if there is no current buffer. 51 // operator* and operator-> will assert() if there is no current buffer.
59 T& operator*() const { 52 T& operator*() const {
60 assert(buffer_ != NULL); 53 assert(buffer_ != NULL);
61 return *buffer_; 54 return *buffer_;
62 } 55 }
63 T* operator->() const { 56 T* operator->() const {
(...skipping 25 matching lines...) Expand all
89 // Points to the owned buffer. 82 // Points to the owned buffer.
90 T* buffer_; 83 T* buffer_;
91 84
92 // Length of the owned buffer in bytes. 85 // Length of the owned buffer in bytes.
93 uint32 length_; 86 uint32 length_;
94 }; 87 };
95 88
96 } // namespace remoting 89 } // namespace remoting
97 90
98 #endif // REMOTING_BASE_TYPED_BUFFER_H_ 91 #endif // REMOTING_BASE_TYPED_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698