blob: 711d51adb40d2baa414a8e7c2afc38fe3d94439f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_WIN_SCOPED_PROPVARIANT_H_
#define BASE_WIN_SCOPED_PROPVARIANT_H_
#include <propidl.h>
#include "base/basictypes.h"
#include "base/logging.h"
namespace base {
namespace win {
// A PROPVARIANT that is automatically initialized and cleared upon respective
// construction and destruction of this class.
class ScopedPropVariant {
public:
ScopedPropVariant() {
PropVariantInit(&pv_);
}
~ScopedPropVariant() {
Reset();
}
// Returns a pointer to the underlying PROPVARIANT for use as an out param in
// a function call.
PROPVARIANT* Receive() {
DCHECK_EQ(pv_.vt, VT_EMPTY);
return &pv_;
}
// Clears the instance to prepare it for re-use (e.g., via Receive).
void Reset() {
if (pv_.vt != VT_EMPTY) {
HRESULT result = PropVariantClear(&pv_);
DCHECK_EQ(result, S_OK);
}
}
const PROPVARIANT& get() const { return pv_; }
const PROPVARIANT* operator&() const { return &pv_; }
private:
PROPVARIANT pv_;
// Comparison operators for ScopedPropVariant are not supported at this point.
bool operator==(const ScopedPropVariant&) const;
bool operator!=(const ScopedPropVariant&) const;
DISALLOW_COPY_AND_ASSIGN(ScopedPropVariant);
};
} // namespace win
} // namespace base
#endif // BASE_WIN_SCOPED_PROPVARIANT_H_
|