| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/win/scoped_bstr.h" | 5 #include "base/win/scoped_bstr.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace base { | 9 namespace base { |
| 10 namespace win { | 10 namespace win { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 return bstr; | 32 return bstr; |
| 33 } | 33 } |
| 34 | 34 |
| 35 void ScopedBstr::Swap(ScopedBstr& bstr2) { | 35 void ScopedBstr::Swap(ScopedBstr& bstr2) { |
| 36 BSTR tmp = bstr_; | 36 BSTR tmp = bstr_; |
| 37 bstr_ = bstr2.bstr_; | 37 bstr_ = bstr2.bstr_; |
| 38 bstr2.bstr_ = tmp; | 38 bstr2.bstr_ = tmp; |
| 39 } | 39 } |
| 40 | 40 |
| 41 BSTR* ScopedBstr::Receive() { | 41 BSTR* ScopedBstr::Receive() { |
| 42 DCHECK(bstr_ == NULL) << "BSTR leak."; | 42 DCHECK(!bstr_) << "BSTR leak."; |
| 43 return &bstr_; | 43 return &bstr_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 BSTR ScopedBstr::Allocate(const char16* str) { | 46 BSTR ScopedBstr::Allocate(const char16* str) { |
| 47 Reset(SysAllocString(str)); | 47 Reset(SysAllocString(str)); |
| 48 return bstr_; | 48 return bstr_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 BSTR ScopedBstr::AllocateBytes(size_t bytes) { | 51 BSTR ScopedBstr::AllocateBytes(size_t bytes) { |
| 52 Reset(SysAllocStringByteLen(NULL, static_cast<UINT>(bytes))); | 52 Reset(SysAllocStringByteLen(NULL, static_cast<UINT>(bytes))); |
| 53 return bstr_; | 53 return bstr_; |
| 54 } | 54 } |
| 55 | 55 |
| 56 void ScopedBstr::SetByteLen(size_t bytes) { | 56 void ScopedBstr::SetByteLen(size_t bytes) { |
| 57 DCHECK(bstr_ != NULL) << "attempting to modify a NULL bstr"; | 57 DCHECK(bstr_ != NULL) << "attempting to modify a NULL bstr"; |
| 58 uint32* data = reinterpret_cast<uint32*>(bstr_); | 58 uint32* data = reinterpret_cast<uint32*>(bstr_); |
| 59 data[-1] = static_cast<uint32>(bytes); | 59 data[-1] = static_cast<uint32>(bytes); |
| 60 } | 60 } |
| 61 | 61 |
| 62 size_t ScopedBstr::Length() const { | 62 size_t ScopedBstr::Length() const { |
| 63 return SysStringLen(bstr_); | 63 return SysStringLen(bstr_); |
| 64 } | 64 } |
| 65 | 65 |
| 66 size_t ScopedBstr::ByteLength() const { | 66 size_t ScopedBstr::ByteLength() const { |
| 67 return SysStringByteLen(bstr_); | 67 return SysStringByteLen(bstr_); |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace win | 70 } // namespace win |
| 71 } // namespace base | 71 } // namespace base |
| OLD | NEW |