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

Side by Side Diff: base/win/scoped_bstr.cc

Issue 1446363003: Deleted OS_WIN and all Windows specific files from base. (Closed) Base URL: https://github.com/domokit/mojo.git@base_tests
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « base/win/scoped_bstr.h ('k') | base/win/scoped_bstr_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/win/scoped_bstr.h"
6
7 #include "base/logging.h"
8
9 namespace base {
10 namespace win {
11
12 ScopedBstr::ScopedBstr(const char16* non_bstr)
13 : bstr_(SysAllocString(non_bstr)) {
14 }
15
16 ScopedBstr::~ScopedBstr() {
17 COMPILE_ASSERT(sizeof(ScopedBstr) == sizeof(BSTR), ScopedBstrSize);
18 SysFreeString(bstr_);
19 }
20
21 void ScopedBstr::Reset(BSTR bstr) {
22 if (bstr != bstr_) {
23 // if |bstr_| is NULL, SysFreeString does nothing.
24 SysFreeString(bstr_);
25 bstr_ = bstr;
26 }
27 }
28
29 BSTR ScopedBstr::Release() {
30 BSTR bstr = bstr_;
31 bstr_ = NULL;
32 return bstr;
33 }
34
35 void ScopedBstr::Swap(ScopedBstr& bstr2) {
36 BSTR tmp = bstr_;
37 bstr_ = bstr2.bstr_;
38 bstr2.bstr_ = tmp;
39 }
40
41 BSTR* ScopedBstr::Receive() {
42 DCHECK(!bstr_) << "BSTR leak.";
43 return &bstr_;
44 }
45
46 BSTR ScopedBstr::Allocate(const char16* str) {
47 Reset(SysAllocString(str));
48 return bstr_;
49 }
50
51 BSTR ScopedBstr::AllocateBytes(size_t bytes) {
52 Reset(SysAllocStringByteLen(NULL, static_cast<UINT>(bytes)));
53 return bstr_;
54 }
55
56 void ScopedBstr::SetByteLen(size_t bytes) {
57 DCHECK(bstr_ != NULL) << "attempting to modify a NULL bstr";
58 uint32* data = reinterpret_cast<uint32*>(bstr_);
59 data[-1] = static_cast<uint32>(bytes);
60 }
61
62 size_t ScopedBstr::Length() const {
63 return SysStringLen(bstr_);
64 }
65
66 size_t ScopedBstr::ByteLength() const {
67 return SysStringByteLen(bstr_);
68 }
69
70 } // namespace win
71 } // namespace base
OLDNEW
« no previous file with comments | « base/win/scoped_bstr.h ('k') | base/win/scoped_bstr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698