Chromium Code Reviews| Index: base/win/scoped_propvariant.h |
| diff --git a/base/win/scoped_propvariant.h b/base/win/scoped_propvariant.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..42e443f516d2ccc9a9c9055a54c2106a186be7ae |
| --- /dev/null |
| +++ b/base/win/scoped_propvariant.h |
| @@ -0,0 +1,58 @@ |
| +// 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(); |
| + } |
| + |
| + // Leaks the underlying PROPVARIANT. This should only be called on a brand new |
|
grt (UTC plus 2)
2013/01/10 20:58:08
i don't understand the comment. this doesn't leak
gab
2013/01/10 21:56:46
Done.
|
| + // ScopedPropVariant or one that was just Reset(). |
| + PROPVARIANT* Receive() { |
| + DCHECK_EQ(pv_.vt, VT_EMPTY); |
| + return &pv_; |
| + } |
| + |
| + // Calls PropVariantClear() on the underlying PROPVARIANT which frees any |
|
grt (UTC plus 2)
2013/01/10 20:58:08
how about something like this to document the meth
gab
2013/01/10 21:56:46
Done.
|
| + // memory used by its members and re-initializes it. |
| + void Reset() { |
| + 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_ |