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 { |
11 | 11 |
12 ScopedBstr::ScopedBstr(const char16* non_bstr) | 12 ScopedBstr::ScopedBstr(const char16* non_bstr) |
13 : bstr_(SysAllocString(non_bstr)) { | 13 : bstr_(SysAllocString(non_bstr)) { |
14 } | 14 } |
15 | 15 |
16 ScopedBstr::~ScopedBstr() { | 16 ScopedBstr::~ScopedBstr() { |
17 COMPILE_ASSERT(sizeof(ScopedBstr) == sizeof(BSTR), ScopedBstrSize); | 17 static_assert(sizeof(ScopedBstr) == sizeof(BSTR), "ScopedBstrSize"); |
18 SysFreeString(bstr_); | 18 SysFreeString(bstr_); |
19 } | 19 } |
20 | 20 |
21 void ScopedBstr::Reset(BSTR bstr) { | 21 void ScopedBstr::Reset(BSTR bstr) { |
22 if (bstr != bstr_) { | 22 if (bstr != bstr_) { |
23 // if |bstr_| is NULL, SysFreeString does nothing. | 23 // if |bstr_| is NULL, SysFreeString does nothing. |
24 SysFreeString(bstr_); | 24 SysFreeString(bstr_); |
25 bstr_ = bstr; | 25 bstr_ = bstr; |
26 } | 26 } |
27 } | 27 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |